Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

React Router Route Component: How to Use `` with Examples

Use React Router’s to connect URL patterns to UI. See working examples of basic pages, nested layouts with Outlet, index routes, dynamic parameters, splats, and when to choose a data router.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In React Router v7, <Route> declares a URL pattern and the UI or route behavior to use when that pattern matches. In declarative routing, put routes inside <Routes> and place that tree inside a router such as <BrowserRouter>. Use nested routes and <Outlet /> for shared layouts, index routes for a parent’s default page, and dynamic segments for URL parameters.

One important distinction: declarative <Routes> selects a matching route branch, but does not provide loaders, actions, or route-module code splitting. If you need those features, use a data router such as createBrowserRouter.

What does the React Router <Route> component do?

A <Route> describes a route: a path pattern and the element or other route behavior associated with a match. It is not used as a standalone component in declarative routing; it must be rendered within <Routes>. <Routes> selects the best matching branch for the current location.

Current React Router v7 documentation uses imports from react-router in its declarative examples. Older projects or version-specific examples may use react-router-dom; follow the imports for the version installed in your application. See the Route reference and declarative routing guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Minimal working example

Wrap the route tree in <BrowserRouter>, then declare the pages inside <Routes>:

import React from "react";
import ReactDOM from "react-dom/client";
import { BrowserRouter, Routes, Route } from "react-router";

function Home() {
  return <h1>Home</h1>;
}

function App() {
  return (
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Home />} />
      </Routes>
    </BrowserRouter>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);

Here, path="/" matches the root URL, and element={<Home />} supplies the UI for that route.

How to declare multiple routes

Add a <Route> for each page. A route path without a leading slash can be written relative to the route tree’s root:

<Routes>
  <Route path="/" element={<Home />} />
  <Route path="about" element={<About />} />
</Routes>

For a larger application, group related routes under parent routes rather than building every URL as an unrelated top-level entry.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How nested routes and <Outlet /> work

A child route inherits its parent’s path. The parent component renders the matched child at the position where it places <Outlet />:

import { Outlet } from "react-router";

function Dashboard() {
  return (
    <main>
      <h1>Dashboard</h1>
      <Outlet />
    </main>
  );
}

<Routes>
  <Route path="dashboard" element={<Dashboard />}>
    <Route index element={<DashboardHome />} />
    <Route path="settings" element={<Settings />} />
  </Route>
</Routes>

The index child renders at /dashboard; the settings child renders at /dashboard/settings. Without an <Outlet /> in Dashboard, the parent has no place to display the selected child.

Index routes

An index route supplies the default child UI at the parent route’s URL. It has no path of its own and cannot have children.

Layout routes and path-prefix routes

A route with an element but no path can create a layout grouping without adding a URL segment. For example, an authentication layout can wrap login and registration screens while their paths remain unchanged. By contrast, a path-only parent can group child URLs under a prefix without adding a layout component. These patterns solve different needs: one adds shared UI nesting, the other groups paths. The routing guide covers nested routes and layouts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to read a URL parameter from a route

A colon-prefixed path segment is dynamic. React Router exposes the matched value as a parameter through APIs such as useParams:

import { useParams } from "react-router";

function Team() {
  const { teamId } = useParams();
  return <h1>Team {teamId}</h1>;
}

<Route path="teams/:teamId" element={<Team />} />

For a URL such as /teams/42, the route’s parameter key is teamId, and its matched value is available to the component through useParams.

How to match trailing path content

Use a splat, written with *, when a route should match trailing path content that can include additional slash-separated segments:

<Route path="files/*" element={<Files />} />

This is a catch-all pattern for the remainder of the path, not a named segment such as :teamId. The declarative routing guide shows the splat pattern.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When to use <Routes> versus createBrowserRouter

Choose according to the features the application needs. Declarative JSX routes are suitable when the main requirement is selecting UI from URL patterns. The official Route reference notes that routes rendered under <Routes> do not participate in data loading, actions, code splitting, or other route-module features.

Approach Route definition Data and route-module features Use it when
Declarative routing JSX elements inside <Routes> Does not provide loaders, actions, or route-module code splitting You want a direct JSX route tree for matching URLs to UI
Data router Route objects passed to createBrowserRouter; JSX route trees can also be converted with createRoutesFromElements Supports route configuration such as loaders and actions, along with data-router features You need route data APIs or route-module capabilities

For example, the data-router approach configures route objects, including nested children and a loader. It is a different setup from placing a declarative route tree inside <BrowserRouter>. See the data routing guide and the Route reference.

Common <Route> props

The v7 Route reference documents properties including:

  • path for the route pattern and element for the rendered UI.
  • Component as an alternative component-based prop; use either element or Component, not both.
  • children for nested route declarations, and index for a default child at the parent URL.
  • loader and action for data-router route configuration.
  • errorElement or ErrorBoundary for error handling; these paired alternatives are mutually exclusive.
  • lazy and caseSensitive for additional route behavior.

Not every prop applies to every routing setup. In particular, do not add loaders or actions to a basic declarative <Routes> tree expecting it to gain data-router behavior; use route configuration with createBrowserRouter when those APIs are required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.