Visual Diagrams
Visual explanations of Aurelia 2's router architecture and concepts.
Table of Contents
1. Route Matching Pipeline
How the router resolves a URL to components:
┌──────────────────────────────────────────────────────────┐
│ User navigates to: /products/42/reviews │
└──────────────────┬───────────────────────────────────────┘
↓
┌──────────────────────┐
│ 1. Parse URL │
│ Path: /products/42/ │
│ reviews │
│ Fragment: #section2 │
│ Query: ?sort=date │
└──────────┬───────────┘
↓
┌──────────────────────┐
│ 2. Match Routes │
│ - Check path pattern │
│ - Extract params │
│ - Apply constraints │
└──────────┬───────────┘
↓
┌──────────────────────┐
│ 3. Build Route Tree │
│ Root │
│ └─ Products (:id) │
│ └─ Reviews │
└──────────┬───────────┘
↓
┌──────────────────────┐
│ 4. Execute Hooks │
│ - canLoad (guard) │
│ - loading (data) │
│ - canUnload (prev) │
└──────────┬───────────┘
↓
┌──────────────────────┐
│ 5. Render Components │
│ - Swap viewports │
│ - loaded hooks │
│ - Update title │
└──────────────────────┘
Route Configuration Match Example:
routes: [
{
path: 'products/:id', ✓ Matches /products/42
component: ProductDetail,
routes: [
{ path: 'reviews', ... } ✓ Matches /reviews
]
},
{
path: 'products/:id{{^\\d+$}}', ✓ Only if :id is numeric
component: ProductDetail
}
]Key Points:
Routes are matched top-to-bottom in configuration order
First matching route wins
Parameters are extracted during matching
Constraints (
{{regex}}) are validatedHierarchical routes build a route tree
Route matching documentation →
2. Navigation Flow
How different navigation methods work:
Decision Guide:
Use
hreffor simple, static linksUse
loadwhen you need parameter binding or active stateUse
IRouter.load()for conditional/programmatic navigation
3. Lifecycle Hook Execution Order
Complete sequence when navigating from ComponentA to ComponentB:
Important Notes:
All hooks can be async (return Promise)
Router waits for each hook to complete before proceeding
Returning
falsefrom guard hooks stops navigationRouter hooks run before component hooks
unloadingandloadinghappen in parallel for performance
Lifecycle hooks documentation →
4. Component vs Router Hooks
Two ways to implement lifecycle logic:
Decision Guide:
Router hooks for: Authentication, authorization, logging, analytics
Component hooks for: Data fetching, validation, component state
Both when you need layered checks (global + local)
Router hooks → | Component hooks →
5. Viewport Hierarchy
How viewports nest and relate to each other:
Key Concepts:
Default viewport:
<au-viewport></au-viewport>(no name)Named viewport:
<au-viewport name="aside"></au-viewport>Target viewport: Use
@viewportNamein navigationHierarchical: Nested components each have their own viewport
Sibling: Multiple viewports at the same level
6. History Strategy
How router interacts with browser history:
Decision Guide:
push: Normal navigation, want history
replace: Redirects, corrections, interim states
none: Modals, overlays, no history needed
History strategy documentation →
7. Transition Plans
What happens when navigating to the same component with different parameters:
Rule of Thumb:
Default (
replace): Safe, always worksinvoke-lifecycles: Optimize when parameters drive content, not fundamentally different pages
Transition plans documentation →
8. Route Parameter Flow
How parameters flow from URL to component:
Key Points:
All parameters are strings
Path params come from URL segments
Query params come from
?key=valueAccess via lifecycle hooks or ICurrentRoute
Always validate and convert types
Path parameters → | Query parameters →
Summary
These diagrams cover the core architectural concepts of Aurelia 2's router:
Route Matching - How URLs become components
Navigation - Three ways to navigate and their differences
Lifecycle - Complete hook execution sequence
Hooks - Component vs Router hooks
Viewports - Nested and sibling viewport patterns
History - Push vs Replace vs None strategies
Transitions - Replace vs invoke-lifecycles behavior
Parameters - How data flows from URL to component
For more details, see the complete Router Documentation.
Last updated
Was this helpful?