I am npm install react-router-dom@6.0.0-alpha.2 but don't work this Routes is not working help....
import './App.css';
import { Route, Routes } from 'react-router-dom';
import login from './pages/login';
function App() {
return (
<Routes>
<Route exact path="/">
dashboard
</Route>
<Route exact path="/login" component={login}/>
<Route path="*" render={() => "404 Not found!"}/>
</Routes>
);
}
export default App;
In react router v6 you must use element prop, I guess you are wrapping app in index.js
with <BrowserRouter>
and login
should be in capital letter if it is a component, like this Login
and exact is not supported in react router v6
import './App.css';
import { Routes, Route } from 'react-router-dom';
import login from './pages/login';
function App() {
return (
<Routes>
<Route path="/" element={<h1>Dashboard</h1>}/>
<Route path="/login" element={<login/>}/>
<Route path="*" element={<h1>404 Not found!</h1>}/>
</Routes>
);
}
export default App;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.