Part 15 / Topic 0 of 9
Installing React Router, and the mode this course teaches
npm install react-router resolved [email protected] at the time this part was written (re-check node_modules/react-router/package.json yourself before trusting that number - this ecosystem moves fast). One package, one name: react-router ships everything - BrowserRouter, Link, useParams, all of it - there is no separate react-router-dom to install alongside it, and no v8 vs v6 import-path difference to remember.
The installed package's own docs/ (shipped inside node_modules/react-router/docs/, not fetched from anywhere) spell out something worth knowing before writing a single route: React Router v7+ has three modes - Declarative, Data, and Framework - and they are additive, each adding more machinery (and more to learn) than the last:
| Mode | Top-level API | Adds |
|---|---|---|
| Declarative | <BrowserRouter> + <Routes>/<Route> |
matching a URL to an element, <Link>, useNavigate, useLocation - routing only |
| Data | createBrowserRouter([...]) + <RouterProvider> |
loader/action functions, useLoaderData, redirect(), pending-navigation UI |
| Framework | a Vite plugin on top of Data mode | file conventions, type-safe routes, SSR/SSG |
This course teaches Declarative mode, on purpose, for a reason specific to this course: Part 11 already spent a full lesson teaching fetch + useEffect + AbortController by hand, deliberately before handing students a library that solves data-fetching for them. Data mode's loader is exactly that kind of library-solves-it tool, one part early - introducing it here would mean a routed page fetches its data completely differently from every non-routed page in this course, with no reason for the difference other than "this one happens to be reached via a route." Declarative mode has no loader, no useLoaderData, no redirect() - a routed page fetches data exactly the way Part 11 already taught, reading whatever id it needs from useParams instead of a prop. Section 6 below is this choice, worked through completely.
⚠️ If you learned React Router from an older tutorial or the reference material behind this course: you may have seen
createMemoryRouter,loader, andredirect()used for a protected route with a redirect. That is Data mode, correct for that mode, and not what this part teaches - this part's protected route (Section 7) reaches the identical end result (a signed-out visitor lands on/login?next=/account) with a plain component and<Navigate/>, no loader involved. Both are legitimate, officially documented approaches; this course picked Declarative mode specifically to stay consistent with Part 11, not because Data mode is wrong.
Done here? The practice set for Part 15 — including the solutions — is on the part page.