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 validated

  • Hierarchical routes build a route tree

Route matching documentation →


2. Navigation Flow

How different navigation methods work:

Decision Guide:

  • Use href for simple, static links

  • Use load when you need parameter binding or active state

  • Use IRouter.load() for conditional/programmatic navigation

Navigation documentation →


3. Lifecycle Hook Execution Order

Complete sequence when navigating from ComponentA to ComponentB:

Important Notes:

  1. All hooks can be async (return Promise)

  2. Router waits for each hook to complete before proceeding

  3. Returning false from guard hooks stops navigation

  4. Router hooks run before component hooks

  5. unloading and loading happen 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 @viewportName in navigation

  • Hierarchical: Nested components each have their own viewport

  • Sibling: Multiple viewports at the same level

Viewports documentation →


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 works

  • invoke-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=value

  • Access 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:

  1. Route Matching - How URLs become components

  2. Navigation - Three ways to navigate and their differences

  3. Lifecycle - Complete hook execution sequence

  4. Hooks - Component vs Router hooks

  5. Viewports - Nested and sibling viewport patterns

  6. History - Push vs Replace vs None strategies

  7. Transitions - Replace vs invoke-lifecycles behavior

  8. Parameters - How data flows from URL to component

For more details, see the complete Router Documentation.

Last updated

Was this helpful?