-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Open
Labels
Error HandlingRelated to handling errors (e.g., error.tsx, global-error.tsx).Related to handling errors (e.g., error.tsx, global-error.tsx).linear: nextConfirmed issue that is tracked by the Next.js team.Confirmed issue that is tracked by the Next.js team.
Description
Describe the feature you'd like to request
I would like to have the possibility to control the page title, description etc. in the error and not-found page.
currently Its possible to get around not-found page by creating a conditional in metadata function for the not-found page but is still not nice.
Describe the solution you'd like
I would like not-found.js and error.js accept metadata
and generateMetadata()
similar to page.js
and layout.js
// app/entity/[entityId]/not-found.js
export async function generateMetadata(props) {
return {
title: `entity ${props.params.entityId} not found`,
description: `There is no entity with id: ${props.params.entityId}`
}
}
export default function EntityNotFound() {
return <div>Sorry this Entity was not found</div>;
}
// app/error.js
export const metadata = {
title: "Error",
description: "ups something went wrong"
}
export default function Error() {
return <div>Sorry this Entity was not found</div>;
}
Describe alternatives you've considered
for not-found, maybe allow to pass the metadata object as an argument for the function
export default async function AnimalPage(props) {
const singleEntity = await getAnimalById(props.params.entityId);
if (!singleEntity) {
const metadata = {
title: `entity ${props.params.entityId} not found`,
description: `There is no entity with id: ${props.params.entityId}`
}
notFound(metadata);
}
return <>
... rest of the component
}
cbetancourt, mschaul, akratzel, karlhorky, jahirfiquitiva and 77 moremdaoust-sidlee, AntonWeigel and lucasmcht
Metadata
Metadata
Assignees
Labels
Error HandlingRelated to handling errors (e.g., error.tsx, global-error.tsx).Related to handling errors (e.g., error.tsx, global-error.tsx).linear: nextConfirmed issue that is tracked by the Next.js team.Confirmed issue that is tracked by the Next.js team.