Skip to content

[Solved] export ‘Switch’ (imported as ‘Switch’) was not found in ‘react-router-dom’

In react-router-dom v6, Switch is replaced by routes Routes.

You need to update the import from:

import { Switch, Route } from "react-router-dom";
Code language: JavaScript (javascript)

to:

import { Routes, Route } from 'react-router-dom';
Code language: JavaScript (javascript)

You also need to update the Route declaration from:

<Route path="/" component={Home} />
Code language: HTML, XML (xml)

to:

<Route path='/welcome' element={<Home/>} />
Code language: HTML, XML (xml)

See also  How to Format Numbers by Prepending 0 to single-digit numbers in Javascript
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x