20 entries · 15-question quiz
Building a Multi-Page SPA with React Router
React ↔ Angular reference. React examples use React 19 + TypeScript with React Router's Data Router API (v6.4+, written for v7). Angular examples use modern Angular (standalone components, signals, inject(), @if/@for) with the Angular Router.
Version note: In v7, everything is imported from react-router (RouterProvider from react-router/dom). In v6, the same APIs come from react-router-dom. The concepts are identical.
Test yourself
15 questions
- 1Router Setup:
createBrowserRouterandRouterProvidercreateBrowserRouterbuilds the router from an array of route objects, and<RouterProvider>renders it. Together they enable client-side routing: the URL changes and the matching component renders without a full page reload. - 2JSX Routes with
createRoutesFromElementsAn alternative way to define routes using
<Route>JSX elements, converted into route objects bycreateRoutesFromElements. - 3Navigating with
<Link><Link to="...">performs client-side navigation. It renders an<a>but prevents the full page reload. - 4Layouts and Nested Routes with
<Outlet />A layout route wraps child routes with shared UI (navigation, footer).
<Outlet />marks where the matching child renders. - 5Index Routes and Catch-All Routes
An index route is the default child rendered when the parent's path matches exactly. A catch-all route (
path: '*') matches any URL no other route matches. - 6Active Links with
<NavLink>andend<NavLink>is a<Link>that knows whether it's active, for highlighting the current page in navigation. - 7Programmatic Navigation with
useNavigateuseNavigate()returns anavigatefunction for changing routes from code, e.g. after a timer or a button click that does more than link. - 8Path Params with
useParamsA dynamic segment (
:paramName) in a route path captures part of the URL, anduseParams()reads it. - 9Absolute vs Relative Paths
An absolute path starts with
/and resolves from the root. A relative path has no leading/and resolves from the current route. - 10Query Params with
useSearchParamsuseSearchParams()reads and writes the URL's query string (?role=admin), and re-renders the component when it changes. - 11Loading Data with
loaderanduseLoaderDataA route's
loaderruns before the route renders and fetches its data. The component reads the result withuseLoaderData(). - 12Pending UI with
useNavigationuseNavigation()returns the router's current navigation state, so you can show feedback while a loader or action runs. - 13Error Handling with
errorElementanduseRouteErrorWhen a loader, action, or component throws, React Router renders the nearest
errorElement. Inside it,useRouteError()returns what was thrown. - 14Dynamic Loaders and
useRouteLoaderDataLoaders receive
{ params, request }for dynamic routes. Giving a route anidlets its children read its loader data withuseRouteLoaderData(id). - 15Mutations with
action,<Form>, andredirectA route's
actionhandles form submissions. React Router's<Form>collects the inputs and sends them to the action, which usually returnsredirect(). - 16Programmatic Submission with
useSubmituseSubmit()returns a function that triggers a route action from code, without a<Form>. - 17Validation Feedback with
useActionDataIf an action returns data instead of a redirect,
useActionData()gives the component that data, typically server validation errors. - 18Updates Without Navigation:
useFetcheruseFetcher()calls a loader or action without navigating. It's an isolated mini-form for in-place updates. - 19Organizing a Router Project
A folder structure and set of conventions that keep routes, pages, and data logic separate.
- 20Summary