From 0b6b01102e7ddeb2468931974dab16962b04e3b3 Mon Sep 17 00:00:00 2001 From: zhang zhuo Date: Wed, 24 Dec 2025 17:31:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/route.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 } //路由扁平化