umi 路由
在.umirc.ts的routes進(jìn)行路由配置1、配置路由routes:[{path:'/路徑',components:'路徑,@為src,不需要引入組件',exact:true}]配置:redirect:'/重定向路由路徑'title:'路由頁面名稱'wrappers:['/路由校驗的組件路徑']其中該組件:export default (props) => {校驗操作return {props.children} 如果驗證成功返回所在的路由組件}2、路由跳轉(zhuǎn)(1)聲明式導(dǎo)航import { Link,NavLink } from 'umi';<Link to="/路徑">xx</Link>exact、strict和高亮等配置和react相同(2)編程式導(dǎo)航(都可以使用this.props.xx的寫法)import { history } from 'umi'; 或者this.props.history.push和react相同寫法history.push('/x');history.push('/xx?鍵=值');history.push({pathname: '/xx',query: {參數(shù)鍵值對},});history.goBack();history.replace('/路徑');參數(shù)獲取:history.location.query.鍵名獲取this.props.location.query3、路由重定向import { Redirect } from 'umi'<Redirect to="/路徑" />4、嵌套路由routes: [{path: '/',component: '@/layouts/index',routes: [{ path: '/user', redirect: '/user/login' },{ path: '/user/login', component: './user/login' },],},],父路由上:{this.props.children}顯示子路由5、配置hash路由history: { type: 'hash' },和nodeModulesTransform同級
總結(jié)
- 上一篇: 【嵌入式设计开发】基于STM32 HD0
- 下一篇: 学习淘淘商城第一课