Search⌘ K
AI Features

Setting Up React Router

Explore the process of setting up React Router with TypeScript in a React frontend project. Learn how to create blank pages and declare routes using BrowserRouter, Routes, and Route components to enable smooth multi-page navigation within a single-page application.

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:

Node.js
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:

Node.js
npm install history

A peer dependency is a dependency that is ...