Routing lifecycle
Learn about the different routing hooks and how to leverage those in terms of dis/allow loading or unloading as well as performing setup and teardown of a view.
Hook summary
Hook
When it runs
Common uses
Return type
import {
IRouteViewModel,
INavigationOptions,
Params,
RouteNode,
NavigationInstruction,
} from '@aurelia/router';
export class MyComponent implements IRouteViewModel {
canLoad?(
params: Params,
next: RouteNode,
current: RouteNode | null,
options: INavigationOptions
): boolean
| NavigationInstruction
| NavigationInstruction[]
| Promise<boolean | NavigationInstruction | NavigationInstruction[]>;
loading?(params: Params, next: RouteNode, current: RouteNode | null, options: INavigationOptions): void | Promise<void>;
loaded?(params: Params, next: RouteNode, current: RouteNode | null, options: INavigationOptions): void | Promise<void>;
canUnload?(next: RouteNode | null, current: RouteNode, options: INavigationOptions): boolean | Promise<boolean>;
unloading?(next: RouteNode | null, current: RouteNode, options: INavigationOptions): void | Promise<void>;
}canLoad
canLoadAllow or disallowed loading components
Redirect to another view from canLoad
canLoadAccessing fragment and query
loading
loadingAccessing parent route parameters
loaded
loadedcanUnload
canUnloadunloading
unloadingNavigation Direction Detection
Order of invocations
Order of invocations of component lifecycle hooks
Inspecting current route and query inside lifecycle hooks
Last updated
Was this helpful?