vue 路由权限配置

router----->index.js

{
          path:'record',
          name:'record',
          component:record,
          meta:{
            requireAuth:true
          }
        }
// 配置路由权限
router.beforeEach((to, from, next) => {
  let token=localStorage.getItem('token')
  if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
    if (token) { // 判断本地是否存在access_token
      NProgress.start()//页面加载进度条开始
      next()
      
    } else {
      // 未登录,跳转到登陆页面,并且带上 将要去的地址,方便登陆后跳转。
      next('/login')
    }
  } else {
    next()
  }
})
router.afterEach(() => {
    NProgress.done()//页面加载进度条结束
})
发布了29 篇原创文章 · 获赞 22 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_41628411/article/details/96144307
今日推荐