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.