From 841619c227aeb700ba3a34f0023ffca3a0125002 Mon Sep 17 00:00:00 2001 From: PeachScript Date: Tue, 2 Jun 2020 17:30:37 +0800 Subject: [PATCH] fix(theme): menu render error when configure 2-level navs (#193) --- .../preset-dumi/src/themes/default/Navbar.tsx | 2 +- .../preset-dumi/src/themes/default/SideMenu.tsx | 2 +- .../preset-dumi/src/themes/default/layout.tsx | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/preset-dumi/src/themes/default/Navbar.tsx b/packages/preset-dumi/src/themes/default/Navbar.tsx index 5e5cd30125..49d1d0ef95 100644 --- a/packages/preset-dumi/src/themes/default/Navbar.tsx +++ b/packages/preset-dumi/src/themes/default/Navbar.tsx @@ -73,7 +73,7 @@ const Navbar: FC = ({ onMobileMenuClick, navPrefix }) => { ); return ( - + {nav.title} {child} diff --git a/packages/preset-dumi/src/themes/default/SideMenu.tsx b/packages/preset-dumi/src/themes/default/SideMenu.tsx index 978c6fa27c..c0cc3e691a 100644 --- a/packages/preset-dumi/src/themes/default/SideMenu.tsx +++ b/packages/preset-dumi/src/themes/default/SideMenu.tsx @@ -55,7 +55,7 @@ const SideMenu: FC = ({ mobileMenuCollapsed, location }) => {
    {navs.map(nav => ( -
  • +
  • {nav.title} {Boolean(nav.children?.length) && ( diff --git a/packages/preset-dumi/src/themes/default/layout.tsx b/packages/preset-dumi/src/themes/default/layout.tsx index 846b914a4d..5a90c1d8ff 100644 --- a/packages/preset-dumi/src/themes/default/layout.tsx +++ b/packages/preset-dumi/src/themes/default/layout.tsx @@ -122,12 +122,15 @@ export default class Layout extends Component { if (navs[state.currentLocale]) { for (let i = navs[state.currentLocale].length - 1; i >= 0; i -= 1) { const nav = navs[state.currentLocale][i]; - - if ( - nav.path && - new RegExp(`^${nav.path.replace(/\.html$/, '')}(/|\.|$)`).test(location.pathname) - ) { - navPath = nav.path; + const items = [nav].concat(nav.children).filter(Boolean); + const matched = items.find( + item => + item.path && + new RegExp(`^${item.path.replace(/\.html$/, '')}(/|\.|$)`).test(location.pathname), + ); + + if (matched) { + navPath = matched.path; break; } }