异常优化

This commit is contained in:
xielue 2023-09-13 08:39:31 +08:00
parent 424ce90c28
commit 6f50fc49c7
1 changed files with 4 additions and 1 deletions

View File

@ -37,6 +37,9 @@ function parseRoutes(routesConfig, routerMap) { // 解析路由
router = routerMap[item] // 从 routerMap 中获取路由
routeCfg = { path: (router && router.path) || item, router: item } // 路由配置获取路由的 path 和 router
} else if (typeof item === 'object') { // 如果路由配置是对象
if(!item.router){
return;
}
router = routerMap[item.router] // 从 routerMap 中获取路由
routeCfg = item // 路由配置为 item
}
@ -306,7 +309,7 @@ function deepMergeRoutes(target, source) {
function formatRoutes(routes) { // 格式化路由
routes.forEach(route => { // 遍历路由
const { path } = route // 获取路由的path
if (!path.startsWith('/') && path !== '*') { // 如果路由的path不是以/开头 并且 不是*
if (path && !path.startsWith('/') && path !== '*') { // 如果路由的path不是以/开头 并且 不是*
route.path = '/' + path // 将路由的path添加/
}
})