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.
#1 Best Overall
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.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallHow 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.
Rank #3
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.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesHow 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:
Rank #4
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.
Best Value
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:
pathfor the route pattern andelementfor the rendered UI.Componentas an alternative component-based prop; use eitherelementorComponent, not both.childrenfor nested route declarations, andindexfor a default child at the parent URL.loaderandactionfor data-router route configuration.errorElementorErrorBoundaryfor error handling; these paired alternatives are mutually exclusive.lazyandcaseSensitivefor 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.
Quick Recap
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.




