Skip to content

Commit

Permalink
feat: support custom layout component
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 committed Sep 13, 2022
1 parent 3970406 commit 71be9be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions docs/src/custom.tsx
@@ -0,0 +1,5 @@
export const pageType = 'custom';

export default function Custom() {
return <div>This is a custom component </div>;
}
1 change: 0 additions & 1 deletion src/client/runtime/client-entry.tsx
@@ -1,4 +1,3 @@

import { hydrateRoot, createRoot } from 'react-dom/client';
import { ComponentType } from 'react';
import { BrowserRouter } from 'react-router-dom';
Expand Down
25 changes: 14 additions & 11 deletions src/client/theme-default/layout/Layout/index.tsx
Expand Up @@ -2,28 +2,31 @@ import React from 'react';
import { HomeLayout } from '../HomeLayout';
import { Nav } from '../../components/Nav';
import { DocLayout } from '../DocLayout';
import { usePageData } from 'island/client';
import { usePageData, Content } from 'island/client';
import { NotFoundLayout } from 'island/theme';

export const Layout: React.FC = () => {
const { pageType } = usePageData();
// Use doc layout by default
const getContentLayout = () => {
if (pageType === 'home') {
return <HomeLayout />;
} else if (pageType === 'doc') {
return <DocLayout />;
} else if (pageType === '404') {
return <NotFoundLayout />;
} else {
return <DocLayout />;
switch (pageType) {
case 'home':
return <HomeLayout />;
case 'doc':
return <DocLayout />;
case '404':
return <NotFoundLayout />;
case 'custom':
return <Content />;
default:
return <DocLayout />;
}
};

return (
<div>
<div style={{ height: '100%' }}>
<Nav />
{getContentLayout()}
<section style={{ paddingTop: '72px' }}>{getContentLayout()}</section>
</div>
);
};

0 comments on commit 71be9be

Please sign in to comment.