In my nuxt project, I am encountering an issue with the meta title and description. These values are coming from nuxt/content.
The data is fetched asynchronously in the index and passed to a sub component using a getter.
When generating the page, the meta tags are present, but not during SSR (server-side rendering).
I have tried using async/await, but I still receive the following error:
Uncaught (in promise) TypeError: seoTitle is undefined
I attempted to solve this by adding a useless await before this.getArticle const, hoping that it would make everything wait for the data, but unfortunately, the issue persists.
Below is the code snippet showing how I am handling the meta titles and descriptions:
async head() {
const article = await this.getArticle;
const seoTitle = await this.getArticle.seoTitle,
title = await this.getArticle.title,
seoDescription = await this.getArticle.description;
return {
title: `"${
seoTitle.length ? seoTitle : title
}"`,
meta: [{
hid: "description",
name: "description",
content: `${
seoDescription.length
? seoDescription.slice(0, 50)
: seoDescription.slice(0, 50)
}`,
}],
};
},