You can call the notFound function within a route segment and use the not-found.js file to show a 404 UI.
TypeScript
app/blog/[slug]/page.tsx
import { notFound } from 'next/navigation'
import { getPostBySlug } from '@/lib/posts'
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
const post = getPostBySlug(slug)
if (!post) {
notFound()
}
return
}
app/blog/[slug]/not-found.tsx
export default function NotFound() {
return 404 - Page Not Found
}
Top comments (0)