project_e_commerce icon indicating copy to clipboard operation
project_e_commerce copied to clipboard

Error! it gives error in App.js file.

Open kavitakadam297 opened this issue 3 years ago • 3 comments

switch is not exported or usehistory not imported from react-router-dom. please help me

kavitakadam297 avatar Nov 22 '21 18:11 kavitakadam297

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

JohnESwan3 avatar Nov 25 '21 17:11 JohnESwan3

I switched the version of "react-router-dom" but im still getting an error. Anyone know why?

eramadani3 avatar Dec 03 '21 00:12 eramadani3

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

thewilliamster avatar Dec 03 '21 17:12 thewilliamster