路由优化
This commit is contained in:
parent
a0da7b943e
commit
0b6b01102e
|
|
@ -58,12 +58,13 @@ export function filterAsyncRouter(routerMap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadComponent(component: string) {
|
export function loadComponent(component: string) {
|
||||||
|
// 替换路径中的动态参数(例如 :id, :name)
|
||||||
|
component = component.replace(/\/(:\w+)/g, '')
|
||||||
// 构建可能的路径
|
// 构建可能的路径
|
||||||
const fullPath = `/src/views/${component}.vue`
|
const fullPath = `/src/views/${component}.vue`
|
||||||
const fullPathWithIndex = `/src/views/${component}/index.vue`
|
const fullPathWithIndex = `/src/views/${component}/index.vue`
|
||||||
// 先尝试直接路径,再尝试添加/index的路径
|
// 先尝试直接路径,再尝试添加/index的路径
|
||||||
const module = modules[fullPath] || modules[fullPathWithIndex]
|
return modules[fullPath] || modules[fullPathWithIndex] || notFound
|
||||||
return module || notFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//路由扁平化
|
//路由扁平化
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue