主题
ppr
部分预渲染 (PPR) 使你能够在同一路由中将静态和动态组件组合在一起。了解有关 PPR 的更多信息。
¥Partial Prerendering (PPR) enables you to combine static and dynamic components together in the same route. Learn more about PPR.
使用部分预渲染
¥Using Partial Prerendering
增量采用(版本 15)
¥Incremental Adoption (Version 15)
在 Next.js 15 中,你可以通过将 next.config.js 中的 ppr 选项设置为 incremental,并在文件顶部导出 experimental_ppr 路由配置选项,逐步采用 layouts 和 pages 中的部分预渲染:
¥In Next.js 15, you can incrementally adopt Partial Prerendering in layouts and pages by setting the ppr option in next.config.js to incremental, and exporting the experimental_ppr route config option at the top of the file:
ts
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
experimental: {
ppr: 'incremental',
},
}
export default nextConfigtsx
import { Suspense } from "react"
import { StaticComponent, DynamicComponent, Fallback } from "@/app/ui"
export const experimental_ppr = true
export default function Page() {
return {
<>
<StaticComponent />
<Suspense fallback={<Fallback />}>
<DynamicComponent />
</Suspense>
</>
};
}需要了解:
¥Good to know:
没有
experimental_ppr的路由将默认为false,并且不会使用 PPR 进行预渲染。你需要为每条路由明确选择加入 PPR。¥Routes that don't have
experimental_pprwill default tofalseand will not be prerendered using PPR. You need to explicitly opt-in to PPR for each route.
experimental_ppr将应用于路由段的所有子项,包括嵌套布局和页面。你不必将其添加到每个文件中,只需添加到路由的顶部部分即可。¥
experimental_pprwill apply to all children of the route segment, including nested layouts and pages. You don't have to add it to every file, only the top segment of a route.要禁用子段的 PPR,你可以在子段中将
experimental_ppr设置为false。¥To disable PPR for children segments, you can set
experimental_pprtofalsein the child segment.
| 版本 | 更改 |
|---|---|
v15.0.0 | 引入实验性 incremental 值 |
v14.0.0 | 引入实验性 ppr |