如下:
router.beforeEach((to, from, next) => {
if (to.path == '/Login'||to.path == '/home'||to.path =='/Register'||to.name=='mine'||to.name == 'yuYue'||to.name == 'video') {
next();
} else {
let token = localStorage.getItem('Authorization');
// console.log(token)
if (!token) {
console.log(9999)
next('/Login');
} else {
next();
}
}
});
path:用到第三个会出现无法识别的问题,无奈之下使用 name 属性,但是在路由匹配的时候要是有这个name字段的:
例如:
{
path: '/MyCollect',
name: 'myCollect',
component: resolve => require.ensure([], () => resolve(require('@/views/MyCollect/myCollect.vue')))
}
网友评论