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

Hello friends, how are you all? Everything will be fine. You are new to React 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,
  Switch,
  Route,
  Link
} 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, 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 react 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 your React Router Dom.

How to uninstall React Router Dom

npm uninstall react-router-dom

or

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 React Router Dom

npm install react-router-dom@5.3.0

or

yarn add react-router-dom@5.3.0

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 help you out.

Leave a Comment

Your email address will not be published.