vue使用redired对路由重定向:
router.beforeEach((to, from, next) => {
if (to.matched.some(m => m.meta.auth)) {
// 对路由进行验证
var token=sessionStorage.getItem("token");
if (token) { // 已经登陆
next() // 正常跳转到你设置好的页面
} else {
// 未登录则跳转到登陆界面,query:{ Rurl: to.fullPath}表示把当前路由信息传递过去方便登录后跳转回来;
next({
name: ‘login‘,
query: {
Rurl: to.fullPath
}
})
}
} else {
next()
}
})
原文:https://www.cnblogs.com/yeyuqian/p/13992542.html