React Routing Cheatsheet
Learn how to set up React Router v6, define routes, nested routes, and navigation.
· 8 min read · AI-reviewed
Learn how to set up React Router v6, define routes, nested routes, and navigation.
Source: z2h.fyi/cheatsheets/react-routing — Zero to Hero cheatsheets for developers.
React Router v6 provides a declarative way to handle client‑side navigation in React applications.
npm i react-router-dom@6.<BrowserRouter>.| Concept | Description |
|---|---|
| Routes | Define a path → element mapping. |
| Nested Routes | Build layout hierarchies. |
| Params | Extract URL parameters. |
| Redirects | Use <Navigate> for redirects. |
| Lazy Loading | Load route components lazily. |
<Routes><Route path="/about" element={<About/>} /></Routes>useParams() – read dynamic segments.useNavigate() – programmatic navigation.const About = React.lazy(() => import('./About')) – lazy route.<Outlet> for children.fallback UI when using lazy routes.useNavigate replaces the older history API.