Skip to content

Commit 9a1ce76

Browse files
committed
feat(mdx): Improve mdx links
Support client-side routing
1 parent a3babb1 commit 9a1ce76

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import Head from "next/head";
22
import { MDXComponents } from "mdx/types";
3+
import Link from "next/link";
4+
5+
// To have client-side routing
6+
const CustomLink: MDXComponents["a"] = (props) => (
7+
<Link href={props.href!}>
8+
<a {...props} />
9+
</Link>
10+
);
311

412
/**
513
* Use Next's components in MDX (e.g. Head)
614
*/
715
export const mdxComponents: MDXComponents = {
16+
a: CustomLink,
817
// https://github.com/mdx-js/mdx/discussions/1921
918
head: Head as any,
1019
};

0 commit comments

Comments
 (0)