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
- pushState and replaceState
- The popstate Event
- Hash-Based vs Path-Based Routing
- The Navigation API modern browsers