---
title: Installation
order: 1
---
# Installation
This document describes the most common ways people use React Router with various tools in the React Ecosystem.
- [Basic Installation](#basic-installation)
- [Create React App](#create-react-app)
- [Parcel](#parcel)
- [Webpack](#webpack)
- [HTML Script Tags](#html-script-tags)
## Basic Installation
Most modern React projects manage their dependencies using a package manager like [npm](https://www.npmjs.com/) or [Yarn](https://yarnpkg.com/). To add React Router to an existing project, the first thing you should do is install the necessary dependencies with the tool of your choice:
npm
```sh
$ npm install react-router-dom@6
```
Yarn
```sh
$ yarn add react-router-dom@6
```
pnpm
```sh
$ pnpm add react-router-dom@6
```
## Create React App
Follow the instructions in the [React documentation to set up a new project with Create React App](https://reactjs.org/docs/create-a-new-react-app.html#create-react-app), then follow [the installation instructions above](#basic-installation) to install React Router in your project.
Once your project is set up and React Router is installed as a dependency, open the `src/index.js` in your text editor. Import `BrowserRouter` from `react-router-dom` near the top of your file and wrap your app in a ``:
```js [3, 9-11]
import * as React from "react";
import * as ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
ReactDOM.render(
,
document.getElementById("root")
);
```
Now you can use React Router anywhere in your app! For a simple example, open `src/App.js` and replace the default markup with some routes:
```js [2, 8-12]
import * as React from "react";
import { Routes, Route, Link } from "react-router-dom";
import "./App.css";
function App() {
return (
Welcome to React Router!
} />
} />
);
}
```
Now, still in `src/App.js`, create your route components:
```js
// App.js
function Home() {
return (
<>
Welcome to the homepage!
You can do this, I believe in you.
>
);
}
function About() {
return (
<>
Who are we?
That feels like an existential question, don't you
think?
>
);
}
```
Go ahead and start your app by running `npm start`, and you should see the `Home` route when your app starts running. Click the "About" link to see your `` route, and voilà! You've successfully set up React Router using Create React App! 🥳
When it's time to deploy your app to production, be sure to follow [Create React App's instructions](https://create-react-app.dev/docs/deployment#serving-apps-with-client-side-routing) on deploying with React Router to be sure your server is configured correctly.
## Parcel
Follow the instructions in the [Parcel documentation to set up a new project](https://parceljs.org/getting_started.html), then follow [the installation instructions above](#basic-installation) to install React Router in your project.
In your project's `package.json`, add a `start` script so you can open your project in a browser during development.
```json [2]
"scripts": {
"start": "parcel index.html"
}
```
Once the project is set up and your dependencies are installed, create a new `.babelrc` file at the root of your project:
```json
{
"presets": ["@babel/preset-react"]
}
```
Go to the `index.js` file in your project and import the necessary functions from `react`, `react-dom`, and `react-router-dom` and mount a React app in a `div` with the ID of `root`:
```js
// index.js
import * as React from "react";
import * as ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import App from "./App.js";
ReactDOM.render(
,
document.getElementById("root")
);
```
In your `index.html`, create the root div in the document body above the script tag. It's also helpful to provide a `noscript` fallback message for users who may have disabled JavaScript, unless you plan on server-rendering your app later.
```html
```
Now that React and React Router are set up create a new file `App.js` and add some routes and components:
```js
// App.js
import * as React from "react";
import { Routes, Route, Link } from "react-router-dom";
function App() {
return (
Welcome to React Router!
} />
} />
);
}
function Home() {
return (
<>
Welcome to the homepage!
You can do this, I believe in you.
>
);
}
function About() {
return (
<>
Who are we?
That feels like an existential question, don't you
think?
>
);
}
export default App;
```
Now start your app by running `npm start`, and you should see the `Home` route when your app starts running. Click the "About" link to see your `About` route, and voilà! You successfully set up React Router using Parcel! 🥳
## Webpack
Follow the instructions in the [webpack documentation to set up a new project](https://webpack.js.org/guides/getting-started/), then follow [the installation instructions above](#basic-installation) to install React Router in your project.
Setting up a new React project in webpack is a bit more involved than Parcel or Create React App. Because webpack is a low-level tool that allows you to fine-tune your build to your liking, you may want to read the [webpack documentation](https://webpack.js.org/) or check out [webpack configurations in other repos](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/webpack.config.js) to understand how to build your own.
Once you have webpack configured and the necessary dependencies installed, somewhere in your code (probably towards the root of your React component tree) you can `import` the modules you need from `react-router-dom`.
```js
import {
BrowserRouter,
Routes,
Route,
} from "react-router-dom";
function App() {
return (
Hello, React Router!
} />
);
}
```
## HTML Script Tags
One of the quickest ways to add React and React Router to a website is to use good ol' `