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