Step 5: Router events + polish
Add router event listeners and polish the navigation experience.
1. Listen to router events in the Projects layout
import { IDisposable, resolve } from '@aurelia/kernel';
import { IRouterEvents, NavigationEndEvent, route } from '@aurelia/router';
import { ProjectsActivityPage } from './projects-activity-page';
import { ProjectsOverviewPage } from './projects-overview-page';
@route({
routes: [
{ path: ['', 'overview'], component: ProjectsOverviewPage, title: 'Overview' },
{ path: 'activity', component: ProjectsActivityPage, title: 'Activity' }
]
})
export class ProjectsPage {
lastNavigation = '';
private readonly events = resolve(IRouterEvents);
private subscription?: IDisposable;
bound(): void {
this.subscription = this.events.subscribe(
'au:router:navigation-end',
(event: NavigationEndEvent) => {
this.lastNavigation = event.instructions.toPath();
}
);
}
unbinding(): void {
this.subscription?.dispose();
}
}2. Recap the routing features used
Last updated
Was this helpful?