when I import switch from react-router-dom error screen shot when I import switch from react-router enter image description here
I copied code from https://v5.reactrouter.com/web/guides/quick-start
CodePudding user response:
Switch is exported from "react-router", not from "react-router-dom"
CONVERT THIS:
import { Switch } from "react-router-dom";
TO:
import { Switch } from "react-router";
CodePudding user response:
Hello because Switch is exported from react-router
import { Switch } from "react-router";
CodePudding user response:
I have faced similiar problem with importing Switch from react-router-dom. In my case, I was using the latest (v6, i think) version of react-router-dom where the "Switch" is replaced by "Routes".
So either you check your react-router-dom's version and replace Switch to Routes and change the Route declaraton from <Route path="/" component={Dashboard} /> to <Route path="/" element={Dashboard} /> if it's v6, or you want to downgrade your react-router-dom version and keep using Switch.
Your call.
CodePudding user response:
Try to install npm i [email protected] this version Switch working in this version
