ข้ามไปยังเนื้อหา

หน้าตัวอย่าง

ไม่พบหน้า 404

ใช้เมื่อที่อยู่ไม่ตรงกับหน้าใด หรือระเบียนที่ลิงก์ชี้ไปไม่มีแล้ว Next.js แสดง app/not-found.tsx ให้ทุกที่อยู่ที่ไม่มีหน้า และแสดง not-found.tsx ที่ใกล้ที่สุดเมื่อหน้าเรียก notFound() ถ้าผู้ใช้ไม่มีสิทธิ์ดูระเบียนที่มีอยู่จริง ใช้หน้าไม่มีสิทธิ์ 403 แทน

คอมโพเนนต์ที่ใช้

import { StatusPage, Button, AppShell } from "@bsru/ui";

กฎของหน้านี้

ถ้อยคำ

  • บอกว่าหาไม่พบ ไม่ใช่ว่าผู้ใช้ทำผิด ข้อความเริ่มต้นของ StatusPage ใช้ได้กับทุกที่อยู่
  • เมื่อรู้ว่าหาอะไรไม่พบ เช่น บัญชีผู้ใช้ ให้บอกชื่อสิ่งนั้นในหัวข้อ และบอกที่ที่หาได้

ปุ่มและทางไปต่อ

  • ปุ่มหลักหนึ่งปุ่ม: กลับหน้าแรก หรือกลับไปรายการที่ระเบียนนั้นอยู่
  • ปุ่มรองเป็นทางเลือกเท่านั้น อย่าเกินสองปุ่ม

ห้ามแสดง

  • ที่อยู่ที่ผู้ใช้พิมพ์ ชื่อไฟล์ หรือเส้นทางภายในของระบบ
  • ข้อความที่บอกว่าระเบียนนั้นมีอยู่แต่ถูกซ่อน เพราะจะบอกว่ามีระเบียนนั้นอยู่จริง

ในแอป

  • ก่อนเข้าสู่ระบบหรือนอกโครงแอป ใช้แบบเต็มหน้าจอ พร้อม brand และ notice ในระบบจำลอง
  • ในโครงแอป ส่ง fill={false} เพื่อให้เมนูและแถบบนยังอยู่ AppShell แสดงแถบระบบจำลองเอง
  • ตอบด้วยสถานะ HTTP 404 ซึ่ง Next.js ทำให้เมื่อใช้ not-found.tsx หรือ notFound()

ตัวอย่างทั้งหน้า

แต่ละตัวอย่างเป็นหน้าเต็ม แสดงในกรอบจอคอมพิวเตอร์ เลือกโทรศัพท์หรือแท็บเล็ตที่แถบบนเพื่อดูบนจอนั้น ข้อมูลทั้งหมดเป็นข้อมูลสมมติ

ERP: ที่อยู่ที่ไม่มีหน้า

app/not-found.tsx แสดงเต็มหน้าจอ ใช้หัวข้อและคำอธิบายเริ่มต้นของ StatusPage ตราลิงก์กลับหน้าแรก

จอคอมพิวเตอร์ 1280 × 800 px
// app/not-found.tsx: every address that matches no page, before the app frame.
import { Button, StatusPage } from "@bsru/ui";
import { House } from "lucide-react";
import { getTranslations } from "next-intl/server";
import { isDemo } from "@/server/env";

export default async function NotFound() {
  const t = await getTranslations();
  return (
    <StatusPage
      kind="notFound"
      brand={{ name: "BSRU ERP", caption: t("brand.university"), logo: "/bsru-logo.png", alt: t("brand.seal"), href: "/" }}
      notice={isDemo() ? t("shell.demo") : undefined}
      actions={<Button tone="primary" icon={House} label={t("status.home")} href="/" />}
    />
  );
}

คอนโซล: ระเบียนที่ไม่มีแล้ว ในโครงแอป

หน้าเรียก notFound() เมื่อไม่พบบัญชี not-found.tsx ของเส้นทางนั้นแสดงใน AppShell ด้วย fill={false} บอกว่าหาอะไรไม่พบ และให้กลับไปรายการ

จอคอมพิวเตอร์ 1280 × 800 px
// app/(console)/accounts/[id]/not-found.tsx: shown when the page calls notFound(), inside the console's AppShell.
import { Button, StatusPage } from "@bsru/ui";
import { ArrowLeft, House } from "lucide-react";
import { getTranslations } from "next-intl/server";

export default async function AccountNotFound() {
  const t = await getTranslations();
  return (
    <StatusPage
      kind="notFound"
      fill={false}
      title={t("accounts.notFound.title")}
      description={t("accounts.notFound.body")}
      actions={
        <>
          <Button tone="primary" icon={ArrowLeft} label={t("accounts.backToList")} href="/accounts" />
          <Button icon={House} label={t("status.home")} href="/" />
        </>
      }
    />
  );
}

// app/(console)/accounts/[id]/page.tsx
const account = await getAccount(id);
if (!account) notFound();