Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/.dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default defineConfig({
zh: '教程',
en: 'Tutorials',
},
sidebar: false,
order: 2,
},
{
Expand Down
22 changes: 19 additions & 3 deletions src/slots/ManualContent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
import { Layout } from 'antd';
import { useRouteMeta } from 'dumi';
import { useLocation, useRouteMeta, useSiteData } from 'dumi';
import React, { type PropsWithChildren } from 'react';
import CommonHelmet from '../../common/CommonHelmet';
import { getNavCategory } from '../Header/utils';
import styles from './index.module.less';
import { Main } from './Main';
import { Sidebar } from './Sidebar';

export const ManualContent: React.FC<PropsWithChildren> = ({ children }) => {
const meta = useRouteMeta();
const { title, description } = meta.frontmatter;
const { themeConfig } = useSiteData();
const { navs } = themeConfig;
const { pathname } = useLocation();

// 获取当前路径对应的导航分类
const currentCategory = getNavCategory(pathname);

// 查找匹配的导航配置
const currentNav = navs.find((nav) => {
if (!nav.slug) return false;
const navCategory = getNavCategory(nav.slug);
return navCategory === currentCategory;
});

const shouldShowSidebar = currentNav?.sidebar !== false;

return (
<Layout hasSider className={styles.layout}>
<Layout hasSider={shouldShowSidebar} className={styles.layout}>
<CommonHelmet title={title} description={description} />
<Sidebar />
{shouldShowSidebar && <Sidebar />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里把整个子路由下的侧边栏都隐藏,可能用户体验不太好哦。参考 antd,进入到组件页面时还是可以通过侧边栏切换的。

有一个替代方案,可以在待建设的页面打上 tag

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里把整个子路由下的侧边栏都隐藏,可能用户体验不太好哦。参考 antd,进入到组件页面时还是可以通过侧边栏切换的。

有一个替代方案,可以在待建设的页面打上 tag

我试一下打tag的方式

<Main>{children}</Main>
</Layout>
);
Expand Down