关于Umi 基础

官方文档:https://umijs.org/zh-CN/docs/getting-started

创建一个文件夹 之后在终端运行 npx @umijs/create-umi-app 或者 yarn create @umijs/umi-app

之后再安装一个node包 cnpm i 或者 yarn
输入命令 npm start 就可以运行

先删除ts文件 之后创建一个config文件夹 创建一个config.js 来替代ts文件
ts的东西复制到config.js里面 之后就是配置路由
config.js里面的路由是在routes 所以先把他提出来 之后直接引用就好
把默认的pages的index.js和index.less删掉就好了

在config.js中 写入
// 代理
proxy: {
‘/api’: {
target: ‘https://blogs.zdldove.top’,
changeOrigin: true,
pathRewrite: {
‘^/api’: ‘’
}
}
},

// 别名
alias: {
‘@@@’: path.resolve(__dirname, ‘…/src/components’),
},

关于二级路由以及layout的使用
先在src目录下面创建一个layout文件夹 里面写文件 文件
里主要写 {props.children}
之后在config.js中引入的routes.js路径中写
export default [
{ path: ‘/home’,
component: ‘@/Layouts/Blayout’,
routes:[
{ path: ‘/home/login’, component: ‘@/pages/login’, title: ‘登陆’},
{ path: ‘/home/home’, component: ‘@/pages/home’, title: ‘首页’},
]
},
]
/*
path:路径名
component:路径
title:显示的title
*/

wrappers: ['@/utils/athorized'],        //权限验证  这个在 routes.js 中写  例如:

export default [
{ path: ‘/home’,
component: ‘@/Layouts/Blayout’,
wrappers: [’@/utils/athorized’],//权限验证
routes:[
{ path: ‘/home/home’, component: ‘@/pages/home’, title: ‘首页’},
]
},
{ path: ‘/login’,
component: ‘@/pages/login’,
title: ‘登陆’
},
]

之后找到@/utils/athorized 文件

import { Redirect } from ‘umi’

export default props => {
if(!sessionStorage.getItem(‘red’)){
return
}
return <>{props.children}</>
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值