skip to content

Client Navigation APIs

Moving between routes without a full page load, from prefetched Link hovers to programmatic pushes and server-side redirects. Interviewers ask when to use router.refresh versus a redirect, which reveals whether you understand the cache underneath.

part ofNext.jsoverview, primer and where to startread it →
on this pageshow

explore

questions

6

In a Next.js App Router Client Component, what does `router.refresh()` from `useRouter` (next/navigation) actually do, and how does it differ from `window.location.reload()`?

level: middleimportance: must knowfreq 60%

basics

~20 s

router.refresh() re-requests the current route from the server, re-renders its Server Components, and merges the new payload into the live page — keeping client state and scroll position. window.location.reload() throws the whole document away and starts over.

open as a page

In a Next.js App Router Client Component, how do you read the current pathname and query string, and why can a build fail with "useSearchParams() should be wrapped in a suspense boundary"?

level: middleimportance: should knowfreq 55%

basics

~20 s

Use usePathname() and useSearchParams() from next/navigation inside a client component. useSearchParams reads a value known only at request time, so on a statically prerendered route Next requires a Suspense boundary around the component that calls it.

open as a page

A Next.js App Router page calls `redirect('/login')` from next/navigation inside a try/catch, and the redirect silently stops working. What is the mechanism behind `redirect()` and `notFound()`, and what is the fix?

level: seniorimportance: should knowfreq 52%

basics

~20 s

Both functions work by throwing a special control-flow error that Next catches above your code. A surrounding try/catch swallows it, so nothing happens. Call them outside the try block, or re-throw the framework's error instead of absorbing it.

open as a page

In a Next.js App Router app, a filter panel calls `router.push('?sort=price')` on every change and the page jumps back to the top each time. Why does that happen, and how do you keep the scroll position?

level: seniorimportance: should knowfreq 40%

basics

~20 s

The App Router scrolls to the top on a new navigation by default, and changing the query string counts as one. Pass the scroll option — router.push(url, { scroll: false }) — or use scroll={false} on a Link, to keep the position.

open as a page