Skip to content

Commit

Permalink
🐛 fix: 修正首页白屏的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Feb 22, 2023
1 parent 67ef0ce commit 31eb2be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
32 changes: 15 additions & 17 deletions src/slots/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@ const Sidebar: FC = () => {
const sidebar = useSiteStore((s) => s.sidebar, isEqual);
const { styles } = useStyles();

return (
sidebar && (
<div className={styles.sidebar}>
{sidebar.map((item, i) => (
<dl key={String(i)}>
{item.title && <dt>{item.title}</dt>}
{item.children.map((child) => (
<dd key={child.link}>
<NavLink to={child.link} title={child.title} end>
{child.title}
</NavLink>
</dd>
))}
</dl>
))}
</div>
)
return !sidebar ? null : (
<div className={styles.sidebar}>
{sidebar.map((item, i) => (
<dl key={String(i)}>
{item.title && <dt>{item.title}</dt>}
{item.children.map((child) => (
<dd key={child.link}>
<NavLink to={child.link} title={child.title} end>
{child.title}
</NavLink>
</dd>
))}
</dl>
))}
</div>
);
};

Expand Down
5 changes: 3 additions & 2 deletions src/store/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ISidebarItem } from 'dumi/dist/client/theme-api/types';
import { AnchorItem, ApiHeaderConfig, IFeature } from '../types';
import { SiteStore } from './useSiteStore';

Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/store/useSiteStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface ISiteData {

export interface SiteStore {
siteData: ISiteData;
sidebar: ISidebarGroup[];
sidebar?: ISidebarGroup[];
routeMeta: IRouteMeta;
navData: NavData;
location: Location;
Expand Down

0 comments on commit 31eb2be

Please sign in to comment.