Skip to content
Agents tracked: 440 Downloads (7d): 202M down 19.5% GitHub stars: 10.4M Releases (7d): 607 Agent status: 1 with issuesSince last limit reset: Claude 28d · Codex 0d Updated Oct 21, 2026

Basic routing in React Router

React Router maps URL paths to components. Links change the location and the matching route renders its element.

All React Router examples React Router: usage and stats

Basic routing in React Router: screenshot of the example below running
The code below, running in Chromium on our server (Oct 12, 2026). Press Run to see it live and change it.

How it works

  1. Keep history in memory. The sandbox has no address bar, so the app uses MemoryRouter with initialEntries={['/']} instead of a browser router. [1]
  2. Declare the routes. <Routes> holds one <Route> per page. Each route pairs a path with the element to render. [2]
  3. Link between pages. The nav bar uses <Link to="/about"> and friends. Clicking one changes the location, and the matching page renders below. [3]
  4. Read the location. CurrentPath calls useLocation() and prints location.pathname, so you can see the in-memory URL change. [4]

Run and edit it

It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.

Checked Oct 12, 2026: it starts without errors in Chromium with react-router-dom 7.18.4, react 19.3.0, react-dom 19.3.0. Needs WebGL.

More React Router examples

Nested routes with Outlet in React Router URL params with useParams in React Router Active links with NavLink in React Router Programmatic navigation with useNavigate

Sources

  1. Docs: api › declarative-routers › MemoryRouter
  2. Docs: start › declarative › routing
  3. Docs: start › declarative › navigating
  4. Docs: start › declarative › url-values

Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.

Building something with React Router? Ask AgentGid →