Use Cases

Best Uses for React Router (Real Examples)

React Router examples: dashboard, store, login and search layouts drawn as wireframes

Feature lists only go so far. The best way to understand React Router is to see how real applications put it to work. Below are six patterns you will find in production apps, from admin dashboards to online stores, each with the route setup and the handful of lines that make it work. The examples use React Router 8 and plain JSX, and they are short on purpose so you can adapt them.

New to the basics? Read How to Use React Router: A Beginner's Walkthrough first. It explains Routes, Outlet and useParams step by step.

1. Admin dashboard with a persistent sidebar

The need: a sidebar and top bar that never reload, with reports, users and settings swapping in the main area. Each section should have its own URL so people can bookmark "Users" or share a link to "Reports".

The pattern: a layout route renders the shell and an <Outlet />; every section is a child route.

<Route path="admin" element={<AdminShell />}>
  <Route index element={<Overview />} />
  <Route path="reports" element={<Reports />} />
  <Route path="users" element={<Users />} />
  <Route path="users/:userId" element={<UserDetail />} />
  <Route path="settings" element={<Settings />} />
</Route>

Inside AdminShell, the sidebar uses NavLink so the current section is highlighted automatically. Because the shell stays mounted, scroll position in the sidebar, open menus and any WebSocket connection survive navigation. In Data or Framework Mode, each section's loader fetches its data in parallel when the route matches.

2. Online store with category and product pages

The need: clean, readable URLs like /shop/shoes/sku-1042 that search engines can index and customers can share.

The pattern: two dynamic segments.

<Route path="shop">
  <Route index element={<AllCategories />} />
  <Route path=":category" element={<Category />} />
  <Route path=":category/:sku" element={<Product />} />
</Route>
function Product() {
  const { category, sku } = useParams();
  // fetch product by sku, show breadcrumbs using category
}

For SEO, stores usually pick Framework Mode so product pages are rendered on the server or pre-rendered at build time, with a meta export that sets the title and description for each product.

3. Login-protected areas

The need: anything under /account must only be visible to signed-in users. Guests should land on /login and come back where they started after signing in.

The pattern in Declarative Mode: a guard layout that either renders the outlet or redirects.

import { Navigate, Outlet, useLocation } from "react-router";

function RequireAuth() {
  const user = useUser();          // your auth hook
  const location = useLocation();
  if (!user) {
    return <Navigate to="/login" replace state={{ from: location.pathname }} />;
  }
  return <Outlet />;
}

<Route element={<RequireAuth />}>
  <Route path="account" element={<Account />} />
  <Route path="orders" element={<Orders />} />
</Route>

After login, read location.state.from and call navigate(from, { replace: true }).

In Data or Framework Mode the cleaner place for this check is middleware or a loader, which runs before any protected data is fetched: if there is no session, throw redirect("/login"). Remember that a client-side guard only hides UI; your API must still check permissions on the server.

4. Search and filter pages

The need: a job board or product search where users combine filters. Refreshing the page or sharing the link must keep the same results.

The pattern: store every filter in the query string with useSearchParams instead of component state.

function Jobs() {
  const [params, setParams] = useSearchParams();
  const remote = params.get("remote") === "1";
  const sort = params.get("sort") ?? "newest";

  function toggleRemote() {
    setParams((prev) => {
      remote ? prev.delete("remote") : prev.set("remote", "1");
      return prev;
    });
  }
  // fetch jobs using remote and sort ...
}

Now /jobs?remote=1&sort=salary is a complete, shareable view. The Back button steps through filter changes too, which users expect on search pages. If you do not want every keystroke in a search box to create a history entry, pass { replace: true } as the second argument to setParams.

5. Blog or documentation site

The need: fast pages with good SEO and readable slugs like /blog/react-router-tips.

The pattern: Framework Mode with pre-rendering. Routes are defined in app/routes.ts, and react-router.config.ts lists the URLs to render to static HTML at build time:

// app/routes.ts
import { index, route } from "@react-router/dev/routes";
export default [
  index("./routes/home.tsx"),
  route("blog/:slug", "./routes/post.tsx"),
];

// react-router.config.ts
export default {
  async prerender() {
    const slugs = await getAllSlugs();
    return ["/", ...slugs.map((s) => `/blog/${s}`)];
  },
};

Each post loads instantly as static HTML, then becomes a fully interactive React app after hydration. Links between posts are client-side navigations, so moving around the site feels immediate.

6. Multi-step forms and wizards

The need: a checkout or onboarding flow with several steps, where Back works and each step can be linked to directly.

The pattern: one child route per step inside a wizard layout that holds shared state and a progress bar.

<Route path="checkout" element={<CheckoutLayout />}>
  <Route index element={<Navigate to="shipping" replace />} />
  <Route path="shipping" element={<Shipping />} />
  <Route path="payment" element={<Payment />} />
  <Route path="review" element={<Review />} />
</Route>

CheckoutLayout keeps the order data (in context or the Outlet's context prop) so it survives step changes, and highlights the current step with NavLink. Each step's "Continue" button calls navigate("../payment").

Common mistakes with these patterns

  • Forgetting the Outlet. Every layout in the examples above must render <Outlet />, or child pages appear blank.
  • Storing filters in state. If a filter is not in the URL, a refresh or a shared link loses it. Put anything a user might want to share into search params.
  • Absolute paths in nested routes. Inside a parent route, write path="users", not path="/users", unless you really mean to break out of the parent.
  • Trusting the client guard. The auth layout improves the experience, but the real permission check belongs on the server.

Choosing a mode for your use case

Use caseRecommended modeWhy
Internal dashboardDataLoaders per panel, no SEO needs
Online storeFrameworkSSR for SEO and fast first load
Protected appData or FrameworkMiddleware runs before data loads
Search pageAnyuseSearchParams works everywhere
Blog or docsFrameworkPre-rendering to static HTML
Wizard in an existing appDeclarativeSmallest change to the codebase

Download React Router 8.5.3

Want the reasoning behind each feature used here? React Router key features explained covers them one by one. If an example throws an error in your project, common React Router errors and fixes has the solution for the usual suspects.

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