How does client-side routing work in a React SPA?
Quick answer
A router (e.g. React Router) maps URLs to components and updates the view via the History API without a full page reload.
In detail
In an SPA the server sends one HTML shell; the router intercepts navigation, uses history.pushState to change the URL, and renders the matching component. This gives instant transitions and preserved app state. You define routes, use <Link> instead of <a> to avoid reloads, and read params/search via router hooks.
<Routes>
<Route path="/" element={<Home />} />
<Route path="/kit/:slug" element={<Kit />} />
</Routes>
// const { slug } = useParams();Why interviewers ask this: Routing is part of almost every real React app.
Common follow-up questions
- →Why use <Link> instead of <a>?
This is 1 of 118+ questions in the React Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the React Interview Kit → ₹399