Skip to content

Commit

Permalink
fix(theme): menu render error when configure 2-level navs (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Jun 2, 2020
1 parent e0b525e commit 841619c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/preset-dumi/src/themes/default/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const Navbar: FC<INavbarProps> = ({ onMobileMenuClick, navPrefix }) => {
);

return (
<NavbarLink href={nav.path} key={nav.path}>
<NavbarLink href={nav.path} key={nav.path || nav.title}>
{nav.title}
{child}
</NavbarLink>
Expand Down
2 changes: 1 addition & 1 deletion packages/preset-dumi/src/themes/default/SideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const SideMenu: FC<INavbarProps> = ({ mobileMenuCollapsed, location }) => {
<div className="__dumi-default-menu-mobile-area">
<ul className="__dumi-default-menu-nav-list">
{navs.map(nav => (
<li key={nav.path}>
<li key={nav.path || nav.title}>
<NavbarLink href={nav.path}>
{nav.title}
{Boolean(nav.children?.length) && (
Expand Down
15 changes: 9 additions & 6 deletions packages/preset-dumi/src/themes/default/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,15 @@ export default class Layout extends Component<ILayoutProps & RouteProps> {
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;
}
}
Expand Down

0 comments on commit 841619c

Please sign in to comment.