Installation
Basic Usage
TheRouter component takes a list of Route definitions:
Route Parameters
Define path parameters using the: symbol:
RouteState object passed to the builder function.
Nested Routes
Create nested route hierarchies:Programmatic Navigation
Navigate imperatively from anywhere in your component tree:Navigation Methods
push(path)- Navigate to a new routereplace(path)- Replace the current routeback()- Navigate back in history
Lazy Routes & Code Splitting
For larger applications, split your code into smaller chunks that load on-demand:- Generates separate JavaScript files for each lazy route
- Loads the appropriate file when navigating to the route
- Reduces initial bundle size
- Improves page load performance
Link Component
Use theLink component for declarative navigation with automatic client-side routing:
Link Features
- Automatic client-side navigation (no page reload)
- Fallback to server-side navigation when needed
- Preloading on hover for lazy routes
- Support for all standard anchor attributes
Named Routes
Use named routes for easier navigation:Redirects
Implement redirects at the route or router level:Error Handling
Provide a custom error page:Page Titles
Set page titles for each route:<title> element and overrides any top-level title.