question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot set title with useHead

See original GitHub issue

Environment

  • Operating System: macOS
  • Node Version: v16.15.0
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: pnpm@7.1.7
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Describe the bug

head-management#example-usage-with-definepagemeta

Followed the example in the documentation, but the title is still localhost:3000/some-page.

Additional context

~/layouts/default.vue

<script setup>
	const route = useRoute()
	useHead({
		meta: [{ name: 'og:title', content: `App Name - ${route.meta.title}` }]
	})
</script>

<template>
	<div>
		<div>default</div>
		<slot></slot>
	</div>
</template>

~/pages/some-page.vue

<script setup>
	definePageMeta({
		title: 'Some Page'
	})
</script>

<template>
	<div>some-page</div>
</template>

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Jun 6, 2022

@danielroe Here is the reproduction ashgo-x/nuxt-app.

0reactions
danielroecommented, Jun 8, 2022

Apologies, that was my mistake. It should be:

<script setup>
const route = useRoute();
useHead({
  meta: [
    {
      name: 'og:title',
      content: computed(() => `App Name - ${route.meta.title}`),
    },
  ],
});
</script>

https://stackblitz.com/edit/github-wurrmm?file=layouts%2Fdefault.vue,pages%2Fsome-page.vue

Read more comments on GitHub >

github_iconTop Results From Across the Web

vuejs3, cannot add dynamic title and description with usehead ...
I have been trying to use Vuejs3 useHead package and add dynamic title and decription meta, but i get $route is undefined.... i...
Read more >
[Feature Request] Handle titleTemplate like vue-meta #22
Hi, It could be really cool to have a titleTemplate like vue-meta, to be able to set a part of title for each...
Read more >
Setting Page Titles in Nuxt 3 - Server Side Up
When migrating an app from Nuxt 2 to Nuxt 3, setting page titles is done slightly different. Here's how to add page titles...
Read more >
vuejs3, cannot add dynamic title and description with usehead ...
Coding example for the question vuejs3, cannot add dynamic title and description with usehead meta package-Vue.js.
Read more >
useTitle - VueUse
Set initial title immediately: ... Observe `document.title` changes using MutationObserve * Cannot be used together with `titleTemplate` option.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found