Today We are Going To Solve ‘Switch’ is not exported from ‘react-router-dom’ in reactjs. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.
Contents
How to Fix ‘Switch’ is not exported from ‘react-router-dom’ Error?
- How to Fix ‘Switch’ is not exported from ‘react-router-dom’ Error?
To Fix ‘Switch’ is not exported from ‘react-router-dom’ Error just Run these commands. To solve this error make just two changes :
Just replace “Switch” with “Routes”. Just replaceimport { Switch, Route } from "react-router-dom";
Toimport { Routes ,Route } from 'react-router-dom';
And also You have to update the Route declaration from<Route path="/" component={Home} />
to<Route path='/welcome' element={<Home/>} />
These changes will solve your error. Thank you! - ‘Switch’ is not exported from ‘react-router-dom’
To Fix ‘Switch’ is not exported from ‘react-router-dom’ Error just install version 5.2.0 of react-router-dom. You have to install version 5.2.0 of react-router-dom. First of all uninstall the version 6 of react-router-dom. For this use this command.
npm uninstall react-router-dom
And then install version 5.2.0 of react-router-dom by using this command:npm install [email protected]
This will solve your error.
Solution 1 : Run these commands
To solve this error make just two changes :
Just replace “Switch” with “Routes”. Just replace
import { Switch, Route } from "react-router-dom";
To
import { Routes ,Route } from 'react-router-dom';
And also You have to update the Route declaration from
<Route path="/" component={Home} />
to
<Route path='/welcome' element={<Home/>} />
These changes will solve your error. Thank you!
Solution 2 : install version 5.2.0 of react-router-dom
You have to install version 5.2.0 of react-router-dom. First of all uninstall the version 6 of react-router-dom. For this use this command.
npm uninstall react-router-dom
And then install version 5.2.0 of react-router-dom by using this command:
npm install [email protected]
This will solve your error.
Solution 3 : Run this command
Just run this command one by one. It will solve your error completely.
npm uninstall react-router-dom
npm install [email protected]
Conclusion
So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.
Also Read This Solutions
- How to use square root in python
- How to calculate euclidean distance in python
- How to sort a Set in Python
- How to extract substring from a string in python
- How to clear a List in Python