import {Router, Route, Switch} from 'react-router-dom'; import { createHashHistory } from 'history';
const hashHistory = createHashHistory(); <Router history={hashHistory}> <Switch> <Route exact path="/" component={Login}/> <Route exact path="/login" component={Login}/> </Switch> </Router>
页面跳转:
<a href={"/#/red"}>toRed</a> <Link to="/red">toRed</Link> this.props.history.push("/red") 旧版参考:在React中使用react-router-dom路由 - 简书 (jianshu.com)
新版参考:React Please wrap your <Route> in a <Routes> - 1234前来报到 - 博客园 (cnblogs.com)