https://blog.csdn.net/sinat_37255207/article/details/90745207
上次用react-router 的時候 還是3.x 很久不用 已經到react-router5.x 了
廢話不多說 上代碼
配置
react: ^16.8.6,
react-dom: ^16.8.6,
react-router: ^5.0.0,
react-router-dom: ^5.0.0,
import {HashRouter as Router,Route,Link,BrowserRouter ,Switch,Redirect} from 'react-router-dom';
....
<Router>
<Link to="/a" style={{color:'black'}}>
<div>點擊跳轉到a</div>
</Link>
<Link to="/b" style={{color:'black'}}>
<div>點擊跳轉到b</div>
</Link>
<Route exact path='/' component={App1}/>
<Route path='/a' component={App1}/>
<Route path='/b' component={App2}/>
</Router>
js 跳轉方法
import { createHashHistory,createBrowserHistory } from 'history'; // 是hash路由 history路由 自己根據需求來定 const history = createHashHistory(); ... history.push('/a'); ...