vue-antd-admin icon indicating copy to clipboard operation
vue-antd-admin copied to clipboard

多页签模式下,动态路由菜单设置cacheAble: false无效

Open Leeiio opened this issue 3 years ago • 2 comments

Describe the bug 开启多页签模式的时候,动态路由下设置cacheAble: false会无效

To Reproduce 拿演示代码里的路由设置举例:

{
          name: '动态路由菜单',
          path: 'router/dynamic/:id',
          meta: {
            icon: 'project',
            page: {
                cacheAble: false
            },
            params: {
              id: 123
            }
          },
          component: () => import('@/pages/Demo')
        }

Leeiio avatar Jun 04 '21 04:06 Leeiio

怎么解决啊!!!

lpubcat avatar Apr 07 '23 06:04 lpubcat

框架中设计缓存的组件,没有考虑动态路由,修改AKeepAlive.jshttps://github.com/iczer/vue-antd-admin/blob/master/src/components/cache/AKeepAlive.js

matches方法改造

function matches (pattern, name) {
  if (Array.isArray(pattern)) {
    if (pattern.indexOf(name) > -1) {
      return true
    } else {
      for (let item of pattern) {
        if (isRegExp(item) && item.test(name)) {
          return true
        }
        // 新增判断动态路由匹配机制 start
        let itemToString = item.toString();
        if(itemToString.includes('/:')){
          let pathStart = itemToString.substring(0,itemToString.indexOf('/:')-1).trim()
          if(name.includes(pathStart)){
            return true
          }
        }
        // 新增判断动态路由匹配机制 end
      }
      return false
    }
  } else if (typeof pattern === 'string') {
    return pattern.split(',').indexOf(name) > -1
  } else if (isRegExp(pattern)) {
    return pattern.test(name)
  }
  /* istanbul ignore next */
  return false
}

lpubcat avatar Apr 07 '23 07:04 lpubcat