Hash Routing
The router supports both standard HTML5 History API routing (pathnames) and Hash-based routing (#/path).
Hash routing is perfect for static file hosting environments (like GitHub Pages or Netlify static deploys) because it bypasses the need for server-side redirection fallback configurations.
setRoutingMode
Configures the router's active mode. Accepts "history" (default) or "hash".
typescript
1function setRoutingMode(mode: 'history' | 'hash'): voidExample
javascript
1import { setRoutingMode } from '@beforesemicolon/router'2 3// Enable Hash Routing4setRoutingMode('hash')5 6// URLs will now format as: domain.com/#/dashboard7// <page-link path="/todos"> renders as: <a href="#/todos">getRoutingMode
Retrieves the currently active routing mode.
typescript
1function getRoutingMode(): 'history' | 'hash'Example
javascript
1import { getRoutingMode } from '@beforesemicolon/router'2 3const mode = getRoutingMode() // "history" or "hash"Benefits of Hash Routing
- Zero Server Config: Standard servers return a 404 error when accessing a direct path like
/abouton page refresh unless configured to rewrite toindex.html. Hash routing is fully client-side and requires no server-side fallback rules. - Static Hosting: Highly compatible with static environments like AWS S3 buckets, GitHub Pages, or Netlify.
- Legacy Compatibility: Works flawlessly in older web browser engines.