• 路由模式(hash、h5 history),同 vue-router
    • 路由配置(动态路由、懒加载),同 vue-router
    1. <Router>
    2. <Switch>
    3. <Router exact path="/">
    4. <Home />
    5. </Router>
    6. <Router path="/project/:id">
    7. <Project />
    8. </Router>
    9. <Router exact path="*">
    10. <NotFound />
    11. </Router>
    12. </Switch>
    13. </Router>
    1. import { Link, useParams, useHistory } from 'react-router-dom';
    2. function Project() {
    3. const { id } = useParams();
    4. // 获取参数 例如 /project/100
    5. <Link to="/">首页</Link>
    6. }
    7. let his = useHistory();
    8. his.push('/');