// app/dashboard/loading.tsx — shown instantly while the page's async work runsexportdefaultfunctionLoading() {
return ; // layout stays visible; only this area is a skeleton
}
// app/dashboard/error.tsx — MUST be a client component'use client';
exportdefaultfunctionError({
error, reset,
}: { error: Error & { digest?: string }; reset: () => void }) {
return (
Something broke.
Try again {/* re-renders the segment */}
);
}
// app/not-found.tsx — rendered when notFound() is thrown, or for unmatched routesexportdefaultfunctionNotFound() {
return404 — no such page;
}
// For finer control, drop Suspense boundaries INSIDE the page for per-widget streaming:import { Suspense } from'react';
}>
Итог
File conventions for segment-level UX; inline Suspense for widget granularity.
Next.js: Loading и error UI — пример кода · Sobeso