This commit is contained in:
2026-04-21 15:56:04 +08:00
parent b03c079099
commit e2aaee324e
7 changed files with 1747 additions and 2 deletions
+10 -2
View File
@@ -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) {