在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'); }