{"id":138,"hash":"2e291e44441553e40b678947fc431561a19af7e843d25aaeef345bf1908f8106","pattern":"Attempted import error: &#39;Switch&#39; is not exported from &#39;react-router-dom&#39;","full_message":"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.\n\nThe error I'm getting:\n\nAttempted import error: 'Switch' is not exported from 'react-router-dom'.\n\nCode\nimport React from 'react';\nimport './App.css';\nimport NavBar from './components/navbar.js';\nimport Footer from './components/footer.js';\nimport Home from './components/pages/homepage/home.js';\nimport { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom';\n\nfunction App() {\n  return (\n    <Router>\n      <div className=\"app-container\">\n        <NavBar />\n        <Switch>\n          <Route path=\"/home\" component={Home} />\n        </Switch>\n        <Footer />\n      </div>\n    </Router>\n  );\n}\n\nexport default App;","ecosystem":"npm","package_name":"reactjs","package_version":null,"solution":"In react-router-dom v6, \"Switch\" is replaced by routes \"Routes\". You need to update the import from\n\nimport { Switch, Route } from \"react-router-dom\";\n\nto\n\nimport { Routes ,Route } from 'react-router-dom';\n\nYou also need to update the Route declaration from\n\n<Route path=\"/\" component={Home} />\n\nto\n\n<Route path='/' element={<Home/>} />\n\nIn react-router-dom, you also do not need to use the exact in the Route declaration.\n\nFor more information, you can visit the official documentation:\nupgrade to react-router-dom v6","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/63124161/attempted-import-error-switch-is-not-exported-from-react-router-dom","votes":775,"created_at":"2026-04-19T04:41:23.141097+00:00","updated_at":"2026-04-19T04:51:05.197283+00:00"}