routerLink navigates declaratively in templates—prefer it over manual history.pushState so Angular stays aware of navigation. ActivatedRoute exposes params (path segments like :id) and query params (?tab=settings).
Common patterns
[routerLink]="['/users', userId]"— path paramsrouterLink="/reports" [queryParams]="{ year: 2026 }"— query string- Subscribe to
route.paramMapor usetoSignal(route.paramMap)in modern apps
Compared to Vue Router / React Router
All three separate URL state from component trees. Angular’s router is deeply integrated with DI, guards, and resolvers for enterprise workflows.
Important interview questions and answers
- Q: Path param vs query param?
A: Path params identify a resource (/users/42); query params filter or configure views (?sort=name). - Q: Why avoid reading
window.locationdirectly?
A: The router abstraction keeps navigation testable and syncs with guards, outlets, and lazy loading.
Self-check
- What query param does the playground simulate?
- How would you link to
/users/7withrouterLink?