Server Side rendering and Meta Data - Help

How to Dynamically Populate Meta Tags with Article Data in Nuxt 3 - SSR? 0 I'm working on a Nuxt 3 application where I need to dynamically populate meta tags with the data of an article. Issue: The problem I'm facing is that the meta tags do not get populated with the dynamic data from the article object. If I use static data, the meta tags are populated correctly, but when I try to dynamically set them, they remain empty or fallback to default values. I've tried the following approaches without success: Using useHead, useServerHead, etc. Using reactive properties and watchers Ensuring data is fetched before setting meta tags ( not sure ) Attempted Solutions: Static Data: Using static data like title: "Static Title" works perfectly. Dynamic Data: Using title: article.title "Default Title" or title: () => article.title "Default Title" does not update the meta tags with the dynamic data. What I Suspect: I suspect that the issue might be related to the lifecycle of the component and SSR (Server-Side Rendering). The meta tags might be getting set before the data is fully fetched. Additionally, I’m not sure if the reactive properties are causing issues with how the meta tags are being set. Question: How can I ensure that the meta tags are populated with the dynamic data from the article object once it is fetched? Is there a recommended approach for handling this in Nuxt 3 with SSR? Any help or insights into resolving this issue would be greatly appreciated!
2 Replies
harlan
harlan5mo ago
onBeforeMount(async () => {
await fetchArticleData(route.params.id);
});
onBeforeMount(async () => {
await fetchArticleData(route.params.id);
});
this means it only runs on the client you're trying to populate data on the server you should use useFetch or useAsyncData as the data will be fetched server side
Elunes - Ahmad
Elunes - Ahmad5mo ago
Thank you for your reply, okay I will try
Want results from more Discord servers?
Add your server