Routing
Map URLs to standalone components and guard private pages.
What you will be able to do
- Use provideRouter with route definitions.
- Lazy load feature components.
- Pass params as component inputs.
- Guard private routes with a functional guard.
In plain English
Angular Router matches URLs to component trees. Lazy load large features with loadComponent, read params through the route snapshot or an input binding, and guard private pages with a functional guard.
import { Routes } from '@angular/router'
import { authGuard } from './auth.guard'
export const routes: Routes = [
{ path: '', loadComponent: () => import('./home.component').then((m) => m.HomeComponent) },
{
path: 'courses/:slug',
loadComponent: () => import('./course.component').then((m) => m.CourseComponent),
canActivate: [authGuard],
},
]Your turn
EasyPass a route param as input
Configure a route so :slug is available as a component input.
TYPESCRIPT · starter
provideRouter(routes)Check your understanding before moving on.
Knowledge checkQuestion 1
What does loadComponent enable?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.