From 1c238302728bbf58d8874cc2d63d3feb8e9dc254 Mon Sep 17 00:00:00 2001 From: Jakub Knetl Date: Wed, 3 Jan 2024 09:47:57 +0100 Subject: [PATCH] Chapter 13 - Handle specific error (not found in this case) --- app/dashboard/invoices/[id]/edit/not-found.tsx | 18 ++++++++++++++++++ app/dashboard/invoices/[id]/edit/page.tsx | 5 +++++ app/lib/data.ts | 1 + 3 files changed, 24 insertions(+) create mode 100644 app/dashboard/invoices/[id]/edit/not-found.tsx diff --git a/app/dashboard/invoices/[id]/edit/not-found.tsx b/app/dashboard/invoices/[id]/edit/not-found.tsx new file mode 100644 index 0000000..26a35e0 --- /dev/null +++ b/app/dashboard/invoices/[id]/edit/not-found.tsx @@ -0,0 +1,18 @@ +import Link from 'next/link'; +import { FaceFrownIcon } from '@heroicons/react/24/outline'; + +export default function NotFound() { + return ( +
+ +

404 Not Found

+

Could not find the requested invoice.

+ + Go Back + +
+ ); +} \ No newline at end of file diff --git a/app/dashboard/invoices/[id]/edit/page.tsx b/app/dashboard/invoices/[id]/edit/page.tsx index 72f9a6b..8719078 100644 --- a/app/dashboard/invoices/[id]/edit/page.tsx +++ b/app/dashboard/invoices/[id]/edit/page.tsx @@ -1,6 +1,7 @@ import Form from '@/app/ui/invoices/edit-form'; import Breadcrumbs from '@/app/ui/invoices/breadcrumbs'; import {fetchCustomers, fetchInvoiceById} from '@/app/lib/data'; +import { notFound } from 'next/navigation'; export default async function Page({ params }: { params: { id: string } }) { const id = params.id; @@ -8,6 +9,10 @@ export default async function Page({ params }: { params: { id: string } }) { fetchInvoiceById(id), fetchCustomers(), ]); + + if (!invoice) { + notFound(); + } return (