Vue Router el-menu 子菜单详情页父级菜单不高亮解决方案
如果 'el-menu' 的子菜单对应的路由为详情页,而父级菜单不高亮的话,可以尝试使用 'exact' 属性来匹配路由的精确路径。
例如:
<el-menu router>
<el-submenu index="/parent">
<template slot="title">父级菜单</template>
<el-menu-item index="/parent/child1">子菜单1</el-menu-item>
<el-menu-item index="/parent/child2">子菜单2</el-menu-item>
</el-submenu>
</el-menu>
在路由配置文件中,设置子菜单对应的路由为精确匹配:
{
path: '/parent',
component: ParentComponent,
children: [
{
path: 'child1',
component: Child1Component,
meta: {
title: '子菜单1',
exact: true // 精确匹配
}
},
{
path: 'child2',
component: Child2Component,
meta: {
title: '子菜单2',
exact: true // 精确匹配
}
}
]
}
这样就能够在子菜单路由匹配成功时,同时高亮父级菜单了。
原文地址: https://www.cveoy.top/t/topic/mIZL 著作权归作者所有。请勿转载和采集!