mdx-components.js
使用 带有应用路由的 @next/mdx
需要 mdx-components.js|tsx
文件,没有它就无法工作。此外,你还可以将其用于 定制样式。
¥The mdx-components.js|tsx
file is required to use @next/mdx
with App Router and will not work without it. Additionally, you can use it to customize styles.
使用项目根目录中的文件 mdx-components.tsx
(或 .js
)来定义 MDX 组件。例如,与 pages
或 app
处于同一级别,或者在 src
内部(如果适用)。
¥Use the file mdx-components.tsx
(or .js
) in the root of your project to define MDX Components. For example, at the same level as pages
or app
, or inside src
if applicable.
tsx
import type { MDXComponents } from 'mdx/types'
const components: MDXComponents = {}
export function useMDXComponents(): MDXComponents {
return components
}
导出
¥Exports
useMDXComponents
功能
¥useMDXComponents
function
该文件必须导出一个名为 useMDXComponents
的函数。此函数不接受任何参数。
¥The file must export a single function named useMDXComponents
. This function does not accept any arguments.
tsx
import type { MDXComponents } from 'mdx/types'
const components: MDXComponents = {}
export function useMDXComponents(): MDXComponents {
return components
}
版本历史
¥Version History
版本 | 更改 |
---|---|
v13.1.2 | 已添加 MDX 组件 |