How to fix ‘Switch’ is not exported from ‘react-router-dom’ with React Router?

To fix ‘Switch’ is not exported from ‘react-router-dom’ with React Router, we should use version 5 of React Router.

First we uninstall the existing version of React Router with

npm uninstall react-router-dom

Then install the version 5.2.0 of react-router-dom

npm install [email protected]