主题
devIndicators
devIndicators
允许你配置屏幕指示器,该指示器提供有关你在开发过程中正在查看的当前路由的上下文。
¥devIndicators
allows you to configure the on-screen indicator that gives context about the current route you're viewing during development.
ts
devIndicators: false | {
position?: 'bottom-right'
| 'bottom-left'
| 'top-right'
| 'top-left', // defaults to 'bottom-left',
},
将 devIndicators
设置为 false
将隐藏指示器,但 Next.js 将继续显示遇到的任何构建或运行时错误。
¥Setting devIndicators
to false
will hide the indicator, however Next.js will continue to surface any build or runtime errors that were encountered.
故障排除
¥Troubleshooting
指示器未将路由标记为静态
¥Indicator not marking a route as static
如果你希望路由是静态的,而指示器已将其标记为动态,则路由很可能已选择退出静态渲染。
¥If you expect a route to be static and the indicator has marked it as dynamic, it's likely the route has opted out of static rendering.
你可以通过使用 next build --debug
构建应用并检查终端中的输出来确认路由是 static 还是 dynamic。静态(或预渲染)路由将显示 ○
符号,而动态路由将显示 ƒ
符号。例如:
¥You can confirm if a route is static or dynamic by building your application using next build --debug
, and checking the output in your terminal. Static (or prerendered) routes will display a ○
symbol, whereas dynamic routes will display a ƒ
symbol. For example:
bash
Route (app) Size First Load JS
┌ ○ /_not-found 0 B 0 kB
└ ƒ /products/[id] 0 B 0 kB
○ (Static) prerendered as static content
ƒ (Dynamic) server-rendered on demand
有两个原因可能导致路由选择退出静态渲染:
¥There are two reasons a route might opt out of static rendering:
动态 API 的存在依赖于运行时信息。
¥The presence of Dynamic APIs which rely on runtime information.
未缓存的数据请求,例如对 ORM 或数据库驱动程序的调用。
¥An uncached data request, like a call to an ORM or database driver.
检查你的路由是否存在以下任何情况,如果你无法静态渲染路由,请考虑使用 loading.js
或 <Suspense />
来利用 streaming。
¥Check your route for any of these conditions, and if you are not able to statically render the route, then consider using loading.js
or <Suspense />
to leverage streaming.
版本历史
¥Version History
版本 | 更改 |
---|---|
v15.2.0 | 使用新的 position 选项改进了屏幕指示器。appIsrStatus 、buildActivity 和 buildActivityPosition 选项已被弃用。 |
v15.0.0 | 使用 appIsrStatus 选项添加了静态屏幕指示器。 |