OneCompiler

Attempted import error: 'Switch' is not exported from 'react-router-dom'.

Failed to compile

./src/App.js
Attempted import error: 'Switch' is not exported from 'react-router-dom'.

My Code

import React from "react";
import {Header, Sidebar, Main, Watch } from "./Components";
import { BrowserRouter as Router, Switch, Route} from "react-router-dom";

function App() {
return (
<Router>
<Switch>
<Route path="/">
<div className="home">
<Header />

      <div className="app">
        <Sidebar />
      <Main />
    </div>
  </div>
</Route>

<Route path="/Watch">
  <Watch/>
</Route>
</Switch> </Router> ); }

export default App;

2 Answers

4 years ago by

Please Solve it

4 years ago by Adarsh Kumar

@Adarsh Kumar Cross check you are using react-router-dom version 5 or below.
From version 6 "Switch" is replaced by "Routes"

4 years ago by Karthik Divi