I used vite to create a react project and reported an error when doing nested routing
The error prompt is the following code:
import { BrowserRouter, Route, Switch } from 'react-router-dom';
There is an error in the switch.
The NPM package version of the project at that time is as follows:
{ …… "dependencies": { "react": "^17.0.0", "react-dom": "^17.0.0", "react-router": "^6.0.2", "react-router-dom": "^6.0.2" }, "devDependencies": { "@vitejs/plugin-react": "^1.0.0", "vite": "^2.6.4" } }
There is a switch method in the react route DOM, but the version may be too high and vite does not fit, so I choose to reduce the react route DOM to V5 version:
npm i [email protected]
Restart the project and the error will be solved~
Similar Posts:
- Solve the problem of JS using JSX syntax to report errors in vite react project
- React Run Error: Uncaught TypeError: Cannot read property ‘forEach‘ of undefined
- [Solved] React Project Start Error: Uncaught TypeError: Cannot read property ‘forEach‘ of undefined
- TypeError: Cannot read property ‘location‘ of undefined [How to Solve]
- How to Solve React-native-gesture-handler Error
- Mac: How to Solve Print: Entry, “:CFBundleIdentifier”, Does Not Exist
- Using react native elements in RN project to report an error: unrecognized font family ‘material icons’
- [Solved] Use of create react app on Mac platform (command not found)