Error! it gives error in App.js file.
kavitakadam297 opened this issue · comments
switch is not exported or usehistory not imported from react-router-dom.
please help me
The way that I got around this is to got to your package.json and change your "react-router-dom" version to "^5.2.3". React changed the way that the Router work and got rid of Switch. Unfortunately it isn't as simple as just renaming Switch to the new Routes
I switched the version of "react-router-dom" but im still getting an error. Anyone know why?
Either upgrade and use the new package, it's components, it's new hooks and change your code.
OR
Find out which version is the one you want to use and make sure to only download that version of react-router-dom, removing the other version before installing the one you want
So basically, react-router-dom updated and changed a lot of the way you work with the package. You have two options, upgrade and use the new package and make the changes to your code, or use the older version. Obviously I have no idea which version you're using so I can't help but if you down to upgrade here's some resources:
Here's what your component tree should look like, replacing Switch with Routes and making all the changes:
https://reactrouter.com/docs/en/v6/getting-started/overview#configuring-routes
Using useHistory and .push? Try this, it uses Link and useNavigate
https://reactrouter.com/docs/en/v6/getting-started/overview#navigation
Getting the params from the route? Try this, it uses "useParams" hook:
https://reactrouter.com/docs/en/v6/getting-started/overview#reading-url-parameters