Skip to content

Commit 57cac1c

Browse files
mokuwakiclaude
andcommitted
Fix MDX internal links missing basePath by using Next.js Link component
MDX content links like [text](/docs/...) rendered as plain <a> tags, which don't get the Next.js basePath prefix, causing 404s on GitHub Pages. Added MdxLink component that routes internal links through Next.js Link for automatic basePath handling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c00e4f6 commit 57cac1c

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/components/docs/mdx/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Link from "next/link";
12
import { Heading } from "./Heading";
23
import { CodeBlock } from "./CodeBlock";
34
import { Callout } from "./Callout";
@@ -12,6 +13,14 @@ import { Badge } from "./Badge";
1213
import { FileTree } from "./FileTree";
1314
import { Image } from "./Image";
1415

16+
function MdxLink(props: React.AnchorHTMLAttributes<HTMLAnchorElement>) {
17+
const { href, children, ...rest } = props;
18+
if (href && href.startsWith("/")) {
19+
return <Link href={href} {...rest}>{children}</Link>;
20+
}
21+
return <a href={href} {...rest}>{children}</a>;
22+
}
23+
1524
export { Accordion, AccordionItem } from "./Accordion";
1625
export { ApiTable } from "./ApiTable";
1726
export { Badge } from "./Badge";
@@ -42,6 +51,7 @@ export const mdxComponents: Record<string, React.ComponentType<any>> = {
4251
table: Table,
4352
pre: CodeBlock,
4453
img: Image,
54+
a: MdxLink,
4555
Callout,
4656
Steps,
4757
Tabs,

0 commit comments

Comments
 (0)