Angular·Angular from components to production

Routing

Map URLs to standalone components and guard private pages.

Intermediate 13 min read Lesson 8 of 300 Challenge included
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.

app.routes.tsTYPESCRIPT
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

Pass a route param as input

Easy

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 in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Signals
Lesson 8 of 300 · 0% of course