@vueuse/head not working properly
See original GitHub issueHello Thanks for this perfect library. It is amazing. I am working on this vue-router example and need to use vueuse/head package to manage titles dynamically but not made work it. Are there any configs etc. about this?
Here are my app.js
import { createSSRApp } from "vue";
import { createRouter } from "./router";
import { createStore } from "../store/store";
import { createHead } from "@vueuse/head";
export { createApp };
function createApp({ Page }) {
const app = createSSRApp(Page);
const router = createRouter();
const store = createStore();
const head = createHead();
app.use(store);
app.use(router);
app.use(head);
return { app, router, store, head };
}
all.page.server.js
import { renderToString } from "@vue/server-renderer";
import { html } from "vite-plugin-ssr";
import { createHead, renderHeadToString } from "@vueuse/head";
import { createApp } from "./app";
export { render };
export { addContextProps };
export { setPageProps };
async function render({ contextProps }) {
const { appHtml } = contextProps;
const head = createHead();
const { headTags, htmlAttrs, bodyAttrs } = renderHeadToString(head);
return html`<!DOCTYPE html>
<html>
<head>
${html.dangerouslySetHtml(headTags)}
</head>
<body>
<div id="app">${html.dangerouslySetHtml(appHtml)}</div>
</body>
</html>`;
}
async function addContextProps({ Page, contextProps }) {
const { app, store, router } = createApp({ Page });
await router.push(contextProps.url);
await router.isReady();
const appHtml = await renderToString(app);
const INITIAL_STATE = store.state;
return {
INITIAL_STATE,
appHtml,
};
}
function setPageProps({ contextProps }) {
const { INITIAL_STATE } = contextProps;
return { INITIAL_STATE };
}
About.vue component
<template>
<p>The count is preserved when switching between "Home" and "About".</p>
</template>
<script setup>
import { useHead } from "@vueuse/head";
useHead({
title: "My About Page",
});
</script>
I cant see my title in SSR rendered code.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
VueUse Head v1 release - Harlan Wilton
A few months ago I was decided to fix a quick bug on @vueuse/head. ... This one was pretty tedious, but well worth...
Read more >Vue-head not working in production
I have a little problem with my site when I put in production. well I installed the vue-head plugging in my site localhost...
Read more >VueUse Head and Netlify PreRendering for SEO and Social ...
Netlify Prerendering combined with VueUse head empowers Vue.js 3 SPAs to be SEO and social friendly with virtually no extra work.
Read more >@vueuse/head | Yarn - Package Manager
No unreleased changes. 1.0.22. fix: expose use function for plugins. 1.0.21. chore(deps): bump deps ...
Read more >Injecting into <head> in Vue.js - Stack Overflow
This isn't addressed in documentation because it's not Vue's job. ... then you can go for dynamic loading of JS script tag.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Had a deeper look, it seems to be a problem on
@vueuse/head
’s side. I’d open a ticket over there.@ozergul Try to use vuex on server and get data from component
I hope I helped you and understood the problem correctly