useLinkStatus
is a Client Component hook that tracks the pending state of a <Link>
. Use it to show inline visual feedback (like spinners or text glimmers) while a navigation to a new route completes.
useLinkStatus
is useful when:
loading.js
file that would allow an instant navigation.Note: We recommend using loading.js
and not disabling prefetching. This allows Next.js to instantly navigate to the new route and show a loading state while the rest of the page loads.
loading.js
is intentionally not used.position: absolute
) or use a CSS approach that doesn't create an element (e.g. animating the background
position of a gradient).opacity: 0
) or outside the parent's clipping boundary (e.g. overflow: hidden
and translate: -100%
).Next.js routing is server centric. This has many benefits, but means navigations require a round trip to the server to get information about the new route.
Next.js alleviates this tradeoff through strategies like prerendering, prefetching and streaming. As well as API's developers can use like loading.js
and useLinkStatus
.
When a user navigates (e.g. clicking a <Link>
), there are two phases before the navigation is fully complete:
Next.js provides features and APIs to improve the loading experiences in both phases:
<Link>
prefetches routes to enable instant navigation. Static routes are fully prefetched by default. Dynamic routes are partially prefetched up to the nearest segment with a loading.js
file. Including the segments fallback UI in the prefetch allows instant navigation for dynamic routes.useLinkStatus
and useFormStatus
to show visual feedback to the user during the pending phase.loading.js
to define fallback UI for a route segment. On navigation, this essentially skips the pending phase and immediately shows something to the user while the rest of the content loads.<Suspense>
boundaries to further split server-side work into smaller parts and show something to the user earlier in the loading phase.