Vue-element-admin: 设置动态路由后,没有权限的侧边栏仍然留有展示位置

Created on 9 Dec 2018  ·  4Comments  ·  Source: PanJiaChen/vue-element-admin

这里遇到一个问题,按照动态权限配置路由表后,原来没有权限的侧边栏导航,仍然保留了之前应该显示的位置。按照正常需求,这个位置是不希望被留空的,而是有权限的侧边栏直接展示在前面。
这种问题,该如何解决呢?求大神帮忙。

image

Most helpful comment

该问题我已经修复,修复内容如下:
修改src/store/modules/permission.js文件中的filterAsyncRouter 函数,修改方法如下:

function filterAsyncRouter(routes, roles) {
  const res = []
  routes.forEach(route => {
    const tmp = { ...route }
    if (hasPermission(roles, tmp)) {
      if (tmp.children) {
        tmp.children = filterAsyncRouter(tmp.children, roles)
        if (tmp.children.length === 0) {
          return false
        }
      }
      res.push(tmp)
    }
  })
  return res
}

All 4 comments

求大神帮忙回复,多谢多谢~

@PanJiaChen 期待回复

该问题我已经修复,修复内容如下:
修改src/store/modules/permission.js文件中的filterAsyncRouter 函数,修改方法如下:

function filterAsyncRouter(routes, roles) {
  const res = []
  routes.forEach(route => {
    const tmp = { ...route }
    if (hasPermission(roles, tmp)) {
      if (tmp.children) {
        tmp.children = filterAsyncRouter(tmp.children, roles)
        if (tmp.children.length === 0) {
          return false
        }
      }
      res.push(tmp)
    }
  })
  return res
}

@PanJiaChen 这个问题是不是最新版本还没有修复,因为我下载最新版的依旧有这个问题存在,期待大神告知

Was this page helpful?
0 / 5 - 0 ratings