Setting Up React Router

Learn about installing the React Router.

In this section, we are going to install React Router with the corresponding TypeScript types by carrying out the following steps:

  1. Make sure the frontend project is open in Visual Studio Code and enter the following command to install React Router in the terminal:

Press + to interact
npm install react-router-dom

Note: Make sure react-router-dom version 6+ has been installed and listed in package.json. If version 5 has been installed, then version 6 can be installed by running npm install react-router-dom@next.

  1. React router has a peer dependency on the history package, so let’s install this using the terminal as well:

Press + to interact
npm install history

A peer dependency is a dependency that is not automatically installed by npm. This is why we have installed it in our project.

That’s it—nice and simple! We’ll start to declare the routes in our app in the next section.

Declaring routes

...