1:需要登录页面的拦截
/*
* 在beforeEach中拦截
* https://router.vuejs.org/zh-cn/advanced/navigation-guards.html
*/
routes.beforeEach((to, from, next) => {
if(to.matched.some(record => record.meta.requiresAuth)){
if (noLogin) { // 没有登录则跳转/login页,进行登录
next({
path: '/login',
query: { redirect: to.fullPath }
})
} else {
next()
}
}else{
next()
}
})
2:登录成功后进入到command页面,返回不回到登录页
// 登录成功后的跳转使用router.replace,而不是router.push
this.$router.replace('/command')