Switch is not exported from react-router-dom

Hello friends, how are you all? Everything will be fine. You are new to React router and you are trying to do the React Router DOM. And if this type of error state as I have shown you below.

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

Sometimes this error would have come if the switch had not been imported. If so, then you can import the switch as shown in the code. This is a common problem, it can be easily solved.

import {
  BrowserRouter as Router,
} from "react-router-dom";

More info about React Router dom

Even after doing this, the problem is not getting solved and if you are facing the problem in the evening, then do not panic. I am also new to React router, I also came across this issue. I was worried even if I did Google, I didn’t get the solution.

This issue is caused by the version of react-router-dom. So you don’t have to do much, you install the new versions by uninstalling the old router dom, this will solve your problem. After uninstalling you don’t have to do much go to your react app folder and open the terminal by shift+right click. In the terminal, you run the code given below. This will uninstall you Router, Dom.

How to uninstall React Router Dom

npm uninstall react-router-dom


yarn remove react-router-dom

After uninstalling, you should install the latest versions of React. It’s currently 5.3.0. If you are seeing this post after a year, then you can see the latest versions on Google. To add new versions, you need to run the following command in the terminal.

CodeIgniter installation tutorial steps for beginners

How to install latest version of Router Dom

npm install react-router-dom@5.3.0


yarn add react-router-dom@5.3.0

Need Help from experts? Get free help. Click here

After installing the new react router dom, your problem will be solved. Now open your app again. According to my, doing this should solve your problem. If you are still facing a problem then comment to me. I will also help you out.

Leave a Comment