xxxxxxxxxx
Use rect-router-version @5.2.0 TO access or use Switch
npm install react-router-dom@5.2.0
#N.B: Updated version dosen't support "Switch".
xxxxxxxxxx
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";
to
import { Routes ,Route } from 'react-router-dom';
You also need to update the Route declaration from
<Route path="/" component={Home} />
to
<Route path='/welcome' element={<Home/>} />
In react-router-dom, you also do not need to use the exact in the Route declaration.
For more information, you can visit the official documentation:
https://reactrouter.com/docs/en/v6/upgrading/v5
xxxxxxxxxx
//TEMPLATE TO USE
import React from "react";
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
//------------------------------------------------IMPORTS VIEWS-----------------------------------------------
import Home from "./views/Home.js";
//------------------------------------------------CLASS APP-----------------------------------------------
class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<Router>
<Routes>
<Route exact path="/" element={<Home/>} />
</Routes>
</Router>
);
}
}
export default App;
xxxxxxxxxx
import { Switch, Route } from "react-router-dom";
xxxxxxxxxx
import { Switch, Route } from "react-router-dom";
xxxxxxxxxx
<Route path="/" component={Home} />
xxxxxxxxxx
<Route path='/' element={<Home/>} />
xxxxxxxxxx
<Route path="/" component={Home} />
xxxxxxxxxx
<Route path="/" component={Home} />