Tutorials

React Router for Beginners: Key Features Explained

React Router features shown as connected tiles for routes, params, loaders and modes

React Router has grown from a simple URL-to-component matcher into a full routing toolkit, and in version 7 it absorbed the Remix framework as well. That is great for power, but it can make the feature list feel overwhelming when you are new. This article walks through the React Router features you will actually use, grouped from "day one" to "when your app grows", with a short example of each.

Everything here applies to React Router 8.5.3. If you want to follow along in code, install it with our step-by-step installation walkthrough.

Day-one features

1. Declarative routes

You describe which component belongs to which URL, and React Router handles the rest. There is no manual if (location === ...) logic.

<Routes>
  <Route path="/" element={<Home />} />
  <Route path="pricing" element={<Pricing />} />
</Routes>

2. Client-side navigation with Link

<Link> renders a real <a href>, so it works with keyboard navigation, screen readers, right-click and "open in new tab". When clicked normally, React Router intercepts it and updates the page without asking the server for new HTML. Pages feel instant, and the browser's Back and Forward buttons keep working.

3. Active links with NavLink

<NavLink> is a Link that knows whether it matches the current URL. It adds an active class and aria-current="page" automatically, and accepts functions for className and style:

<NavLink to="/inbox" className={({ isActive }) => isActive ? "tab on" : "tab"}>
  Inbox
</NavLink>

It also exposes isPending, which is handy for showing a subtle loading state on the link the user just clicked.

4. Navigating in code

The useNavigate hook returns a function you can call after any event: a login, a saved form, a timer. Use navigate("/home") to go somewhere, navigate(-1) to go back, and { replace: true } when the current page should not stay in history.

Features for structuring bigger apps

5. Nested routes and layouts

This is the feature that makes React Router scale. Routes can contain routes, and each parent decides where its child appears using <Outlet />. A settings area with its own sidebar looks like this:

<Route path="settings" element={<SettingsLayout />}>
  <Route index element={<Profile />} />
  <Route path="billing" element={<Billing />} />
  <Route path="security" element={<Security />} />
</Route>

The sidebar inside SettingsLayout stays mounted while only the inner panel changes. Routes without a path ("layout routes") let you share a layout between URLs that have nothing in common, such as wrapping all logged-in pages in one shell.

6. Dynamic, optional and splat segments

  • Dynamic: /projects/:projectId matches /projects/42 and gives you projectId = "42" through useParams.
  • Optional: /:lang?/about matches both /about and /fr/about.
  • Splat: /files/* matches /files/a/b/c.txt and puts a/b/c.txt in params["*"].

React Router ranks all paths so the most specific match wins, regardless of the order you wrote them in.

7. Search params

Filters, sorting and pagination belong in the query string so they survive a refresh and can be shared. useSearchParams reads and writes them like React state:

const [params, setParams] = useSearchParams();
const sort = params.get("sort") ?? "newest";
setParams({ sort: "price" }); // URL becomes ?sort=price

Data features (Data and Framework modes)

8. Loaders

A loader is a function attached to a route that fetches the data that route needs. React Router calls it before rendering, in parallel for every matched route, so nested pages do not create a waterfall of spinners.

{
  path: "projects/:projectId",
  loader: async ({ params }) => fetchProject(params.projectId),
  Component: Project,
}

Inside the component, useLoaderData() returns the result.

9. Actions and Form

Actions handle data changes. A <Form method="post"> submits to the route's action, and after the action finishes React Router automatically re-runs the loaders on the page so the UI shows fresh data. No manual cache juggling.

10. Pending and optimistic UI

useNavigation() tells you when a navigation or submission is in progress, and useFetcher() lets you load or submit data without changing the URL, which is perfect for "like" buttons and inline edits.

11. Middleware

In v8, middleware is always on. It runs before loaders and actions, which makes it the natural place for authentication checks, logging and shared context.

12. Error boundaries

Each route can export an ErrorBoundary. If its loader, action or component throws, only that part of the page is replaced with the error UI, and the rest of the layout keeps working.

13. Scroll restoration and navigation blocking

Two small features make apps feel polished. <ScrollRestoration /> (Data and Framework modes) remembers the scroll position of each page, so pressing Back returns users to where they were in a long list instead of the top. useBlocker lets you stop a navigation when a form has unsaved changes and ask the user to confirm before leaving. Both replace code that teams used to write by hand, and both respect the browser's normal behaviour where they can.

Framework Mode features

Framework Mode wraps everything above in a Vite plugin and adds:

  • Route modules: one file per route exporting loader, action, meta, ErrorBoundary and the component.
  • Type safety: generated types for params and loader data, plus a type-checked href() helper that catches links to routes that do not exist.
  • Automatic code splitting: each route's code loads only when needed.
  • Rendering strategies: server-side rendering, a static SPA, or pre-rendering selected URLs at build time.

The three modes at a glance

FeatureDeclarativeDataFramework
Routes, Link, NavLink, paramsYesYesYes
Loaders, actions, fetchersNoYesYes
MiddlewareNoYesYes
Type-safe route modulesNoNoYes
SSR and pre-renderingNoManualBuilt in
Setup effortLowestLowStarter template

The modes are additive. You can start in Declarative Mode and move up later without throwing away your components.

Download React Router 8.5.3

Which features should a beginner learn first?

Learn them in this order: routes, Link, NavLink, nested routes with Outlet, useParams, useNavigate. That set is enough to build most single-page apps, and it is exactly what our beginner's walkthrough covers. Then add search params, and move to loaders and actions once you notice data fetching spreading across your components.

For real projects that use these features together, see Best uses for React Router (real examples).

Get React Router 8.5.3: one npm command, or the verified package download.

Download

Tivari

Professional content writer

Tivari is a professional content writer who covers web development tools, with a focus on turning technical documentation into clear, step-by-step articles. Every command and code sample in Tivari's articles is run against the current React Router release before publishing. About the writer and how we test.

Related articles