本页还没有译文
本页 7 段还没译成日本語,下面显示的是英文原文。notFound
还没翻译译自英文(nextjs.org)本页 7 段都还没译
The notFound function allows you to render the not-found file within a route segment as well as inject a <meta name="robots" content="noindex" /> tag for search engines.
notFound()
Invoking the notFound() function throws a NEXT_HTTP_ERROR_FALLBACK;404 error and terminates rendering of the route segment in which it was thrown. Specifying a not-found file allows you to gracefully handle such errors by rendering a Not Found UI within the segment.
app/user/[id]/page.js
import { notFound } from 'next/navigation'
async function fetchUser(id) {
const res = await fetch('https://...')
if (!res.ok) return undefined
return res.json()
}
export default async function Profile({ params }) {
const { id } = await params
const user = await fetchUser(id)
if (!user) {
notFound()
}
// ...
}Good to know
notFound() does not require you to use return notFound() due to using the TypeScript never type.
Version History
| Version | Changes |
|---|---|
v13.0.0 | notFound introduced. |
AI 翻译查看英文原文