تخطَّ إلى المحتوى

شرح Next.js

التحميل والأخطاء والحالات الخاصّة

الدرس 10 من 25· ⏱ 1 دقائق قراءة

loading.tsx — واجهة تحميل فورية

تظهر تلقائيًا أثناء جلب بيانات الصفحة (Suspense):

// app/blog/loading.tsx
export default function Loading() {
  return <p>جارٍ التحميل...</p>;
}

error.tsx — معالجة الأخطاء

"use client";
export default function Error({
  error,
  reset,
}: {
  error: Error;
  reset: () => void;
}) {
  return (
    <div>
      <p>حدث خطأ: {error.message}</p>
      <button onClick={reset}>أعد المحاولة</button>
    </div>
  );
}

not-found.tsx — صفحة 404 مخصّصة

import { notFound } from "next/navigation";

if (!post) notFound();   // يعرض not-found.tsx

مجموعات المسارات

مجلّد بين قوسين (group) ينظّم الملفّات دون التأثير على الرابط:

app/(marketing)/about/page.tsx   →   /about

🎯 التالي: مكوّنات الخادم (Server Components).

هل كان هذا الدرس مفيدًا؟