Attempted import error: ‘Switch’ is not exported from ‘react-router-dom’

You may encounter the following error 'Switch' is not exported from 'react-router-dom' when working on routing using react-router-dom. So today we will show you how to fix the routing error in React.

Error

Attempted import error: ‘Switch’ is not exported from ‘react-router-dom’

When we try to import Switch from the react-router-dom v6 (Version 6) package, we’ll get the above error. Let’s have a look at what we can do about it.

Solution

The Switch has been replaced with Routes in react-router-dom v6.

From:

To:

Additionally, you must alter the Route declaration.

From:

To:

You don’t have to use the exact in the Route declaration in the react-router-dom.

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

1 Response

  1. prescriptions online says:

    Wow, this post is pleasant, my sister is analyzing these things, so I am going to let know her.

Leave a Reply

Your email address will not be published. Required fields are marked *