vscode拦截器

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

{
          path:'/myprofile',
          name:'myprofile',
          component:myprofile,
          //拦截器器
          beforeEnter: (to, from, next) => {
            //如果登录过,停留在此页面
            if(localStorage.getItem('username')){
              console.log('已登录')
              next()
            //如果没有登录过,强制跳到其他页面
            }else{
              console.log('没有登录')
              next('/login')
            }
          }
        }
原文地址:https://www.cnblogs.com/bronyaa/p/12810220.html