0

I want to add a simple route diagram in the react application that I have installed with vite, but I am getting an error.

Error: Uncaught SyntaxError: The requested module '/node_modules/.vite/deps/react-router-dom.js?v=8b3cf1e8' does not provide an export named 'Switch'

import './App.css';
import {Login} from './pages/Login';
import {Register} from "./pages/Register";
import {MainLayout} from './layouts/MainLayout';
import { BrowserRouter as Router, Route,Switch } from 'react-router-dom';


function App() {
  return (
    <div>
      <Router>
      <Switch>
        <Route exact path="/" component={Register} />
        <Route path="/login" component={Login} />
        <Route path="/dashboard" component={MainLayout} />
      </Switch>
    </Router>
    </div>
  );
};

export default App
"dependencies": {
    "@reduxjs/toolkit": "^1.9.3",
    "antd": "^5.3.2",
    "axios": "^1.3.4",
    "dotenv": "^16.0.3",
    "js-base64": "^3.7.5",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-icons": "^4.8.0",
    "react-redux": "^8.0.5",
    "react-router-dom": "^6.9.0"
  }

I deleted the node/modules folder and did npm install but the problem still persists.

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
Jiddo
  • 23
  • 3
  • 2
    Did you upgrade from an older version of react-router-dom? v6 does not support the switch component. Use Routes in place of Switch . Reference: https://reactrouter.com/en/v6.3.0/upgrading/v5#upgrade-all-switch-elements-to-routes – Phanisimha N R Mar 28 '23 at 07:28
  • 1
    After addressing the `Switch` -> `Routes` issue you'll next need to tackle rendering the routed content correctly on the `Route` component's `element` prop ***as JSX***. See the [Upgrading from v5](https://reactrouter.com/en/main/upgrading/v5) migration guide for all the breaking changes and parts you may need to update. – Drew Reese Mar 28 '23 at 07:55

0 Answers0