Setting Up React Router
Learn about installing the React Router.
We'll cover the following...
In this section, we are going to install React Router with the corresponding TypeScript types by carrying out the following steps:
Make sure the frontend project is open in Visual Studio Code and enter the following command to install React Router in the terminal:
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 runningnpm install react-router-dom@next
.
React router has a peer dependency on the
history
package, so let’s install this using the terminal as well:
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.