How navigation works
Server rendering
Layouts and pages are React Server Components by default. On initial and subsequent navigations, the Server Component Payload is generated on the server before being sent to the client. There are two types of server rendering:- Prerendering — happens at build time or during revalidation; the result is cached.
- Dynamic rendering — happens at request time in response to a client request.
Prefetching
Prefetching loads a route in the background before the user navigates to it. By the time a user clicks a link, the data to render the next route is already available on the client. Next.js automatically prefetches routes linked with the<Link> component when they enter the user’s viewport:
- Static route — the full route is prefetched.
- Dynamic route — prefetching is skipped, or the route is partially prefetched if a
loading.tsxfile is present.
Streaming
Streaming allows the server to send parts of a dynamic route to the client as soon as they’re ready, rather than waiting for the entire route to render. Users see something sooner even while parts of the page are still loading. To use streaming, create aloading.tsx file in your route folder:
page.tsx contents in a <Suspense> boundary. The prefetched fallback UI is shown while the route renders, then swapped for the actual content once ready.
Benefits of loading.tsx:
- Immediate navigation and visual feedback.
- Shared layouts remain interactive and navigation is interruptible.
- Improved Core Web Vitals: TTFB, FCP, and TTI.
Client-side transitions
Next.js avoids full page reloads with client-side transitions using the<Link> component. Instead of reloading the page, it updates content dynamically by:
- Keeping any shared layouts and UI.
- Replacing the current page with the prefetched loading state or the new page if available.
What can make transitions slow?
Dynamic routes without loading.tsx
When navigating to a dynamic route without a loading.tsx file, the client must wait for the full server response before anything is shown.
Add loading.tsx to dynamic routes to enable partial prefetching, trigger immediate navigation, and display a loading UI while the route renders:
Dynamic segments without generateStaticParams
If a dynamic segment could be prerendered but is missing generateStaticParams, the route falls back to dynamic rendering at request time.
Add generateStaticParams to pre-generate pages at build time:
Slow networks
On slow or unstable networks, prefetching may not finish before the user clicks a link. Use theuseLinkStatus hook to show immediate feedback while the transition is in progress:
opacity: 0). The indicator only shows if navigation takes longer than the delay.
Disabling prefetching
Opt out of prefetching by settingprefetch={false} on <Link>. This is useful for large lists of links (e.g. infinite scroll tables) where prefetching all links would waste resources:
- Static routes are only fetched when the user clicks the link.
- Dynamic routes must be rendered on the server before the client can navigate.
Native History API
Next.js integrates with the nativewindow.history.pushState and window.history.replaceState methods, syncing with usePathname and useSearchParams.
