Loading and Error UI Conventions
Use the App Router file conventions loading.js, error.js, and not-found.js to build resilient, streamed routes with graceful fallbacks.
Why Loading and Error UI Matter
Advanced routing is not only about where a route lives but about what users see while it resolves or fails. The App Router gives you special files that wrap segments automatically.
loading.jsrenders an instant fallback while the segment streams.error.jscatches runtime errors in that segment.not-found.jsrenders whennotFound()is called.
The loading.js Convention
A loading.js file in a segment folder is automatically wrapped around page.js in a React Suspense boundary. While the server component awaits data, the loading UI shows instantly.
export default function Loading() {
return <div className="spinner">Loading dashboard...</div>;
}All lessons in this course
- Dynamic Routes and Catch-all Segments
- Nested Layouts and Route Groups
- Parallel and Intercepting Routes
- Loading and Error UI Conventions