Skip to main content

default.js

当 Next.js 在全页加载后无法恢复 插槽的 活动状态时,default.js 文件用于在 并行路由 内渲染后备。

¥The default.js file is used to render a fallback within Parallel Routes when Next.js cannot recover a slot's active state after a full-page load.

软导航 期间,Next.js 跟踪每个槽的活动状态(子页面)。但是,对于硬导航(全页加载),Next.js 无法恢复活动状态。在这种情况下,可以为与当前 URL 不匹配的子页面渲染 default.js 文件。

¥During soft navigation, Next.js keeps track of the active state (subpage) for each slot. However, for hard navigations (full-page load), Next.js cannot recover the active state. In this case, a default.js file can be rendered for subpages that don't match the current URL.

考虑以下文件夹结构。@team 插槽有 settings 页,但 @analytics 没有。

¥Consider the following folder structure. The @team slot has a settings page, but @analytics does not.

当导航到 /settings 时,@team 插槽将渲染 settings 页面,同时维护 @analytics 插槽的当前活动页面。

¥When navigating to /settings, the @team slot will render the settings page while maintaining the currently active page for the @analytics slot.

刷新时,Next.js 将为 @analytics 渲染 default.js。如果 default.js 不存在,则会渲染 404

¥On refresh, Next.js will render a default.js for @analytics. If default.js doesn't exist, a 404 is rendered instead.

此外,由于 children 是隐式插槽,因此你还需要创建 default.js 文件,以便在 Next.js 无法恢复父页面的活动状态时渲染 children 的后备。

¥Additionally, since children is an implicit slot, you also need to create a default.js file to render a fallback for children when Next.js cannot recover the active state of the parent page.

属性

¥Props

params(可选)

¥params (optional)

包含从根段到插槽子页的 动态路由参数 的对象。例如:

¥An object containing the dynamic route parameters from the root segment down to the slot's subpages. For example:

示例URLparams
app/[artist]/@sidebar/default.js/zack{ artist: 'zack' }
app/[artist]/[album]/@sidebar/default.js/zack/next{ artist: 'zack', album: 'next' }