系统--登陆权限校验

// permission.js 在main.js的引入 就会被执行

const whiteList =['/login']

router.beforeEach(to ,from, next) => {
  if(checkPermission()){
      if(to.path === '/'&& router.options.routes.length>2){
      // 一般有两个默认菜单 /login和* 多余两个说明此用户有可看的菜单权限,默认选中要第一个

        const route = router.options.routes[0]
        next({
             path: route.redirect||route.path
        })  
        return
      }   
  } else {
       // 如果没有这句判断会进入login循环
      if (whiteList.indexOf(to.path) !== -1){
         next()
      } else {
      next({path:'/login'})
      }
  }
}

  

猜你喜欢

转载自www.cnblogs.com/cs122/p/12692645.html