next/link swaps pages in the browser without a full reload, and it fetches pages before the user clicks.
Client-side navigation. <Link> renders an a tag. But a click does a client-side navigation instead of a full page load:
- Next.js fetches only the RSC payload for the new route (the compact description of its rendered Server Component tree).
- Shared layouts stay mounted, with their state.
- The URL and browser history update.
Prefetching. In production, links are prefetched automatically when they scroll into view.
- For static routes, the whole route is prefetched.
- For dynamic routes, Next.js prefetches the shared layout and the
loading.tsxfallback. So the loading state shows at once.
Prefetched data is kept in the browser Router Cache. You can turn prefetching off with prefetch={false}. Prefetching does not run in development.
In code. For programmatic navigation in Client Components, use useRouter from next/navigation. Its router also has router.prefetch().
<Link>does client-side navigation with no full reload.- Only the RSC payload is fetched, and shared layouts stay mounted.
- Links in view are prefetched, in production only.
- Dynamic routes are prefetched down to the
loading.tsxfallback. - Use
useRouterfromnext/navigationto navigate in code.