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

请问怎么生成不在侧边栏显示的router呢?比如详情页 #171

Closed
haihuilai123 opened this issue Aug 22, 2017 · 11 comments
Closed

Comments

@haihuilai123
Copy link

如题

@PanJiaChen
Copy link
Owner

PanJiaChen commented Aug 23, 2017

@lllsmiling
Copy link

那么跳转后怎么选中跳转之前的菜单?hidden菜单要设置成跳转之前选中菜单的子菜单?

@PanJiaChen
Copy link
Owner

@lllsmiling 不是很懂你想表达什么?

@lllsmiling
Copy link

lllsmiling commented Sep 28, 2017

就比如有个文章管理的菜单,进入一个页面以后,页面内有个添加按钮,点击添加按钮进入一个添加文章的页面,但是这时候菜单其实还是选中的文章管理的菜单。
如果一个内页很复杂,不适合用弹框来做的。

@PanJiaChen
Copy link
Owner

所以到底要干嘛。。。

@lllsmiling
Copy link

lllsmiling commented Sep 28, 2017

好吧,还是没描述清楚么……
1、有一个菜单我设置了hidden,然后左侧就不会显示了。
2、我想做到的是进入这个隐藏的菜单地址,但是还想在左侧菜单中选中一个可见的菜单(这个菜单是隐藏菜单逻辑上的父菜单)。

@PanJiaChen
Copy link
Owner

PanJiaChen commented Sep 28, 2017

暂时 element 官方并没有提供手动set高亮的接口,日后可能会有。
目前的解决方案有两种

  1. 现在 default-active 设置是根据 $route.path来的,这样设置是不能满足你的需求的,所以你可以在router里面自定义一个字段来实现你要的效果。

  2. 简单点,就是在进入你隐藏的页面的时候操作menu的dom给它加上一个active的class

@lllsmiling
Copy link

好的,多谢了……

@leochen-g
Copy link

目前这个问题有好的解决办法了吗?

@leochen-g
Copy link

defaultActive() { console.log('/' + this.$route.path.split('/')) return '/' + this.$route.path.split('/')[1] },
目前定义defaultActive为这样发现可以,只匹配父路由来决定是否高亮

@azhai
Copy link

azhai commented Jul 8, 2020

假设左侧的导航最多两层

  • 交易管理 (/trade)
    • 产品列表 (/trade/product)
      • 查看产品 hidden (/trade/product/detail/:id)
      • 编辑产品 hidden (/trade/product/edit/:id)
    • 订单列表 (/trade/order)
      • 查看订单 hidden (/trade/order/detail/:id)
      • 编辑订单 hidden (/trade/order/edit/:id)
  • 其他管理 (/other)

要让访问 查看产品/编辑产品 页面时,菜单高亮在 产品列表 上
可以修改这里 src/layout/components/Sidebar/index.vue 第34行开始
原来的代码是

    activeMenu() {
      const route = this.$route
      const { meta, path } = route
      // if set path, the sidebar will highlight the path you set
      if (meta.activeMenu) {
        return meta.activeMenu
      }
      return path
    }

改为

    activeMenu() {
      const route = this.$route
      const { meta, path } = route
      // if set path, the sidebar will highlight the path you set
      if (meta.activeMenu) {
        return meta.activeMenu
      }
      // get the first and second parts of path
      let n = path.indexOf('/', 1)
      if (n > 0) {
        n = path.indexOf('/', n+1)
      }
      return n > 0 ? path.substring(0, n) : path
    }

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

5 participants