refactor: make all docs lazy imported

This commit is contained in:
p-sw 2024-08-03 23:42:31 +09:00
parent 52a78b146c
commit c5274444c0

View File

@ -9,19 +9,8 @@ import {
import DocsLayout from "./DocsLayout"; import DocsLayout from "./DocsLayout";
import DynamicLayout from "./DynamicLayout"; import DynamicLayout from "./DynamicLayout";
import ErrorBoundary from "./ErrorHandler"; import ErrorBoundary from "./ErrorHandler";
import Home from "./Home";
import MainLayout from "./MainLayout"; import MainLayout from "./MainLayout";
import DocsConfiguration, {
tableOfContents as docsConfigurationToc,
} from "./docs/configuration.mdx";
import DocsInstallation, {
tableOfContents as docsInstallationToc,
} from "./docs/installation.mdx";
import DocsIntroduction, {
tableOfContents as docsIntroductionToc,
} from "./docs/introduction.mdx";
import { Tooltip, TooltipContent } from "@pswui/Tooltip"; import { Tooltip, TooltipContent } from "@pswui/Tooltip";
import React, { import React, {
type ForwardedRef, type ForwardedRef,
@ -225,12 +214,20 @@ const router = createBrowserRouter(
> >
<Route <Route
index index
loader={() => lazy={async () => {
REDIRECTED_404.test(window.location.search) const { default: Component } = await import("./Home");
? redirect(REDIRECTED_404.exec(window.location.search)?.[1] ?? "/")
: true return {
} Component,
element={<Home />} loader() {
return REDIRECTED_404.test(window.location.search)
? redirect(
REDIRECTED_404.exec(window.location.search)?.[1] ?? "/",
)
: true;
},
};
}}
/> />
<Route <Route
path="docs" path="docs"
@ -242,27 +239,50 @@ const router = createBrowserRouter(
/> />
<Route <Route
path="introduction" path="introduction"
element={ lazy={async () => {
<DynamicLayout toc={docsIntroductionToc}> const { default: DocsIntroduction, tableOfContents } = await import(
<DocsIntroduction components={overrideComponents} /> "./docs/introduction.mdx"
</DynamicLayout> );
}
return {
Component: () => (
<DynamicLayout toc={tableOfContents}>
<DocsIntroduction components={overrideComponents} />
</DynamicLayout>
),
};
}}
/> />
<Route <Route
path="installation" path="installation"
element={ lazy={async () => {
<DynamicLayout toc={docsInstallationToc}> const { default: DocsInstallation, tableOfContents } = await import(
<DocsInstallation components={overrideComponents} /> "./docs/installation.mdx"
</DynamicLayout> );
}
return {
Component: () => (
<DynamicLayout toc={tableOfContents}>
<DocsInstallation components={overrideComponents} />
</DynamicLayout>
),
};
}}
/> />
<Route <Route
path="configuration" path="configuration"
element={ lazy={async () => {
<DynamicLayout toc={docsConfigurationToc}> const { default: DocsConfiguration, tableOfContents } =
<DocsConfiguration components={overrideComponents} /> await import("./docs/configuration.mdx");
</DynamicLayout>
} return {
Component: () => (
<DynamicLayout toc={tableOfContents}>
<DocsConfiguration components={overrideComponents} />
</DynamicLayout>
),
};
}}
/> />
<Route path="components"> <Route path="components">
<Route <Route