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
Santiago Trujillo
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";
Hello because Switch is exported from react-router
import { Switch } from "react-router";
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.