【发布时间】:2017-11-25 11:43:49
【问题描述】:
我试图保护子路由免受父路由的影响,但这失败了
export default new Router({
routes: [
//frontend routes
{
{path: 'auth', component: Auth, children: authroutes,
beforeEnter: (to, from, next) => {
// check if user is a guest or loggedin
auth.canAccess(permissions.is_guest)
.then((res) => {
if (res.data.status) {
next();
} else {
router.push('/auth/not-allowed');
}
})
}}
]
}
]
})
现在在我的孩子路线上
authroutes.js
const authroutes = [
{path: '', redirect: 'login'},
{path: 'login', component: Login, name: "login" },
];
但是当我将上面的 beforeenter 放在子路由上时,它可以工作,但会导致很多代码重复。
我怎样才能保护孩子远离父路线
例如:守卫 /auth/login 和 /auth/register
【问题讨论】:
标签: javascript vue.js vuejs2