1
This commit is contained in:
@@ -27,9 +27,10 @@ export function filterAsyncRoutes(routes: any[], firstRoute = true) {
|
||||
|
||||
// 创建一条路由记录
|
||||
export function createRouteRecord(route: any, firstRoute: boolean): RouteRecordRaw {
|
||||
const normalizedPath = normalizeMenuPath(route.paths)
|
||||
//@ts-ignore
|
||||
const routeRecord: RouteRecordRaw = {
|
||||
path: isExternal(route.paths) ? route.paths : firstRoute ? `/${route.paths}` : route.paths,
|
||||
path: isExternal(route.paths) ? route.paths : firstRoute ? `/${normalizedPath}` : normalizedPath,
|
||||
name: Symbol(route.paths),
|
||||
meta: {
|
||||
hidden: !route.is_show,
|
||||
@@ -59,8 +60,9 @@ export function createRouteRecord(route: any, firstRoute: boolean): RouteRecordR
|
||||
// 动态加载组件
|
||||
export function loadRouteView(component: string) {
|
||||
try {
|
||||
const normalizedComponent = normalizeMenuPath(component)
|
||||
const key = Object.keys(modules).find((key) => {
|
||||
return key.includes(`/${component}.vue`)
|
||||
return key.includes(`/${normalizedComponent}.vue`)
|
||||
})
|
||||
if (key) {
|
||||
return modules[key]
|
||||
@@ -72,6 +74,12 @@ export function loadRouteView(component: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeMenuPath(path?: string) {
|
||||
return String(path || '')
|
||||
.replace(/^\/+/, '')
|
||||
.replace(/\/+$/, '')
|
||||
}
|
||||
|
||||
// 找到第一个有效的路由
|
||||
export function findFirstValidRoute(routes: RouteRecordRaw[]): string | undefined {
|
||||
for (const route of routes) {
|
||||
|
||||
Reference in New Issue
Block a user