路由中设置
export default {
routes: [
{ path: '/user', component: 'user',
wrappers: [
'@/wrappers/auth',
],
},
{ path: '/login', component: 'login' },
]
}
然后
然后在 src/wrappers/auth 中,
import { Redirect } from 'umi';
import { LocalStorage } from '@/utils/storage';
export default (props) => {
const isLogin = LocalStorage.get('token');
console.log(props.location);
if (isLogin) {
return {props.children};
} else {
return (
{ pathname: '/login', state: { from: props.location } }} />
);
}
};
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)