Error: Cannot read properties of undefined (reading 'openGraph')
Answered
Dunker posted this in #help-forum
DunkerOP
Unable to fetch parent layout's metadata, any idea what could cause this issue?
https://media.discordapp.net/attachments/663324452934778880/1163840526152372315/image.png?ex=654109f4&is=652e94f4&hm=e35d768f1433c11e8556014999fa8297f16bc977fe6ffedd4efe28ecee70b731&=&width=1140&height=513
export async function generateMetadata(props: {
params: { tournament: string; seasonNo: number }
parent: ResolvingMetadata
}): Promise<Metadata> {
const { tournament, seasonNo } = props.params
const tournamentData = await getTournamentData(tournament, seasonNo)
const { tournamentName: name, seasonNo: season } = tournamentData
const [_, imageUrl] = await getMatchesData(tournament, seasonNo)
const title = `Matches | ${name} - Season ${season}`
const description = 'Upcoming matches & results of ' + `${name}, Season ${season}`
return {
title: title,
description: description,
openGraph: {
siteName: (await props.parent).openGraph?.siteName,
title: title,
images: imageUrl,
description: description
},
twitter: {
title: title,
images: imageUrl,
description: description
}
}
}
https://media.discordapp.net/attachments/663324452934778880/1163840526152372315/image.png?ex=654109f4&is=652e94f4&hm=e35d768f1433c11e8556014999fa8297f16bc977fe6ffedd4efe28ecee70b731&=&width=1140&height=513
Answered by Chinese Egret
parent
is the second argument to generateMetadata
, not in the object 🙂8 Replies
Chinese Egret
parent
is the second argument to generateMetadata
, not in the object 🙂Answer
Take a look at the function definition here:https://nextjs.org/docs/app/api-reference/functions/generate-metadata#generatemetadata-function
And how to use parent as well ^.
Its in that code example.
DunkerOP
I feel stupid, did not realize i was putting it under props object.
@Dunker thank you very much
Mark the answer 🙂