umi实现路由鉴权
什么是鉴权
鉴权(authentication)是指验证用户是否拥有访问系统的权利。传统的鉴权是通过密码来验证的。这种方式的前提是,每个获得密码的用户都已经被授权。
新建文件夹
import { Redirect } from 'umi'
export default (props) => {
const token = localStorage.getItem('login')//获取本地缓存的token
if (token) {
return <div>{ props.children }</div>;
} else {
return <Redirect to="/" />;
}
}
在.umirc.ts中配置
routes: [
{ path: '/', component: '@/pages/index' },
{ path: '/home', component: '@/pages/home/index' ,wrappers:['@/Authentication']},
],