Not-found and error pages: their own metadata
A not-found UI (notFound) and an error UI (error) keep their status.
A not-found UI (notFound) and an error UI (error) keep their status. Their metadata is their own: the module that owns
the UI exports notFoundMetadata or errorMetadata (a static object, or a function with the generateMetadata
signature). It is merged over the chain of the route that renders it, so a title takes the layout's template
(Not found · Site) and a field the UI does not set is inherited.
ts
export const notFoundMetadata = { title: "Not found", robots: { index: false } };
- A 404 is answered by the not-found UI of the route that renders it: the root layout's for an unknown URL. The browser merges the same metadata when that UI is on screen (a client navigation to an unknown path).
- An error status is answered by the innermost route that has an
errorUI (a loader orbeforeLoadfailure). An error caught inside a component has no route, so it gets the chain's metadata only. - The built-in 404 (no not-found UI answers) has the title
Not foundandnoindex. Configure it withcreateHandler({ notFoundPage: { title, noindex } }), or keep the status title (404 Not Found) and no robots tag withnotFoundPage: false.