Skip to content

Commit 6003eb1

Browse files
committed
fix native url routing
1 parent 90b6f86 commit 6003eb1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

app/docs/[[...slug]]/page.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { source } from "@/lib/source";
2+
import { getMDXComponents } from "@/mdx-components";
3+
import { createRelativeLink } from "fumadocs-ui/mdx";
4+
import { DocsBody, DocsDescription, DocsPage, DocsTitle } from "fumadocs-ui/page";
5+
import { notFound } from "next/navigation";
6+
7+
export default async function Page(props: { params: Promise<{ slug?: string[] }> }) {
8+
const params = await props.params;
9+
const page = source.getPage(params.slug);
10+
if (!page) notFound();
11+
12+
const MDXContent = page.data.body;
13+
14+
return (
15+
<DocsPage toc={page.data.toc} full={page.data.full}>
16+
<DocsTitle>{page.data.title}</DocsTitle>
17+
<DocsDescription>{page.data.description}</DocsDescription>
18+
<DocsBody>
19+
<MDXContent
20+
components={getMDXComponents({
21+
// this allows you to link to other pages with relative file paths
22+
a: createRelativeLink(source, page)
23+
})}
24+
/>
25+
</DocsBody>
26+
</DocsPage>
27+
);
28+
}
29+
30+
export async function generateStaticParams() {
31+
return source.generateParams();
32+
}
33+
34+
export async function generateMetadata(props: { params: Promise<{ slug?: string[] }> }) {
35+
const params = await props.params;
36+
const page = source.getPage(params.slug);
37+
if (!page) notFound();
38+
39+
return {
40+
title: page.data.title,
41+
description: page.data.description
42+
};
43+
}

0 commit comments

Comments
 (0)