How Hash Routing Fixed the Web's White-Screen Problem
Hash routing is the conceptual ancestor of every modern frontend router. Understanding its mechanics — particularly the `hashchange` event and the `this` binding trap that breaks event handlers — gives developers a clear mental model for debugging routing bugs in any framework.
Multi-page apps reload everything on navigation, causing a jarring white flash. Single-page apps eliminate that flash but break the URL, killing bookmarks, sharing, and the back button. Hash routing resolves this by using the fragment identifier — the part of a URL after the `#` — which the browser can change without sending a new request. A `hashchange` event listener then swaps page content in JavaScript, restoring the one-to-one mapping between URL and view without server involvement. The technique is simple enough to implement in a few dozen lines of vanilla JavaScript, and its constraints — ugly URLs, poor SEO — directly motivated the later History API that underpins modern routers like React Router and Vue Router.
Hash routing was not an arbitrary invention but a logical endpoint of a stepwise debugging process: prevent default navigation, notice the URL breaks, then search for a URL component that changes without triggering a request.
The `this` binding problem in event listeners is a rite-of-passage bug that persists in modern frontend frameworks; arrow functions and class properties are syntactic sugar over the same `.bind()` fix.
SEO was the primary force that pushed the industry from hash routing to the History API, not aesthetics — crawlers simply ignored fragment identifiers.