devIndicators
用于配置屏幕指示器的选项,该指示器会在开发期间提供有关你当前所查看路由的上下文信息。
devIndicators 允许你配置屏幕指示器,该指示器会在开发期间提供有关你当前所查看路由的上下文信息。
打开 next.config.ts 并设置 position 以选择指示器的显示位置。默认值为 bottom-left。
next.config.ts
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.ts
const nextConfig: NextConfig = {
devIndicators: false,
}
export default nextConfig故障排除#
指示器未将路由标记为静态#
如果你期望某个路由是静态的,但指示器将其标记为动态,那么很可能是该路由选择退出了预渲染。
你可以通过使用 next build --debug 构建应用并查看终端输出,来确认某个路由是预渲染还是动态渲染。静态(或预渲染)路由会显示 ○ 符号,而动态路由会显示 ƒ 符号。例如:
Build Output
Route (app)
┌ ○ /_not-found
└ ƒ /products/[id]
○ (Static) 预渲染为静态内容
ƒ (Dynamic) 按需进行服务端渲染路由选择退出预渲染的原因有两个:
- 存在依赖请求信息的 Request-time API。
- 未缓存的数据请求,例如对 ORM 或数据库驱动的调用。
检查你的路由是否存在上述任一情况,如果无法静态渲染该路由,请考虑使用 loading.js 或 <Suspense /> 来利用流式渲染。
当从页面导出 getServerSideProps 或 getInitialProps 时,该路由会被标记为动态。
版本历史#
| 版本 | 变更 |
|---|---|
v16.0.0 | appIsrStatus、buildActivity 和 buildActivityPosition 选项已移除。 |
v15.2.0 | 改进了屏幕指示器,新增 position 选项。appIsrStatus、buildActivity 和 buildActivityPosition 选项已弃用。 |
v15.0.0 | 新增静态屏幕指示器,带有 appIsrStatus 选项。 |