GenerateMetaData in Layout
Answered
LaPerm posted this in #help-forum
LaPermOP
Does GenerateMetaData work in layout or just pages in Next13 app router? I am pulling my data in from a CMS and so I want default meta data. Does this not work on the layout file?
Or is there a way to pass a prop from the layout to all children components? If this doesn't work I can fetch the data in the layout function and pass it down somehow?
export async function generateMetaData(): Promise<Metadata> {
const { metaTitle, metaDescription, ogImage } = await sanityFetch<ISettings>({
query: settingsQuery,
});
return {
title: metaTitle ',
description: metaDescription,
openGraph: {
images: [ogImage.url],
},
};
}
Or is there a way to pass a prop from the layout to all children components? If this doesn't work I can fetch the data in the layout function and pass it down somehow?
8 Replies
it is
generateMetadata
not generateMetaData
Answer
LaPermOP
Ok so it is detecting the function but my title tag is not being set and the data definately is coming through.
LaPermOP
export async function generateMetadata(): Promise<Metadata> {
const { metaTitle, metaDescription, ogImage } = await sanityFetch<ISettings>({
query: settingsQuery,
});
return {
metadataBase: new URL('http://localhost:3000'),
title: {
default: metaTitle,
template:
},
description: metaDescription,
openGraph: {
images: [ogImage?.url],
},
robots: {
index: false,
},
};
}
const { metaTitle, metaDescription, ogImage } = await sanityFetch<ISettings>({
query: settingsQuery,
});
return {
metadataBase: new URL('http://localhost:3000'),
title: {
default: metaTitle,
template:
%s | ${metaTitle}
,},
description: metaDescription,
openGraph: {
images: [ogImage?.url],
},
robots: {
index: false,
},
};
}
this is on pages as well
ohh is that what you meant... i didn't realise you wanted the template...
LaPermOP
I am just trying different things to get it to show I don’t mind if it’s just title without template but no dynamic values are working