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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM