Three special files, three behaviors
| File | What it does | Server or Client? |
|---|---|---|
loading.tsx | Wraps the page in Suspense; shown while data loads | Either |
error.tsx | Error boundary for the segment and below | Must be Client |
not-found.tsx | UI for notFound() calls in this segment | Either |
global-error.tsx for the root
An error.tsx can't catch errors in its own layout. The root layout has a special boundary: app/global-error.tsx. It must render its own <html> and <body> because it replaces the broken root layout.
Trigger 404 from anywhere
Call notFound() from next/navigation in a Server Component to bail out and render the nearest not-found.tsx. The framework handles the status code (404) for you.