1.Link

  1. import { defineConfig } from 'umi';
  2. export default defineConfig({
  3. nodeModulesTransform: {
  4. type: 'none',
  5. },
  6. routes: [
  7. { path: '/', component:'@/layouts/index',routes:[
  8. {path:'/', component:'@/pages/index'},
  9. { path: '/user',
  10. wrappers:[
  11. '@/wrappers/auth'
  12. ],
  13. //这里配置公共部分
  14. routes:[
  15. {
  16. path:"/user",component:'@/pages/user',
  17. },
  18. {
  19. path:"/user/one",component:'@/pages/index1',
  20. },
  21. {
  22. path:"/user/two",component:'@/pages/index2',
  23. },
  24. ] },
  25. ] },
  26. ],
  27. fastRefresh: {},
  28. });

2.NavLink

  1. import React from 'react'
  2. import {Link,NavLink} from 'umi'
  3. import "./index.less"
  4. const Index = (props:any) => {
  5. return (
  6. <div>
  7. <h1>header</h1>
  8. <Link to="/user/one">链接一</Link>
  9. <Link to="/user/two">链接二</Link>
  10. {props.children}
  11. <hr/>
  12. <NavLink to="/user/one">链接三</NavLink>
  13. <NavLink to="/user/two">链接四</NavLink>
  14. <h2>Footer</h2>
  15. </div>
  16. )
  17. }
  18. export default Index
  1. .active{
  2. font-size: 24rpx;
  3. width: 100px;
  4. height: 50px;
  5. background-color: aquamarine;
  6. color: #fff;
  7. border-radius: 12px;
  8. line-height: 50px;
  9. text-align: center;
  10. margin: 15px;
  11. }

3.命令式跳转

需要引入history,从umi中

  1. import styles from './index.less';
  2. import {useEffect} from 'react'
  3. import { Calendar } from 'antd';
  4. import {history} from "umi"
  5. export default function IndexPage(props:any) {
  6. useEffect(()=>{
  7. setTimeout(() => {
  8. history.push("/login")
  9. }, 2000);
  10. })
  11. const onPanelChange=(value:any, mode:any)=>{
  12. console.log(value.format('YYYY-MM-DD'), mode);
  13. }
  14. {
  15. console.log(props.match.params);
  16. }
  17. return (
  18. <div>
  19. <div className={styles.scard} >
  20. <Calendar fullscreen={false} onPanelChange={onPanelChange} />
  21. </div>
  22. </div>
  23. );
  24. }