Skip to content

Commit

Permalink
fix(preset): order not working when set 0
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Apr 15, 2020
1 parent b189b1a commit 4b32513
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/preset-dumi/src/routes/getMenuFromRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,28 @@ export default function getMenuFromRoutes(
meta: {},
};

if (route.meta?.order) {
if (typeof route.meta?.order === 'number') {
menuItem.meta.order = route.meta.order;
}

if (group?.path) {
const { title, path, ...meta } = group;
const groupKey = group.path || group.title;

// group route items by group path & locale
localeMenusMapping[locale] = {
...(localeMenusMapping[locale] || {}),
[nav]: {
...(localeMenusMapping[locale]?.[nav] || {}),
[group.path || group.title]: {
[groupKey]: {
title,
path,
meta: {
// merge group meta
...(localeMenusMapping[locale]?.[nav]?.[group.path]?.meta || {}),
...(localeMenusMapping[locale]?.[nav]?.[groupKey]?.meta || {}),
...meta,
},
children: (localeMenusMapping[locale]?.[nav]?.[group.path]?.children || []).concat(
children: (localeMenusMapping[locale]?.[nav]?.[groupKey]?.children || []).concat(
menuItem,
),
},
Expand All @@ -186,7 +187,7 @@ export default function getMenuFromRoutes(
const menus = Object.values(localeMenusMapping[locale][nav]).map((menu: IMenuItem) => {
// discard children if current menu only has 1 children
if (menu.children?.length === 1 && menu.title === menu.children[0].title) {
if (menu.children[0].meta?.order) {
if (typeof menu.children[0].meta?.order === 'number') {
menu.meta.order = menu.children[0].meta.order;
}
menu.children = [];
Expand Down

0 comments on commit 4b32513

Please sign in to comment.