Nextjs Fundamentals · Navigation

Streaming a route segment

`loading.tsx`

Streaming a route segment

Server-rendered routes can be slow to arrive, so the App Router lets you stream a route segment with a loading.tsx file. Drop it in a route folder and Next.js shows it immediately while the page's data loads:

// app/dashboard/loading.tsx
export default function Loading() {
  return <DashboardSkeleton />;
}

Behind the scenes, Next.js wraps the segment's page.tsx (and any nested layouts) in a <Suspense> boundary and uses loading.tsx as its fallback. The fallback is prefetched, so navigation can happen instantly; the real content streams in and is swapped in place when it is ready.

loading.tsx is a Server Component by default, but it can opt into the client with 'use client'. It takes no parameters — keep the UI lightweight, like a skeleton or spinner.

Placement matters. In the same folder, loading.tsx sits inside layout.tsx and wraps page.tsx and nested layouts. It does not wrap the layout.tsx, template.tsx, or error.tsx in that same segment. Because the fallback is prefetched, shared layouts stay interactive and navigation stays interruptible while the new segment loads.

For dynamic routes, loading.tsx is what makes partial prefetching possible: Next.js can prefetch the shared layout and the loading shell ahead of time, then stream the rest on navigation.

You are about to answer a short quiz on loading.tsx.

  1. A `loading.tsx` file provides an instant loading UI for a route segment while its content streams in.
  2. Next.js automatically wraps a segment's `page.tsx` in a ___ boundary using `loading.tsx` as the fallback.
  3. A `loading.tsx` in a folder wraps the `layout.tsx` in that same folder.
  4. A `loading.tsx` component receives route parameters as props.
  5. With a `loading.tsx` present, a dynamic route can be ___ prefetched.
  6. `loading.tsx` is a Server Component by default but can use the `'use client'` directive.