Skip to content

Commit 1315f99

Browse files
EmiyaYangsendya
authored andcommitted
fix(menu): fail to match route item with relative path #662
1 parent 00efa5e commit 1315f99

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"enquire.js": "^2.1.6",
2020
"lodash.get": "^4.4.2",
2121
"lodash.pick": "^4.4.0",
22+
"lodash.clonedeep": "^4.5.0",
2223
"md5": "^2.2.1",
2324
"mockjs2": "1.0.8",
2425
"moment": "^2.24.0",

β€Žsrc/config/router.config.jsβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ export const asyncRouterMap = [
1313
children: [
1414
// dashboard
1515
{
16-
path: '/dashboard',
16+
path: 'dashboard',
1717
name: 'dashboard',
1818
redirect: '/dashboard/workplace',
1919
component: RouteView,
2020
meta: { title: 'δ»ͺθ‘¨η›˜', keepAlive: true, icon: bxAnaalyse, permission: [ 'dashboard' ] },
2121
children: [
2222
{
23-
path: '/dashboard/analysis',
23+
path: 'analysis',
2424
name: 'Analysis',
2525
component: () => import('@/views/dashboard/Analysis'),
2626
meta: { title: 'εˆ†ζžι‘΅', keepAlive: false, permission: [ 'dashboard' ] }
@@ -32,13 +32,13 @@ export const asyncRouterMap = [
3232
meta: { title: 'η›‘ζŽ§ι‘΅οΌˆε€–ιƒ¨οΌ‰', target: '_blank' }
3333
},
3434
{
35-
path: '/dashboard/workplace',
35+
path: 'workplace',
3636
name: 'Workplace',
3737
component: () => import('@/views/dashboard/Workplace'),
3838
meta: { title: 'ε·₯作台', keepAlive: true, permission: [ 'dashboard' ] }
3939
},
4040
{
41-
path: '/dashboard/test-work',
41+
path: 'test-work',
4242
name: 'TestWork',
4343
component: () => import('@/views/dashboard/TestWork'),
4444
meta: { title: 'ζ΅‹θ―•εŠŸθƒ½', keepAlive: true, permission: [ 'dashboard' ] }

β€Žsrc/layouts/BasicLayout.vueβ€Ž

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ import SideMenu from '@/components/Menu/SideMenu'
7070
import GlobalHeader from '@/components/GlobalHeader'
7171
import GlobalFooter from '@/components/GlobalFooter'
7272
import SettingDrawer from '@/components/SettingDrawer'
73+
import cloneDeep from 'lodash.clonedeep'
74+
75+
function convertRoutes (nodes) {
76+
if (!nodes) return null
77+
78+
nodes = cloneDeep(nodes)
79+
80+
let queue = Array.isArray(nodes) ? nodes.concat() : [nodes]
81+
82+
while (queue.length) {
83+
const levelSize = queue.length
84+
85+
for (let i = 0; i < levelSize; i++) {
86+
const node = queue.shift()
87+
88+
if (!node.children || !node.children.length) continue
89+
90+
node.children.forEach(child => {
91+
// θ½¬εŒ–η›Έε―Ήθ·―εΎ„
92+
if (child.path[0] !== '/') {
93+
child.path = node.path.replace(/(\w*)[/]*$/, `$1/${child.path}`)
94+
}
95+
})
96+
97+
queue = queue.concat(node.children)
98+
}
99+
}
100+
101+
return nodes
102+
}
73103
74104
export default {
75105
name: 'BasicLayout',
@@ -109,7 +139,8 @@ export default {
109139
}
110140
},
111141
created () {
112-
this.menus = this.mainMenu.find(item => item.path === '/').children
142+
const routes = convertRoutes(this.mainMenu.find(item => item.path === '/'))
143+
this.menus = (routes && routes.children) || []
113144
this.collapsed = !this.sidebarOpened
114145
},
115146
mounted () {

β€Žyarn.lockβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7037,6 +7037,11 @@ locate-path@^5.0.0:
70377037
dependencies:
70387038
p-locate "^4.1.0"
70397039

7040+
lodash.clonedeep@^4.5.0:
7041+
version "4.5.0"
7042+
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
7043+
integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=
7044+
70407045
lodash.defaultsdeep@^4.6.1:
70417046
version "4.6.1"
70427047
resolved "https://registry.npm.taobao.org/lodash.defaultsdeep/download/lodash.defaultsdeep-4.6.1.tgz#512e9bd721d272d94e3d3a63653fa17516741ca6"

0 commit comments

Comments
Β (0)