/
Write
Start a team blog
NEW ✨
Start a team blog, invite your team, and start publishing.

‘Switch’ is not exported from ‘react-router-dom’

Tanya Kansal's photo
Tanya Kansal
·Jan 23, 2022·

1 min read

Hello guys, how are you all? Hope you all are fine. The other day I was learning react js and practicing some stuff. I faced the following error ‘Switch’ is not exported from ‘react-router-dom’ in reactjs. So, here I will explain you some possible solutions to get rid of this error.

Let's solve this error:

Screenshot (34).png

How To Solve ‘Switch’ is not exported from ‘react-router-dom’ Error ?

Solution-1: To solve 'Switch' is not exported from 'react-router-dom' error, just install Switch. Switch is replaced in react-router-dom version 6. So, you need to install react-router-dom version 5. Now, your error should be resolved.

Use the command below:

Screenshot (35).png

Solution-2: Use Routes instead of Switch.

Check the code below:

Screenshot (36).png

Then you can use it like this:

Screenshot (37).png

That's all about this issue. Hope your issue is resolved. Comment down which solution worked for you. Thankyou!