0

Attempted import error : 'Switch' is not exported from 'react-router-dom' (imported as 'Switch').

https://www.sololearn.com/post/1713839/?ref=app

28th Oct 2022, 11:35 AM
Asha
Asha - avatar
3 odpowiedzi
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 ?
28th Oct 2022, 11:41 AM
Asha
Asha - avatar
+ 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.
28th Oct 2022, 12:10 PM
Kashyap Kumar
Kashyap Kumar - avatar
+ 2
Kashyap Kumar Yes, you're right. I also decided to use Routes instead of Switch.
28th Oct 2022, 1:45 PM
Asha
Asha - avatar