diff --git a/docs/content/2.guide/2.features/4.head-management.md b/docs/content/2.guide/2.features/4.head-management.md index 7cba23c8f94..cbeca416f0c 100644 --- a/docs/content/2.guide/2.features/4.head-management.md +++ b/docs/content/2.guide/2.features/4.head-management.md @@ -47,7 +47,7 @@ The `titleTemplate` can either be a string, where `%s` is replaced with the titl ``` -Now, if you set the title to `My Page` with `useHead` on another page of your site, the title would appear as 'My Page - Site Title' in the browser tab. You could also pass `undefined` to default to the site title. +Now, if you set the title to `My Page` with `useHead` on another page of your site, the title would appear as 'My Page - Site Title' in the browser tab. You could also pass `null` to default to the site title. ## Meta Components diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index cb67b51cc74..8c3c690846c 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -38,7 +38,7 @@ "@nuxt/vite-builder": "^3.0.0-rc.6", "@vue/reactivity": "^3.2.37", "@vue/shared": "^3.2.37", - "@vueuse/head": "^0.7.8", + "@vueuse/head": "^0.7.9", "chokidar": "^3.5.3", "cookie-es": "^0.5.0", "defu": "^6.0.0", diff --git a/packages/nuxt/src/head/runtime/lib/vueuse-head.plugin.ts b/packages/nuxt/src/head/runtime/lib/vueuse-head.plugin.ts index 0e3bb809bfa..224a3facef0 100644 --- a/packages/nuxt/src/head/runtime/lib/vueuse-head.plugin.ts +++ b/packages/nuxt/src/head/runtime/lib/vueuse-head.plugin.ts @@ -25,8 +25,9 @@ export default defineNuxtPlugin((nuxtApp) => { const headObj = computed(() => { const overrides: MetaObject = { meta: [] } - if (titleTemplate.value && 'title' in meta.value) { - overrides.title = typeof titleTemplate.value === 'function' ? titleTemplate.value(meta.value.title) : titleTemplate.value.replace(/%s/g, meta.value.title) + // cast a null titleTemplate to an empty string so @vueuse/head ignores it + if (titleTemplate.value === null) { + overrides.titleTemplate = '' } if (meta.value.charset) { overrides.meta!.push({ key: 'charset', charset: meta.value.charset }) diff --git a/test/basic.test.ts b/test/basic.test.ts index 9b6bb232d3e..524676238a9 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -131,21 +131,21 @@ describe('pages', () => { describe('head tags', () => { it('should render tags', async () => { - const html = await $fetch('/head') - expect(html).toContain('