skip to content

Navigation and Links

Moving between routes with <Link> and <NavLink>, redirecting with <Navigate>, and navigating programmatically through useNavigate. The subtle part interviewers probe is relative versus absolute paths once routes are nested.

on this pageshow

explore

questions

5

In React Router v7, how does a relative to like ".." resolve inside nested routes, and what does relative="path" change?

level: middleimportance: must knowfreq 57%

basics

~20 s

Relative to values resolve against the route hierarchy where the link is rendered, so ".." moves up one route and drops that route's whole path pattern. relative="path" makes ".." drop a single URL segment instead.

open as a page

In React Router v7, when do you call useNavigate's navigate() and when do you render <Navigate>, and why must navigate() not run during render?

level: middleimportance: should knowfreq 52%

basics

~20 s

Call navigate() from event handlers or effects after something happens, such as a save completing. Render <Navigate> when the render output itself should be a redirect. navigate() during a component's first render only logs a warning and is ignored.

open as a page

In a React Router v7 settings area, a Back button and the post-save redirect both call navigate(-1); what breaks for deep-linked users, and how do you fix it?

level: seniorimportance: should knowfreq 42%

basics

~20 s

navigate(-1) steps back in the browser history, which is outside the app when the user opened the edit URL directly, so they are sent away. Go back only when location.key is not "default"; otherwise navigate to a known parent route with replace.

open as a page