0Pricing
HTML Academy · Lesson

Hash-Based vs Path-Based Routing

Compare hash routing with pushState-based history routing.

Two Strategies for SPA URLs

SPAs need URLs that the browser does not fetch. Two approaches: hash-based uses the fragment (everything after #) which the browser never sends to the server, and path-based uses the pathname plus History API trickery.

Hash-Based Routing

URLs look like https://example.com/#/about. The server only sees / and serves the same HTML for every URL. Client JS reads location.hash to decide which view to render. Simple, requires no server config.

All lessons in this course

  1. pushState and replaceState
  2. The popstate Event
  3. Hash-Based vs Path-Based Routing
  4. The Navigation API modern browsers
← Back to HTML Academy