Skip to content

Commit 71be9be

Browse files
committed
feat: support custom layout component
1 parent 3970406 commit 71be9be

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

docs/src/custom.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const pageType = 'custom';
2+
3+
export default function Custom() {
4+
return <div>This is a custom component </div>;
5+
}

src/client/runtime/client-entry.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { hydrateRoot, createRoot } from 'react-dom/client';
32
import { ComponentType } from 'react';
43
import { BrowserRouter } from 'react-router-dom';

src/client/theme-default/layout/Layout/index.tsx

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,31 @@ import React from 'react';
22
import { HomeLayout } from '../HomeLayout';
33
import { Nav } from '../../components/Nav';
44
import { DocLayout } from '../DocLayout';
5-
import { usePageData } from 'island/client';
5+
import { usePageData, Content } from 'island/client';
66
import { NotFoundLayout } from 'island/theme';
77

88
export const Layout: React.FC = () => {
99
const { pageType } = usePageData();
1010
// Use doc layout by default
1111
const getContentLayout = () => {
12-
if (pageType === 'home') {
13-
return <HomeLayout />;
14-
} else if (pageType === 'doc') {
15-
return <DocLayout />;
16-
} else if (pageType === '404') {
17-
return <NotFoundLayout />;
18-
} else {
19-
return <DocLayout />;
12+
switch (pageType) {
13+
case 'home':
14+
return <HomeLayout />;
15+
case 'doc':
16+
return <DocLayout />;
17+
case '404':
18+
return <NotFoundLayout />;
19+
case 'custom':
20+
return <Content />;
21+
default:
22+
return <DocLayout />;
2023
}
2124
};
2225

2326
return (
24-
<div>
27+
<div style={{ height: '100%' }}>
2528
<Nav />
26-
{getContentLayout()}
29+
<section style={{ paddingTop: '72px' }}>{getContentLayout()}</section>
2730
</div>
2831
);
2932
};

0 commit comments

Comments
 (0)