skip to content

Links & Navigation Calls

Navigating with routerLink, RouterLinkActive and Router.navigate versus navigateByUrl, with relative paths, queryParams and UrlTree. Interviewers probe links that resolve somewhere unexpected.

part ofAngularread it →
on this pageshow

explore

questions

5

In Angular's Router, what is the difference between navigate() and navigateByUrl(), and which one honours relativeTo and queryParams?

level: middleimportance: must knowfreq 62%

basics

~10 s

Router.navigate() builds a UrlTree from a commands array, honouring relativeTo, queryParams, queryParamsHandling and fragment, then calls navigateByUrl(). navigateByUrl() takes a complete URL string or UrlTree and applies no delta. Both return a Promise<boolean>.

open as a page

In Angular, how do you move a product list to page 3 without dropping its active filter query parameters, and what does queryParamsHandling control?

level: middleimportance: should knowfreq 55%

basics

~10 s

Navigate with empty commands, queryParams {page: 3} and queryParamsHandling 'merge' so current filters are kept. The option decides how new query params combine with current ones: 'replace' (default), 'merge' or 'preserve'.

open as a page

In Angular, why does routerLinkActive keep highlighting a Home link to '/' on every page, and how do routerLinkActiveOptions fix it?

level: middleimportance: should knowfreq 48%

basics

~20 s

RouterLinkActive matches by subset by default, so a link to '/' is contained in every URL and stays active. Setting routerLinkActiveOptions to {exact: true}, or to IsActiveMatchOptions with paths 'exact', restricts it to the exact URL.

open as a page