Canonical tag in generateMetadata for static export
Answered
averydelusionalperson posted this in #help-forum
So, I have this
How can I generate this canonical tag for every page on the build with static exports, I can't use headers to get
Any Ideas?
generateMetadata function in layout.tsxexport const generateMetadata = () => {
const siteURL = "https://srisaitravels.ymtsindia.net";
return {
metadataBase: new URL(siteURL),
alternates: {
canonical: `/`,
},
};
};How can I generate this canonical tag for every page on the build with static exports, I can't use headers to get
pathName, cause this is static export. Any Ideas?
Answered by riský
i mean, on every page you can have the generateMetadate/matadata with the right canonical
23 Replies
If I'm on about page, I want the canonical tag as website_url/about, help = website_url/help, etc.
I searched ways to do it, without making all pages dynamic, so far couldn't find anything, so thought to ask in the discord server, might get cleared if I can do it or not.
Plott Hound
you should be able to access it from the headers https://nextjs.org/docs/app/api-reference/functions/headers
something like this
const headersList = headers();
const pathName =
headersList.get('x-url') || headersList.get('x-invoke-path') || '';yeah, IK I can use headers, but it won't work for static export
IG there is no solution as of now
Plott Hound
yeah without hard coding them
sorry i missed that you were trying to static export
i mean, on every page you can have the generateMetadate/matadata with the right canonical
Answer
@riský i mean, on every page you can have the generateMetadate/matadata with the right canonical
What if I have 100's of pages, can't add metadata to each page.
make an automated script or don't do it ig
do you not have any metadata in pages already?
I'll prolly update it manually, or write some quick node script
thanks for the idea
you don't have any other response, do you lol? I swear you respond "yay nice" every single time
well its nice
hmm whats a better response... thats good to hear... i hope it works well
noice is better
(but honesly i think its easy to respond quickly and convay that im happy its fixed)
fake happiness 🙂