Solved - react jsexport 'Switch' (imported as 'Switch') was not found in 'react-router-dom'
Sep 16, 2022 . Admin
Hello Friends,
Today, I will let you know example of react js export 'switch' (imported as 'switch') was not found in 'react-router-dom'. This article goes in detailed on react js switch not working. It's a simple example of react js router switch not working . We will look at an example of react js router switch not found.
few days ago i was working on my old react js code and i found following error:
react jsexport 'Switch' (imported as 'Switch') was not found in 'react-router-dom'
I found above error because i used "Switch" in App.js file as the below:
import { Switch, Route, Link } from "react-router-dom";
But after research i found solution.
react-router-dom npm package replace "c" with "Routes". so you need to use "Routes" instead of "Routes". You can see the below solution code:
import "bootstrap/dist/css/bootstrap.min.css"; import Post from './Post'; import React from "react"; import { Routes, Route, Link } from "react-router-dom"; function App() { return ( <div> .... <div className="container mt-3"> <Routes> <Route exact path={["/", "/tutorials"]} component={Post} /> <Route exact path="/add" component={Post} /> <Route path="/tutorials/:id" component={Post} /> </Routes> </div> </div> ); } export default App;
I hope it can help you