skip to content

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 pageshow

explore

questions

page 2 of 2

In an Angular app, a route never renders or a redirect keeps looping; how do you diagnose the route configuration?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Check 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.

open as a page

In Angular 22, how do you handle navigation errors centrally with withNavigationErrorHandler, and what can that handler not change?

level: seniorimportance: should knowfreq 36%

basics

~10 s

Pass withNavigationErrorHandler(fn) to provideRouter; fn receives each NavigationError and runs in an injection context. Returning a RedirectCommand turns the error into a redirect; anything else is ignored, and it cannot stop navigate() from rejecting.

open as a page

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?

level: seniorimportance: should knowfreq 32%

basics

~20 s

Angular 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.

open as a page

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?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Some 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.

open as a page

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?

level: seniorimportance: should knowfreq 38%

basics

~20 s

Implement 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.

open as a page

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?

level: seniorimportance: should knowfreq 42%

basics

~10 s

The 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.

open as a page

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?

level: seniorimportance: should knowfreq 50%

basics

~20 s

Use 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.

open as a page

In Angular's router, how would you write a custom TitleStrategy that appends the site name to every route's title?

level: middleimportance: nice to knowfreq 30%

basics

~10 s

Extend 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}.

open as a page

In Angular's router, when do you need a custom UrlMatcher instead of a path, and what must the matcher function return?

level: middleimportance: nice to knowfreq 26%

basics

~20 s

Use 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.

open as a page

In Angular, what does the Router.currentNavigation() signal expose during a navigation, and how can code abort a pending navigation?

level: middleimportance: nice to knowfreq 26%

basics

~20 s

Router.currentNavigation() returns the in-flight Navigation, or null when idle: its id, initialUrl, extractedUrl, finalUrl (set once routes are recognised), trigger, extras such as state, and previousNavigation. Calling its abort() cancels the navigation with the Aborted code, if activation has not started.

open as a page

In Angular, what can a route guard do by returning a RedirectCommand that returning a plain UrlTree cannot?

level: middleimportance: nice to knowfreq 25%

basics

~20 s

A 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.

open as a page

In Angular, what do a router-outlet's activate and deactivate outputs emit, and when would you pass routerOutletData instead?

level: middleimportance: nice to knowfreq 28%

basics

~20 s

activate 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.

open as a page

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?

level: middleimportance: nice to knowfreq 30%

basics

~20 s

Since 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.

open as a page

showing 31–46 of 46