Installing and configuring React Router
After you create a new React application using create-react-app, the first thing you need to do is to install React Router v6.x, using the following command:
npm install react-router-dom @types/react-router-dom
You are probably confused about why we are installing react-router-dom instead of react-router. React Router contains all the common components of react-router-dom and react-router-native. That means that if you are using React for the web, you should use react-router-dom, and if you are using React Native, you need to use react-router-native.
The react-router-dom package was created originally to contain version 4 and react-router uses version 3. The react-router-dom v6 package has some improvements over react-router. They are listed here:
- Simplified route configuration: React Router v6 has introduced a more straightforward route configuration, eliminating the need for
Switchand exact props. Routes are now implicitly...