Skip to content

Commit 79e2a60

Browse files
authored
feature[Sidebar]: add activeMenu option (PanJiaChen#1833)
1 parent 083a4ad commit 79e2a60

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

src/layout/components/Sidebar/index.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<logo v-if="showLogo" :collapse="isCollapse" />
44
<el-scrollbar wrap-class="scrollbar-wrapper">
55
<el-menu
6-
:default-active="$route.path"
6+
:default-active="activeMenu"
77
:collapse="isCollapse"
88
:background-color="variables.menuBg"
99
:text-color="variables.menuText"
@@ -30,6 +30,15 @@ export default {
3030
'permission_routes',
3131
'sidebar'
3232
]),
33+
activeMenu() {
34+
const route = this.$route
35+
const { meta, path } = route
36+
// if set path, the sidebar will highlight the path you set
37+
if (meta.activeMenu) {
38+
return meta.activeMenu
39+
}
40+
return path
41+
},
3342
showLogo() {
3443
return this.$store.state.settings.sidebarLogo
3544
},

src/router/index.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@ import chartsRouter from './modules/charts'
1212
import tableRouter from './modules/table'
1313
import nestedRouter from './modules/nested'
1414

15-
/** note: sub-menu only appear when children.length>=1
16-
* detail see https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
17-
**/
18-
1915
/**
20-
* hidden: true if `hidden:true` will not show in the sidebar(default is false)
21-
* alwaysShow: true if set true, will always show the root menu, whatever its child routes length
22-
* if not set alwaysShow, only more than one route under the children
23-
* it will becomes nested mode, otherwise not show the root menu
24-
* redirect: noredirect if `redirect:noredirect` will no redirect in the breadcrumb
25-
* name:'router-name' the name is used by <keep-alive> (must set!!!)
26-
* meta : {
27-
roles: ['admin','editor'] will control the page roles (you can set multiple roles)
28-
title: 'title' the name show in sub-menu and breadcrumb (recommend set)
16+
* Note: sub-menu only appear when route children.length >= 1
17+
* Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
18+
*
19+
* hidden: true if set true, item will not show in the sidebar(default is false)
20+
* alwaysShow: true if set true, will always show the root menu
21+
* if not set alwaysShow, when item has more than one children route,
22+
* it will becomes nested mode, otherwise not show the root menu
23+
* redirect: noredirect if `redirect:noredirect` will no redirect in the breadcrumb
24+
* name:'router-name' the name is used by <keep-alive> (must set!!!)
25+
* meta : {
26+
roles: ['admin','editor'] control the page roles (you can set multiple roles)
27+
title: 'title' the name show in sidebar and breadcrumb (recommend set)
2928
icon: 'svg-name' the icon show in the sidebar
30-
noCache: true if true, the page will no be cached(default is false)
31-
breadcrumb: false if false, the item will hidden in breadcrumb(default is true)
32-
affix: true if true, the tag will affix in the tags-view
29+
noCache: true if set true, the page will no be cached(default is false)
30+
affix: true if set true, the tag will affix in the tags-view
31+
breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
32+
activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
3333
}
34-
**/
34+
*/
3535

3636
/**
3737
* constantRoutes
3838
* a base page that does not have permission requirements
3939
* all roles can be accessed
40-
* */
40+
*/
4141
export const constantRoutes = [
4242
{
4343
path: '/redirect',
@@ -113,7 +113,7 @@ export const constantRoutes = [
113113
/**
114114
* asyncRoutes
115115
* the routes that need to be dynamically loaded based on user roles
116-
*/
116+
*/
117117
export const asyncRoutes = [
118118
{
119119
path: '/permission',
@@ -195,7 +195,7 @@ export const asyncRoutes = [
195195
path: 'edit/:id(\\d+)',
196196
component: () => import('@/views/example/edit'),
197197
name: 'EditArticle',
198-
meta: { title: 'editArticle', noCache: true },
198+
meta: { title: 'editArticle', noCache: true, activeMenu: '/example/list' },
199199
hidden: true
200200
},
201201
{

0 commit comments

Comments
 (0)