Install & Setup

How to Download and Install React Router (Step by Step)

React Router installation steps shown as a terminal running npm i react-router

React Router installation takes less than a minute once you know which path fits your project. This walkthrough covers all of them: adding React Router to an app you already have, starting a brand-new app in Framework Mode, and installing the package offline from the file on our download page. Every command below was run against React Router 8.5.3, the current release.

If you only need the short version: open a terminal in your React project and run npm i react-router. Everything else on this page explains what that command needs, what to do if you cannot reach npm, and how to check that it worked.

Before you start: check your versions

React Router 8 raised its minimum requirements. Installing it on an older stack is the number one cause of install errors, so spend thirty seconds on this first.

  1. Check Node.js. Run node -v. You need 22.22.0 or newer. If you see v20 or v18, install a current Node.js LTS release first (a version manager such as nvm, fnm or Volta makes this easy).
  2. Check React. In an existing project, run npm ls react. React Router 8 needs React and React DOM 19.2.7 or newer.
  3. Check your package manager. npm ships with Node.js. pnpm, Yarn and Bun all work too; use whichever your project already uses so you do not end up with two lockfiles.

Still on React 18? Install React Router 7 instead with npm i react-router@7. Version 7 is still maintained and supports React 18. You can move to v8 later, after upgrading React.

For a full table of supported runtimes, bundlers and browsers, see React Router system requirements and compatibility.

Option 1: Add React Router to an existing React app

This is the most common case. You already have a React project, perhaps created with Vite, and you want pages and URLs.

Step 1: Open a terminal in the project folder

The right folder is the one that contains package.json. In VS Code, the built-in terminal opens there by default.

Step 2: Run the install command

Pick the line for your package manager:

npm i react-router
pnpm add react-router
yarn add react-router
bun add react-router

The package manager downloads React Router from its registry and adds a line like "react-router": "^8.5.3" to the dependencies section of package.json.

Step 3: Wrap your app in a router

Open your entry file (usually src/main.jsx or src/main.tsx) and render <BrowserRouter> around the app:

import { createRoot } from "react-dom/client";
import { BrowserRouter } from "react-router";
import App from "./App";

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

That is Declarative Mode, the simplest of the three modes. If you would rather use loaders and actions without a framework, use createBrowserRouter and <RouterProvider> instead (Data Mode). Note that in v8 RouterProvider is imported from react-router/dom.

Step 4: Add your first routes

import { Routes, Route, Link } from "react-router";

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

export default function App() {
  return (
    <>
      <nav>
        <Link to="/">Home</Link> | <Link to="/about">About</Link>
      </nav>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="about" element={<About />} />
      </Routes>
    </>
  );
}

Run npm run dev, open the local URL Vite prints (usually http://localhost:5173) and click between the two links. The URL changes and the heading swaps without a page reload. React Router is installed and working.

Option 2: Start a new app in Framework Mode

If you are starting from scratch and want server rendering, data loading, type-safe routes and code splitting set up for you, let the official starter create the project.

Step 1: Run the create command

npx create-react-router@latest my-app

Other package managers have equivalents: pnpm create react-router@latest my-app, yarn create react-router my-app or bunx create-react-router@latest my-app. The tool asks a couple of questions (such as whether to initialise Git and install dependencies) and then writes the project.

Step 2: Start the dev server

cd my-app
npm i
npm run dev

Open http://localhost:5173. You will see the starter's welcome page, rendered on the server and then hydrated in the browser.

Step 3: Find your way around

  • app/routes.ts lists your routes with helpers like index() and route().
  • app/root.tsx is the HTML shell and top-level layout.
  • app/routes/ holds route modules. Each can export a loader, an action, meta and a default component.
  • react-router.config.ts controls options such as turning server rendering off for a pure SPA.

The starter installs react-router along with the Framework Mode tooling packages @react-router/dev, @react-router/node and @react-router/serve. Keep these on the same version as react-router when you upgrade.

Option 3: Download React Router and install it offline

Some machines cannot reach the npm registry: locked-down company laptops, air-gapped build servers, classrooms with filtered networks. For those, download the package once and install it from the file.

Download React Router 8.5.3

Step 1: Download the package

Our download page provides react-router-8.5.3.tgz, the unmodified tarball published to npm. It is about 650 KB and contains the compiled library, type definitions, the license, the changelog and the bundled docs.

Step 2: Verify the checksum

Before installing any file you downloaded, confirm it has not been altered. Compare the result with the SHA-256 value shown on the download page:

# macOS and Linux
shasum -a 256 react-router-8.5.3.tgz

# Windows PowerShell
Get-FileHash react-router-8.5.3.tgz -Algorithm SHA256

If the values match, the file is byte-for-byte identical to the package on npm. If they do not, delete the file and download it again.

Step 3: Install from the file

Move the file into your project folder, then run:

npm i ./react-router-8.5.3.tgz

npm records it in package.json as "react-router": "file:react-router-8.5.3.tgz". Keep the file in the project (or in a shared folder) so teammates and CI can install it too. For pnpm use pnpm add ./react-router-8.5.3.tgz; for Yarn use yarn add file:./react-router-8.5.3.tgz.

Heads-up: React Router 8.5.3 itself depends on two small packages, cookie-es and @remix-run/route-pattern. On a fully offline machine you will also need those from an internal registry mirror or an npm cache. On most company networks that block only the public internet, an internal mirror already provides them.

Notes for pnpm, Yarn and Bun users

All four package managers install the same React Router package, but a few details differ:

  • pnpm uses a strict node_modules layout. Packages can only import what they declare, which is good for catching mistakes. React Router 8 declares React's type packages as optional peer dependencies, so TypeScript projects should add @types/react and @types/react-dom themselves.
  • Yarn (Berry, version 2 and later) defaults to Plug'n'Play. React Router works with it, but if your editor cannot find types, run yarn dlx @yarnpkg/sdks vscode or switch to nodeLinker: node-modules in .yarnrc.yml.
  • Bun installs very quickly and writes a bun.lock file. Use bun run dev to start Vite. Framework Mode builds still use Vite under the hood.

Whichever you choose, commit the lockfile it creates so every teammate and your CI server install exactly the same version.

Adding TypeScript support

React Router is written in TypeScript and ships its own type definitions, so there is nothing extra to install for the router itself. If your project uses TypeScript, make sure React's types are present too:

npm i -D @types/react @types/react-dom

In Declarative and Data modes you get full autocomplete for components, hooks and route objects right away. In Framework Mode, the dev server also generates types for each route in a hidden .react-router/types folder, so params and loaderData are typed for that exact route. Run npx react-router typegen if your editor ever shows stale route types.

How to check that React Router is installed

Three quick checks confirm a good install:

  1. List the package: npm ls react-router should print react-router@8.5.3 (or the version you chose). If it prints (empty), the install went to a different folder.
  2. Look at package.json: react-router should appear under dependencies, not devDependencies.
  3. Run the app: the test routes above should switch without a full page reload. Open the browser console and make sure there are no red errors.

Common installation problems and quick fixes

npm ERR! ERESOLVE unable to resolve dependency tree

This almost always means your React version is older than React Router 8 allows. Either upgrade with npm i react@latest react-dom@latest or install v7 with npm i react-router@7. Avoid --force and --legacy-peer-deps: they hide the conflict and the app fails at runtime instead.

EBADENGINE Unsupported engine

Your Node.js version is below 22.22.0. Upgrade Node.js, delete node_modules and install again.

Cannot find module 'react-router-dom'

You are following a tutorial written for v6 or v7. In v8 that package no longer exists. Change imports to react-router, and import RouterProvider or HydratedRouter from react-router/dom.

useNavigate() may be used only in the context of a <Router> component

A component that uses a router hook is rendered outside <BrowserRouter> or <RouterProvider>. Move the router higher, usually to main.jsx.

More errors and their fixes are in React Router not working? Common errors and fixes.

Which installation path should you choose?

Your situationCommandMode you get
Existing Vite or CRA-style appnpm i react-routerDeclarative or Data
New full-stack appnpx create-react-router@latest my-appFramework
No access to npmnpm i ./react-router-8.5.3.tgzDeclarative or Data
Project still on React 18npm i react-router@7Any (v7)

What to do next

With React Router installed, the next step is learning the handful of components and hooks you will use every day: Routes, Route, Link, NavLink, Outlet, useNavigate and useParams. Our beginner's walkthrough for using React Router builds a small multi-page app with all of them, and React Router key features explained gives you the bigger picture of what the library can do.

Curious whether the download is safe to use at work? Is React Router safe? License, safety and download sources covers the MIT license, checksums and where each copy comes from.

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