Quick Reference ("How Do I...")
Table of Contents
Getting Started
How do I install and configure the router?
// Install
npm i @aurelia/router
// Configure in main.ts
import { RouterConfiguration } from '@aurelia/router';
Aurelia
.register(RouterConfiguration.customize({
useUrlFragmentHash: false, // Clean URLs (default)
historyStrategy: 'push', // Browser history
}))
.app(MyApp)
.start();How do I define routes?
How do I set up a viewport?
How do I use hash-based routing instead of clean URLs?
Navigation
How do I create navigation links?
How do I navigate programmatically?
How do I highlight the active link?
How do I navigate to parent routes from nested components?
How do I pass query parameters?
How do I handle external links?
Route Parameters
How do I define route parameters?
How do I access route parameters in my component?
How do I get all parameters including from parent routes?
How do I constrain parameters with regex?
Route Protection
How do I protect routes (authentication)?
How do I implement authorization (role-based access)?
How do I prevent navigation away from unsaved forms?
How do I redirect based on conditions?
Lifecycle Hooks
How do I load data before showing a component?
How do I run code after a component is fully loaded?
When do lifecycle hooks run?
Hook
When
Use For
What's the difference between component hooks and router hooks?
Advanced Topics
How do I handle 404 / unknown routes?
How do I create route aliases / redirects?
How do I work with multiple viewports (sibling routes)?
How do I implement nested/child routes?
How do I lazy load routes?
How do I set/change the page title?
How do I generate URLs without navigating?
How do I work with base paths (multi-tenant apps)?
How do I handle browser back/forward buttons?
How do I access the current route information?
Troubleshooting
My routes don't work with clean URLs (no hash)
External links are triggering the router (rare)
Navigation isn't working from nested components
My lifecycle hooks aren't being called
Route parameters aren't updating when navigating between same routes
How do I debug routing issues?
Complete Documentation
Getting Started
Routes and Navigation
Lifecycle and Guards
State and Events
Advanced Topics
Reference
Last updated
Was this helpful?