React Router
React Router keeps the URL in sync with which component is on screen, without a full page reload. Wrap the app in BrowserRouter. Use <Link to="/about"> for in-app jumps — not <a href="/about">, which reloads and wipes React state. Declare screens with <Routes> and <Route path="/about" element={<About />} />.
Nested routes let a layout keep the sidebar while the middle changes. useParams() reads /users/:id. useNavigate() jumps after login: navigate('/dashboard', { replace: true }) so the back button does not return to the login form. useSearchParams() is for ?q=asha filters.
Let’s click About on the board. URL becomes /about. About component paints. Home unmounts. Cart state in a parent still alive if that parent did not unmount. Click a raw <a href="/about"> instead → full load, cart empty. That contrast is the router viva.
Deploy trap belongs with BrowserRouter: refresh on /about must not 404. The server (or host rewrite) should serve index.html for unknown paths. HashRouter (/#/about) avoids that but looks uglier. Say both.
Trap: wrapping every tiny widget in its own Router. Trap: <a> for internal links. Trap: forgetting a * splat or a NotFound route. Trap: putting BrowserRouter below a component that needs useNavigate (hook must run under the router).
React Router — click About → URL /about, screen About. No full page reload. Link, not <a> for in-app.
URL /about
│ BrowserRouter
▼
<Route> → About
│ Link
▼
no full reloadBrowserRouter + Link + Route element.