Skip to content

Commit

Permalink
feat(mdx): Improve mdx links
Browse files Browse the repository at this point in the history
Support client-side routing
  • Loading branch information
thien-do committed May 15, 2022
1 parent a3babb1 commit 9a1ce76
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/mdx/components.ts → lib/mdx/components.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import Head from "next/head";
import { MDXComponents } from "mdx/types";
import Link from "next/link";

// To have client-side routing
const CustomLink: MDXComponents["a"] = (props) => (
<Link href={props.href!}>
<a {...props} />
</Link>
);

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

1 comment on commit 9a1ce76

@vercel
Copy link

@vercel vercel bot commented on 9a1ce76 May 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.