vscode拦截器

再写登录页面的时候,即使不登录,也能根据连接跳转,为了阻止这个情况,所以使用了拦截器

{
          path:'/myprofile',
          name:'myprofile',
          component:myprofile,
          //拦截器器
          beforeEnter: (to, from, next) => {
            //如果登录过,停留在此页面
            if(localStorage.getItem('username')){
              console.log('已登录')
              next()
            //如果没有登录过,强制跳到其他页面
            }else{
              console.log('没有登录')
              next('/login')
            }
          }
        }
posted @ 2020-04-30 17:44  Bronya天使  阅读(244)  评论(0编辑  收藏  举报