Step 4: Detail route + guards
Add a detail route with parameters and protect it with router guards.
In this step you will add a parameterized detail route and guard it with canLoad and canUnload.
1. Add the detail route
Update src/pages/projects-page.ts to add the detail child route:
import { route } from '@aurelia/router';
import { ProjectDetailPage } from './project-detail-page';
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' },
{ id: 'project-detail', path: 'detail/:id', component: ProjectDetailPage, title: 'Project Detail' }
]
})
export class ProjectsPage {}We keep detail in the URL to keep the child routes explicit and readable. The id: 'project-detail' value is what the Overview page uses in its route: instruction, with a ../ prefix to resolve against the parent context.
2. Build the detail page
Create src/pages/project-detail-page.ts:
Create src/pages/project-detail-page.html:
Guard recap:
canLoadprevents invalid IDs and redirects toprojects.canUnloadprompts when there is unsaved user input.
Next step: Step 5: Router events + polish
Last updated
Was this helpful?