skip to content

Links & Programmatic Navigation

Moving between routes with RouterLink or router.push, and reading the failure a blocked push resolves with. Interviewers probe active vs exact-active links and push promises.

on this pageshow

explore

questions

5

On a Vue Router 5 job-search page with filters in the query, how do you change one filter via `router.push` without dropping the others?

level: middleimportance: must knowfreq 62%

basics

~20 s

Copy the current query into the new location: router.push({ query: { ...route.query, remote: 'true', page: undefined } }). A location with only query stays on the current route, but its query replaces the old one, so omitted keys vanish.

open as a page

In Vue Router 5, why does every page-number `<RouterLink>` on a job-search results page get `router-link-exact-active`, and how do you highlight only the current page?

level: middleimportance: should knowfreq 48%

basics

~20 s

RouterLink's active matching compares the route record and params only, never the query, so every ?page=N link on the same route is active and exact-active. Compare route.query.page yourself through custom with its slot, or through useLink.

open as a page

In Vue Router 5, a job-search page runs `await router.push()` for each filter change; what can that promise settle with, and how do you tell the outcomes apart?

level: seniorimportance: should knowfreq 45%

basics

~20 s

router.push() resolves undefined on success, including after a guard redirect; resolves with a navigation failure (aborted, cancelled or duplicated) when the user stays put; and rejects when a guard or lazy component throws. isNavigationFailure(result, type) tells failures apart.

open as a page

In Vue Router 5, an app's `scrollBehavior` always returns `{ top: 0 }`; why does a job-search page jump on every filter change and lose its place on Back, and what fixes it?

level: seniorimportance: should knowfreq 38%

basics

~10 s

The function treats every navigation alike and discards savedPosition. Return savedPosition on Back and Forward, after the list has rendered; return false when only the query changed; scroll to the top otherwise.

open as a page