0
Attempted import error : 'Switch' is not exported from 'react-router-dom' (imported as 'Switch').
3 Answers
0
Just found out that The syntax has changed.
Old Syntax:
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
<Switch>
<Route path="/home" component={Home} />
</Switch>
New Syntax:
import { BrowserRouter as Router, Routes, Route, Link } from "react-router-dom";
<Routes>
<Route path="/home" element={<Home/>} />
</Routes>
But should I use the new syntax or just downgrade the react-router-dom ?
+ 2
I also got the same error some minutes ago. Technologies will be changing constantly. So new syntax is better to use than to downgrade, I think.
+ 2
Kashyap Kumar Yes, you're right. I also decided to use Routes instead of Switch.