Current route
Access information about the active route via ICurrentRoute.
ICurrentRoute is a dependency injection token that exposes details of the route that is currently active. The instance is updated whenever navigation finishes so that you can inspect the active path, URL and query information from any component or service.
ICurrentRoute has the following shape:
interface ICurrentRoute {
readonly path: string;
readonly url: string;
readonly title: string;
readonly query: URLSearchParams;
readonly parameterInformation: readonly ParameterInformation[];
}
interface ParameterInformation {
readonly config: RouteConfig | null;
readonly viewport: string | null;
readonly params: Readonly<Params> | null;
readonly children: readonly ParameterInformation[];
}To use it, inject the token and read its properties:
import { ICurrentRoute } from '@aurelia/router';
import { resolve } from '@aurelia/kernel';
export class MyApp {
private readonly currentRoute = resolve(ICurrentRoute);
// ⚠️ Note: accessing in lifecycle hooks shows previous route
// See "Timing Considerations" below for proper solutions
}Timing Considerations
Important: ICurrentRoute is updated by the router after navigation completes, which happens after all component lifecycle hooks complete. This means:
❌ Avoid in lifecycle hooks -
binding(),bound(),attaching(), andattached()all show previous route information✅ Use router events instead - Subscribe to
au:router:navigation-endfor immediate access
Component Lifecycle vs Router Timing
The exact sequence is:
binding()hook → previous routebound()hook → previous routeattaching()hook → previous routeattached()hook → previous routeau:router:navigation-endevent fires → current route updated
Incorrect Timing Examples
Correct Timing Solutions
Option 1: Use navigation-start event (Recommended)
Option 2: Use navigation-end event
Option 3: Use setTimeout as a workaround (Not recommended)
Option 4: Access current route outside of lifecycle hooks
The parameterInformation array mirrors the hierarchy of viewport instructions of the current navigation. It allows you to inspect route parameters and nested routes programmatically.
Last updated
Was this helpful?