From 31eb2bef2692e1eacedb1ae5a5955d8050bcdbac Mon Sep 17 00:00:00 2001 From: arvinxx Date: Wed, 22 Feb 2023 19:02:56 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20fix:=20=E4=BF=AE=E6=AD=A3=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E7=99=BD=E5=B1=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/slots/Sidebar/index.tsx | 32 +++++++++++++++----------------- src/store/selectors.ts | 5 +++-- src/store/useSiteStore.ts | 2 +- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/slots/Sidebar/index.tsx b/src/slots/Sidebar/index.tsx index deedcdc..6a9bc12 100644 --- a/src/slots/Sidebar/index.tsx +++ b/src/slots/Sidebar/index.tsx @@ -9,23 +9,21 @@ const Sidebar: FC = () => { const sidebar = useSiteStore((s) => s.sidebar, isEqual); const { styles } = useStyles(); - return ( - sidebar && ( -
- {sidebar.map((item, i) => ( -
- {item.title &&
{item.title}
} - {item.children.map((child) => ( -
- - {child.title} - -
- ))} -
- ))} -
- ) + return !sidebar ? null : ( +
+ {sidebar.map((item, i) => ( +
+ {item.title &&
{item.title}
} + {item.children.map((child) => ( +
+ + {child.title} + +
+ ))} +
+ ))} +
); }; diff --git a/src/store/selectors.ts b/src/store/selectors.ts index 48291b6..e51314c 100644 --- a/src/store/selectors.ts +++ b/src/store/selectors.ts @@ -1,3 +1,4 @@ +import { ISidebarItem } from 'dumi/dist/client/theme-api/types'; import { AnchorItem, ApiHeaderConfig, IFeature } from '../types'; import { SiteStore } from './useSiteStore'; @@ -139,8 +140,8 @@ export const tocAnchorItemSel = (s: SiteStore) => * 将 sidebar 信息扁平化 * @param s */ -export const flattenSidebarSel = (s: SiteStore) => { - return s.sidebar.map((i) => i.children).flat(); +export const flattenSidebarSel = (s: SiteStore): ISidebarItem[] => { + return s.sidebar?.map((i) => i.children).flat() || []; }; export const contentBottomSel = (s: SiteStore) => { diff --git a/src/store/useSiteStore.ts b/src/store/useSiteStore.ts index 2c1bd6a..e4370ca 100644 --- a/src/store/useSiteStore.ts +++ b/src/store/useSiteStore.ts @@ -38,7 +38,7 @@ export interface ISiteData { export interface SiteStore { siteData: ISiteData; - sidebar: ISidebarGroup[]; + sidebar?: ISidebarGroup[]; routeMeta: IRouteMeta; navData: NavData; location: Location;