devIndicators
用于配置屏幕指示器的选项,该指示器在开发过程中提供你所查看的当前路由的相关信息。
devIndicators 允许你配置屏幕指示器,它在开发过程中提供你所查看的当前路由的相关信息。
打开 next.config.ts 并设置 position,以选择指示器的渲染位置。默认为 bottom-left。
next.config.tsts
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
devIndicators: {
position: 'bottom-right', // 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right'
},
}
export default nextConfig
要完全隐藏指示器,请将 devIndicators 设置为 false。Next.js 仍会显示遇到的任何编译或运行时错误。
next.config.tsts
const nextConfig: NextConfig = {
devIndicators: false,
}
export default nextConfig
故障排除
指示器未将路由标记为静态
如果你期望某个路由是静态的,但指示器将其标记为动态,那么很可能是该路由退出了预渲染。
你可以使用 next build --debug 构建应用,并在终端中查看输出,以确认某个路由是预渲染的还是动态渲染的。静态(或预渲染)路由会显示 ○ 符号,而动态路由会显示 ƒ 符号。例如:
Build Outputbash
Route (app)
┌ ○ /_not-found
└ ƒ /products/[id]
○ (Static) prerendered as static content
ƒ (Dynamic) server-rendered on demand
路由退出预渲染可能有两个原因:
检查你的路由是否存在上述任一情况。如果无法静态渲染该路由,那么可以考虑使用 loading.js 或 <Suspense /> 来利用流式渲染。
版本历史
| 版本 | 变更 |
|---|---|
v16.0.0 |
appIsrStatus、buildActivity 和 buildActivityPosition 选项已被移除。 |
v15.2.0 |
改进了屏幕指示器,新增 position 选项。appIsrStatus、buildActivity 和 buildActivityPosition 选项已被弃用。 |
v15.0.0 |
新增静态屏幕指示器,并提供 appIsrStatus 选项。 |