Skip to content

Commit 697431a

Browse files
committed
fix: Uncaught TypeError
1 parent 431dde9 commit 697431a

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/routers/utils/index.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { routePermissionMap } from '@src/mock/permission'
1313
export const createRoute = (config) => {
1414
const { path, element, index = false, children, name, i18nKey, key, auth = false, meta = {}, ...rest } = config
1515

16+
const safeMeta = meta && typeof meta === 'object' ? meta : {}
17+
1618
const route = {
1719
path,
1820
element,
@@ -28,13 +30,13 @@ export const createRoute = (config) => {
2830
}
2931

3032
// 添加路由元数据(用于菜单、权限控制等)
31-
if (name || i18nKey || key !== undefined || auth || Object.keys(meta).length > 0) {
33+
if (name || i18nKey || key !== undefined || auth || Object.keys(safeMeta).length > 0) {
3234
route.meta = {
3335
name,
3436
i18nKey,
3537
key: key || path,
3638
auth,
37-
...meta,
39+
...safeMeta,
3840
}
3941
}
4042

@@ -65,7 +67,7 @@ export const flattenRoutes = (routes) => {
6567

6668
if (route.meta) {
6769
result.push({
68-
...route.meta,
70+
...(route.meta && typeof route.meta === 'object' ? route.meta : {}),
6971
path: fullPath,
7072
element: route.element,
7173
})

0 commit comments

Comments
 (0)