Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tags view 三级路由问题 #3701

Open
chengazhen opened this issue May 17, 2021 · 0 comments
Open

tags view 三级路由问题 #3701

chengazhen opened this issue May 17, 2021 · 0 comments

Comments

@chengazhen
Copy link

Bug report(问题描述)

头部需要固定显示tags view ,路由层级为三级路由,标签可以显示,但是点过去就是404,路由的路径没有正确生成

Steps to reproduce(问题所在地方)

//路由的路径没有正确生成,作者说了 不太主张使用tagsview 可能是大意了

    filterAffixTags(routes, basePath = '/') {
      let tags = []
      routes.forEach(route => {
        if (route.meta && route.meta.affix) {
          const tagPath = path.resolve(basePath, route.path)
          tags.push({
            fullPath: tagPath,
            path: tagPath,
            name: route.name,
            meta: { ...route.meta }
          })
        }
        if (route.children) {
          const tempTags = this.filterAffixTags(route.children, route.path)// 此处都只会把当前级的路由传到下级,父级路由会造成丢失
          if (tempTags.length >= 1) {
            tags = [...tags, ...tempTags]
          }
        }
      })
      return tags
    },

问题解决办法

 filterAffixTags(routes, basePath = '/') {
      let tags = []
      routes.forEach((route) => {
        if (route.meta && route.meta.affix) {
          const tagPath = path.resolve(basePath, route.path)
          tags.push({
            fullPath: tagPath,
            path: tagPath,
            name: route.name,
            meta: { ...route.meta }
          })
        }
        if (route.children) {
          const tempTags = this.filterAffixTags(
            route.children,
            path.resolve(basePath, route.path)  //在此处把父级页面路径保存 作者的 原方法是route.path ,路由层级超过二级 就会丢失父级路由
          )
          if (tempTags.length >= 1) {
            tags = [...tags, ...tempTags]
          }
        }
      })
      return tags
    },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant