Closed Huucong95 closed 1 year ago
https://nuxt-seo.frostbutter.com/examples/blog If I do it this way, I need to reload the page to load the 'head'
For my SSG I'm using the head method as specified in the documentation: https://nuxt-seo.frostbutter.com/usage. It works perfectly this way ! Just get the api data you need with asyncData and then use it.
async asyncData({ $graphql }) {
const query = backgroundImg
const answer = await $graphql.default.request(query)
return { answer }
},
head({ $seo }) {
return $seo({
description: this.answer.seoDescription,
}
})
This code assumes you get an object from your API with a seoDescription data inside. I hope this helps!
@eliascarella answered this so wonderfully, I am going to close this issue :1st_place_medal:
Reason to "not set SEO via asyncData"
The reason for the documentation stating to NOT set the SEO in asyncData for SSR is that the titles will not be updates as you navigate between the different pages on the Nuxt site. In this case the title is only updates upon initial load of the site. And will not change when navigating to another page. But if you refresh the browser on that new page, the title is updated
So what to do with the data from the api?