#DocumentHead meta tag dynamic

5 messages · Page 1 of 1 (latest)

fallow whale
#

Is it possible to write into DocumentHead meta tag dynamic data from a fetch?

hexed wyvern
#

Yes 🙂

In your layout you export a DocumentHead outside the component and if you add resolveValue as a parameter you can then use this to get hold a a routeLoader which gives you access to any data from a fetch example....

#

// Get hold of the tour loader
const tourDetailsLoaderResponse = resolveValue(useTourDetailsPageLoader)

// Take data from the fetch response
const tourMetaTitle = tourDetailsLoaderResponse.metaTitle
const tourMetaDesc = tourDetailsLoaderResponse.metaTDesc

// Return the dynamic head data
 return {
title:tourMetaTitle,
        meta: [
            {
                name: 'robots',
                content: '{someValue}'
            },
            {
                name: 'description',
                content: tourMetaDesc 
            }
   ]

}

}```
#

Sorry I couldn't work out how to change the message to be code format

sage orchid