diff --git a/src/utils/route.ts b/src/utils/route.ts index 13e1145..bb376f1 100644 --- a/src/utils/route.ts +++ b/src/utils/route.ts @@ -58,12 +58,13 @@ export function filterAsyncRouter(routerMap) { } export function loadComponent(component: string) { + // 替换路径中的动态参数(例如 :id, :name) + component = component.replace(/\/(:\w+)/g, '') // 构建可能的路径 const fullPath = `/src/views/${component}.vue` const fullPathWithIndex = `/src/views/${component}/index.vue` // 先尝试直接路径,再尝试添加/index的路径 - const module = modules[fullPath] || modules[fullPathWithIndex] - return module || notFound + return modules[fullPath] || modules[fullPathWithIndex] || notFound } //路由扁平化