You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Route guards allow you to protect routes with authentication checks, authorization, or any custom logic. Guards can be global (run for all routes) or route-specific.
726
+
727
+
#### registerRouteGuard
728
+
729
+
Register a guard for a specific route. The guard function receives the pathname, search params, and page data, and can return:
730
+
731
+
-`true` - Allow navigation
732
+
-`false` - Block navigation (stay on current page)
733
+
-`string` - Redirect to the specified pathname
734
+
-`Promise<boolean | string>` - Async guards are fully supported
if (!publicRoutes.includes(pathname) &&!isAuthenticated()) {
766
+
return'/login'
767
+
}
768
+
769
+
returntrue
770
+
})
771
+
```
772
+
773
+
**Guard execution order:**
774
+
775
+
1. Global guards (in registration order)
776
+
2. Route-specific guards (in registration order)
777
+
3. First guard that blocks or redirects stops execution
778
+
779
+
### Hash Routing
780
+
781
+
The router supports both history API and hash-based routing. Hash routing is perfect for static hosting (GitHub Pages, Netlify) and requires no server configuration.
782
+
783
+
#### setRoutingMode
784
+
785
+
Set the routing mode to either `'history'` (default) or `'hash'`.
- All navigation uses hash format: `#/path?query=value`
813
+
- Works without server-side routing configuration
814
+
- Perfect for static hosting
815
+
- Backward compatible with older browsers
816
+
817
+
### Module Registry
818
+
819
+
Register route modules for build-time optimization with bundlers like Vite or Webpack. This allows bundlers to analyze dependencies while using the convenient `src` attribute.
820
+
821
+
#### registerRouteModules
822
+
823
+
Register a map of module paths to their loader functions.
0 commit comments