react-router-dom has no exported member 'Switch'
'"react-router-dom"' has no exported member 'Switch'
Got the above error while starting a new CRA app using react-router-dom.
import {
...
Switch,
...
} from "react-router-dom";
The docs had this bit of code at the top that was causing this error. The reason is that in v6, Switch
has been renamed to Routes
.
import {
...
Routes,
...
} from 'react-router-dom';
This very quickly fixes the error.
There's a migration doc here.