How to fix error: Attempted import error: 'Route' is not exported from 'react-router-dom'

Close the server and restart it. It Works Fine.

npm start or yarn start


I was having the same issue. You may have a conflict with NPM and YARN. I deleted my yarn.lock and ran it again with only package.lock; and it worked.

You should only use Yarn or NPM.


I was stuck on this as well... For me it worked when the version of "react-router" and "react-router-dom" matched.

"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",

This issue is happening because of the version of react-router-dom. Try updating the react-router-dom to version 6.

Just run the command:

npm install [email protected]

import React, { Component } from 'react';
import Navbar from './components/Navbar'
import { BrowserRouter, Route ,Switch} from 'react-router-dom'
import Home from './components/Home'

class App extends Component {
render() {
  return (
    <BrowserRouter>
     <div className="App">
     <Navbar />
      <Switch>
      <Route exact path='/' component={Home} />
    </Switch>

    </div>
    </BrowserRouter>
   );
  }
  }

  export default App;

try this way