adrianhajdin / project_e_commerce

This is a code repository for the corresponding video tutorial. In this video, we're going to build a fully functional eCommerce application using commerce.js.
https://jsmastery.pro
1.88k stars 506 forks source link

Error! it gives error in App.js file. #43

Open kavitakadam297 opened 2 years ago

kavitakadam297 commented 2 years ago

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

JohnESwan3 commented 2 years ago

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

eramadani3 commented 2 years ago

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

thewilliamster commented 2 years ago

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