jaspr_router package for seamless navigation without full page reloads.
Installation
Addjaspr_router to your project:
pubspec.yaml
Basic setup
Wrap your application with aRouter component and define routes:
Route parameters
Capture dynamic segments in your routes:Query parameters
Access URL query parameters from the route state:Link component
Use theLink component for client-side navigation:
Styling active links
Highlight the currently active route:Programmatic navigation
Navigate programmatically usingRouter.of(context):
Navigation methods
Nested routes
Create hierarchical route structures:Named routes
Define named routes for easier navigation:Redirects
Redirect users to different routes:404 Not Found page
Handle unknown routes with a catch-all:Route guards
Protect routes with authentication checks:Lazy loading routes
Load route components on demand to reduce initial bundle size:Complete navigation example
Here’s a complete multi-page app with navigation:Best practices
Use named routes for complex navigation
Use named routes for complex navigation
Keep route logic simple
Keep route logic simple
Complex logic should be in components, not route builders:
Handle loading states
Handle loading states
Show loading indicators while lazy loading routes or fetching data
Next steps
Router API
Complete Router component reference
Link API
Link component documentation
jaspr_router plugin
Advanced routing features
State management
Manage state across routes