路由优化

This commit is contained in:
zhang zhuo 2025-12-24 17:31:36 +08:00
parent a0da7b943e
commit 0b6b01102e
1 changed files with 3 additions and 2 deletions

View File

@ -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
}
//路由扁平化