Module not found: Can't resolve 'react-router-dom'


I got the following error when I tried to import and use the 'react-router-dom' package in my React application.

Module not found: Can't resolve 'react-router-dom' in 'D:\Projects\MyProject\src'

My code is given below.

import {Route} from 'react-router-dom';
import Page1 from './pages/Page1';
import Page2 from './pages/Page2';
import Page3 from './pages/Page3';
function App() {
  return <div>
<Route path='/' exact>

<Route path='/page2'>

<Route path='/Page3'>


export default App;



I didn't install the react-router-dom package in my react application. That was the reason for the error. I installed the package using the following command. 

npm install react-router-dom

This fixed the issue. This package allows us to add routing functionality to React.