
正文
Vue-router路由判断页面是否登录,未登录跳转到登录页面
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
在index.js中
//定义路由
const router = new Router({
routes,
strict: process.env.NODE_ENV !== 'production',
})
//拦截器
router.beforeEach((route, redirect, next) => {if (!sessionStorage.getItem("userid") && route.path !== '/') {
next({
path: '/',
query: {redirect: route.fullPath}
})
} else {
console.log("-------------------",route,redirect);
next()
}
})
export default router
在login.vue中登录成功中加入
if(this.$route.query.redirect){
let redirect = this.$route.query.redirect;
this.$router.push(redirect);
}else{
//默认登录成功后进入的页面
this.$router.push('manage');
}






