fylworker 2021-01-18 20:00 采纳率: 0%
浏览 213

前端路由多层级嵌套太深且重复的问题?

 后台管理系统开发中,页面显示效果如下:

路由层级关系如下:

对应完整的路由配置如下:

const routes = [{
  path: '/',
  component: 'LayoutBase',
  redirect: '/a',
  children: [{
    path: 'a',
    component: 'LayoutBlock',
    icon: 'home',
    title: 'a',
    meta: {
      hideChildren: true
    },
    children: [{
      path: '',
      component: 'a',
      title: 'a'
    }, {
      path: 'b',
      component: 'LayoutBlock',
      title: 'b',
      children: [{
        path: '',
        component: 'b',
        title: 'b'
      }, {
        path: 'c',
        component: 'c',
        title: 'c'
      }]
    }, {
      path: 'd',
      component: 'd',
      title: 'd'
    }]
  }, {
    path: 'e',
    component: 'LayoutBlock',
    icon: 'home',
    title: 'e',
    children: [{
      path: 'f',
      component: 'LayoutBlock',
      title: 'f',
      meta: {
        hideChildren: true
      },
      children: [{
        path: '',
        component: 'f',
        title: 'f'
      }, {
        path: 'b',
        component: 'LayoutBlock',
        title: 'b',
        children: [{
          path: '',
          component: 'b',
          title: 'b'
        }, {
          path: 'c',
          component: 'c',
          title: 'c'
        }]
      }]
    }, {
      path: 'g',
      component: 'LayoutBlock',
      title: 'g',
      meta: {
        hideChildren: true
      },
      children: [{
        path: '',
        component: 'g',
        title: 'g'
      }, {
        path: 'b',
        component: 'LayoutBlock',
        title: 'b',
        children: [{
          path: '',
          component: 'b',
          title: 'b'
        }, {
          path: 'c',
          component: 'c',
          title: 'c'
        }]
      }]
    }]
  }]
}]

可以看到,b 和 c 两个路由是父子关系且要在其他路由里面嵌套,但是在菜单中并不展示出来,访问「/a/b」,面包屑展示为「a / b」,访问「/a/b/c」,面包屑展示为「a / b / c」,点击面包屑上面的路由可以跳转回去。

以上嵌套方式,在业务复杂的场景中,就会存在路由嵌套很深的问题,在动态菜单配置的时候比较麻烦,而且还会添加重复的路由,是否还有其他的方案或者写法可以保证菜单展示、同时又能减少路由的复杂度、同时还能保证面包屑展示正常呢?

 

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-07 18:44
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况