1.Link
import { defineConfig } from 'umi';
export default defineConfig({
nodeModulesTransform: {
type: 'none',
},
routes: [
{ path: '/', component:'@/layouts/index',routes:[
{path:'/', component:'@/pages/index'},
{ path: '/user',
wrappers:[
'@/wrappers/auth'
],
//这里配置公共部分
routes:[
{
path:"/user",component:'@/pages/user',
},
{
path:"/user/one",component:'@/pages/index1',
},
{
path:"/user/two",component:'@/pages/index2',
},
] },
] },
],
fastRefresh: {},
});
2.NavLink
import React from 'react'
import {Link,NavLink} from 'umi'
import "./index.less"
const Index = (props:any) => {
return (
<div>
<h1>header</h1>
<Link to="/user/one">链接一</Link>
<Link to="/user/two">链接二</Link>
{props.children}
<hr/>
<NavLink to="/user/one">链接三</NavLink>
<NavLink to="/user/two">链接四</NavLink>
<h2>Footer</h2>
</div>
)
}
export default Index
.active{
font-size: 24rpx;
width: 100px;
height: 50px;
background-color: aquamarine;
color: #fff;
border-radius: 12px;
line-height: 50px;
text-align: center;
margin: 15px;
}
3.命令式跳转
需要引入history,从umi中
import styles from './index.less';
import {useEffect} from 'react'
import { Calendar } from 'antd';
import {history} from "umi"
export default function IndexPage(props:any) {
useEffect(()=>{
setTimeout(() => {
history.push("/login")
}, 2000);
})
const onPanelChange=(value:any, mode:any)=>{
console.log(value.format('YYYY-MM-DD'), mode);
}
{
console.log(props.match.params);
}
return (
<div>
<div className={styles.scard} >
<Calendar fullscreen={false} onPanelChange={onPanelChange} />
</div>
</div>
);
}