mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
fix: 路由顶级非目录菜单直接显示
This commit is contained in:
parent
74dfc60ef0
commit
04fb4c0365
@ -65,30 +65,49 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord
|
|||||||
redirect: route.redirect,
|
redirect: route.redirect,
|
||||||
meta: meta
|
meta: meta
|
||||||
}
|
}
|
||||||
// 目录
|
//处理顶级非目录路由
|
||||||
if (route.children) {
|
if (!route.children && route.parentId == 0 && route.component) {
|
||||||
data.component = Layout
|
data.component = Layout
|
||||||
data.redirect = getRedirect(route.path, route.children)
|
data.meta = {}
|
||||||
// 外链
|
data.name = toCamelCase(route.path, true) + 'Parent'
|
||||||
} else if (isUrl(route.path)) {
|
data.redirect = ''
|
||||||
data = {
|
const childrenData: AppRouteRecordRaw = {
|
||||||
path: '/external-link',
|
path: '',
|
||||||
component: Layout,
|
name: toCamelCase(route.path, true),
|
||||||
meta: {
|
redirect: route.redirect,
|
||||||
name: route.name
|
meta: meta
|
||||||
},
|
}
|
||||||
children: [data]
|
|
||||||
} as AppRouteRecordRaw
|
|
||||||
// 菜单
|
|
||||||
} else {
|
|
||||||
// 对后端传component组件路径和不传做兼容(如果后端传component组件路径,那么path可以随便写,如果不传,component组件路径会根path保持一致)
|
|
||||||
const index = route?.component
|
const index = route?.component
|
||||||
? modulesRoutesKeys.findIndex((ev) => ev.includes(route.component))
|
? modulesRoutesKeys.findIndex((ev) => ev.includes(route.component))
|
||||||
: modulesRoutesKeys.findIndex((ev) => ev.includes(route.path))
|
: modulesRoutesKeys.findIndex((ev) => ev.includes(route.path))
|
||||||
data.component = modules[modulesRoutesKeys[index]]
|
childrenData.component = modules[modulesRoutesKeys[index]]
|
||||||
}
|
data.children = [childrenData]
|
||||||
if (route.children) {
|
} else {
|
||||||
data.children = generateRoute(route.children)
|
// 目录
|
||||||
|
if (route.children) {
|
||||||
|
data.component = Layout
|
||||||
|
data.redirect = getRedirect(route.path, route.children)
|
||||||
|
// 外链
|
||||||
|
} else if (isUrl(route.path)) {
|
||||||
|
data = {
|
||||||
|
path: '/external-link',
|
||||||
|
component: Layout,
|
||||||
|
meta: {
|
||||||
|
name: route.name
|
||||||
|
},
|
||||||
|
children: [data]
|
||||||
|
} as AppRouteRecordRaw
|
||||||
|
// 菜单
|
||||||
|
} else {
|
||||||
|
// 对后端传component组件路径和不传做兼容(如果后端传component组件路径,那么path可以随便写,如果不传,component组件路径会根path保持一致)
|
||||||
|
const index = route?.component
|
||||||
|
? modulesRoutesKeys.findIndex((ev) => ev.includes(route.component))
|
||||||
|
: modulesRoutesKeys.findIndex((ev) => ev.includes(route.path))
|
||||||
|
data.component = modules[modulesRoutesKeys[index]]
|
||||||
|
}
|
||||||
|
if (route.children) {
|
||||||
|
data.children = generateRoute(route.children)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
res.push(data)
|
res.push(data)
|
||||||
}
|
}
|
||||||
|
1
yudao-ui-admin-vue3/types/router.d.ts
vendored
1
yudao-ui-admin-vue3/types/router.d.ts
vendored
@ -74,5 +74,6 @@ declare global {
|
|||||||
children?: AppCustomRouteRecordRaw[]
|
children?: AppCustomRouteRecordRaw[]
|
||||||
keepAlive?: boolean
|
keepAlive?: boolean
|
||||||
visible?: boolean
|
visible?: boolean
|
||||||
|
parentId?: number
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user