I don’t know why I am getting this error and I can’t find an answer for it anywhere. I have uninstalled the react-router-dom package and reinstalled it, but it continues to tell me that the switch module is not exported from react-router-dom. Here’s my code.
The error I’m getting:
Attempted import error: ‘Switch’ is not exported from ‘react-router-dom’.
Code
import React from ‘react’;
import ‘./App.css’;
import NavBar from ‘./components/navbar.js’;
import Footer from ‘./components/footer.js’;
import Home from ‘./components/pages/homepage/home.js’;
import { BrowserRouter as Router, Switch, Route, Link } from ‘react-router-dom’;
function App() {
return (
);
}
export default App;
In react-router-dom v6, \”Switch\” is replaced by routes \”Routes\”. You must update the import from import Switch, Route- from \”react- router–dom\”; you have to re-update import.\n\n\’react-router-dom\’ to import Routes ,Route .\n\nSimilarly, you have to update the Route declaration from Route path=\”/\” component=Home />.\n\nto Route path=\’/\’ element=Home/> / .\n\nIn react-router-dom, you don\’t have to use the exact in the Route declaration. For more information, visit the official documentation: upgrade to respond- Router–dom v6.