VUE实现登录然后跳转到原来的页面

可以在路由里面设置需要登录的界面,判断下没有登录就跳转到登录界面,登录了就不用登录,这里用的是一个存储的

router.beforeEach((to, from, next) => {
if(to.matched.some( m => m.meta.auth)){
if(sessionStorage.getItem('isLogin')){
next()
}else{
next({path:'/login',query:{url: to.fullPath} })
}
}else{
next();
}
})

这里是判断是否登录

this.$router.push(this.$router.currentRoute.query.url)这里的代码可以直接跳转到需要登录的界面

原文地址:https://www.cnblogs.com/liubu/p/9212232.html