I have been trying to implement SSR in Vue 3 with very good results. However, I have hit a complete roadblock with how to add SEO Tags. I have been using unhead for this purpose and it seems to load the title and tags fine once the page is loaded. However, the server does not seem to loading the tags. I am not sure where I am going wrong. So, please do help.
// main.ts
export const createApp = () => {
const app = createSSRApp(App)
const pinia = createPinia()
const head = createHead()
app.use(router)
app.use(pinia)
app.use(head as any)
return {
app,
pinia,
router,
head
}
}
// entry-server.ts
export async function render(url:string, manifest:any):Promise {
const { app, router, head } = createApp();
await router.push(url);
await router.isReady();
await head.resolveTags()
const payload = await renderSSRHead(head as any)
const ctx:any = {};
const html = await renderToString(app, ctx);
const preloadLinks = renderPreloadLinks(ctx.modules, manifest);
return [html, preloadLinks, payload];
}
EDIT:
Turns out, the issue was not with the SSR setup but I had not used useHead or useSEO in App.vue
Once I did, it started working fine.