SPA Router
Angular's router: Routes arrays, links and navigation, guards and resolvers, lazy route chunks and navigation events. Interviewers probe it since routes decide bundle size and where auth is enforced.
part ofAngularoverview, primer and where to startread it →on this pageshowhide
explore
- Path Matching & Redirects5 questions
- Links & Navigation Calls5 questions
- Reading Route State5 questions
- Nested & Named Outlets5 questions
- Functional Route Guards6 questions
- Data Resolvers5 questions
- On-Demand Route Chunks5 questions
- Navigation Lifecycle Events5 questions
- Reuse, Scrolling & Matchers5 questions
questions
page 2 of 2In an Angular app, a route never renders or a redirect keeps looping; how do you diagnose the route configuration?
basics
~20 sCheck the console for the router's dev-mode configuration errors, look for earlier routes shadowing the missing one (a ** or :param too high), check pathMatch on parents and redirects, and trace navigations with withDebugTracing() to see which route matched or why matching failed.
An Angular route has canActivate: [authGuard, adminGuard]; the admin HTTP check fires even for signed-out users, and some non-admins still get in; what explains both?
basics
~20 sAngular invokes every guard in one canActivate array together and uses array order only to rank verdicts, so adminGuard's request always starts. It also ignores results other than boolean, UrlTree or RedirectCommand, so an unmapped response object passes.
An Angular reports route uses loadComponent, yet the build still puts ReportsPage in the initial bundle; what usually causes that, and how do you confirm it?
basics
~20 sSome eagerly loaded file still imports ReportsPage statically, directly or through a barrel, so the bundler must keep it in the initial chunk. Confirm with the build's initial and lazy chunk lists and a stats.json analysis.
How would you write an Angular PreloadingStrategy that preloads the reports section only for signed-in admins, and what must it not be relied on for?
basics
~20 sImplement PreloadingStrategy in a root-provided class whose preload() calls load() only when the route is flagged for admins and the injected auth state says the user is one, returning of(null) otherwise. It is a performance hint, never access control.
In an Angular mail client, why does routerLink="../sent" inside the side outlet's Compose component change the side panel instead of the main view, and how do you target the primary outlet?
basics
~20 sA relative link resolves against the ActivatedRoute of the component it sits in, and Compose's route is the side outlet's branch, so '../sent' rewrites that branch to (side:sent). Use '/sent' or an outlets command naming primary.
An Angular invoice edit route shows stale data when only its ?revision query parameter changes; why does its resolver not re-run, and how do you fix it?
basics
~10 sThe router reuses the component and, under the default runGuardsAndResolvers of 'paramsChange', ignores query parameters, so the resolver is skipped and the old data kept. Set a query-aware policy and read ActivatedRoute.data reactively.
In Angular 22, when should an invoice page's data come from a ResolveFn, from the component itself, or from the router's route resources?
basics
~20 sUse a ResolveFn when the page is meaningless without the data or must redirect before rendering; fetch in the component when a skeleton is acceptable; route resources (developer preview in 22.2) add concurrency, optional non-blocking loads and reload without renavigating.
An Angular /users/:id profile loads its user in ngOnInit from route.snapshot; Next and Previous links change the URL but the page never updates. Why, and how do you fix it robustly?
basics
~20 sThe router reuses the UserProfile instance for /users/2 because it matches the same route config, so ngOnInit and its snapshot read never run again. Derive the load from paramMap or a bound input, cancel superseded loads, and reset per-user state.
In Angular's router, how would you write a custom TitleStrategy that appends the site name to every route's title?
basics
~10 sExtend TitleStrategy, override updateTitle(snapshot), call buildTitle(snapshot) for the deepest primary route's title, and set it with the Title service plus a suffix. Provide it with {provide: TitleStrategy, useClass: AppTitleStrategy}.
In Angular's router, when do you need a custom UrlMatcher instead of a path, and what must the matcher function return?
basics
~20 sUse Route.matcher when path syntax cannot express the pattern, such as /@username or a regex rule. The function receives the URL segments and returns null for no match or {consumed, posParams}, whose parameters appear in paramMap like :id values.
In Angular, what can a route guard do by returning a RedirectCommand that returning a plain UrlTree cannot?
basics
~20 sA RedirectCommand (v18+) wraps the target UrlTree with NavigationBehaviorOptions that override what the redirect would otherwise inherit from the original navigation, so a guard can set skipLocationChange, replaceUrl, state, info or browserUrl for the redirect.
In Angular, what do a router-outlet's activate and deactivate outputs emit, and when would you pass routerOutletData instead?
basics
~20 sactivate emits the routed component instance when the outlet creates it, and deactivate emits it when the outlet destroys it. To send context into routed components, bind routerOutletData and inject ROUTER_OUTLET_DATA as a signal instead of poking the instance.
In Angular 22, why can a child route's component read its parent's :userId from its own ActivatedRoute params, and what did 'emptyOnly' change?
basics
~20 sSince v22, paramsInheritanceStrategy defaults to 'always', so every route inherits its ancestors' params, static data and resolved data, and its own values win on a clash. The old default 'emptyOnly' inherited only for empty-path routes or componentless parents.
showing 31–46 of 46