Skip to content

Commit 8d02b27

Browse files
authored
fix: Unhead v2 compatibility (#3379)
1 parent c5ee506 commit 8d02b27

1 file changed

Lines changed: 10 additions & 22 deletions

File tree

src/runtime/composables/index.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useRequestHeaders, useCookie as useNuxtCookie } from '#imports'
22
import { ref, computed, watch, onUnmounted } from 'vue'
33
import { parseAcceptLanguage, wrapComposable, runtimeDetectBrowserLanguage } from '../internal'
44
import { DEFAULT_DYNAMIC_PARAMS_KEY, localeCodes, normalizedLocales } from '#build/i18n.options.mjs'
5-
import { getActiveHead } from 'unhead'
5+
import { useHead } from '#imports'
66
import { initCommonComposableOptions } from '../utils'
77
import {
88
creatHeadContext,
@@ -20,7 +20,6 @@ import type { Ref } from 'vue'
2020
import type { Locale } from 'vue-i18n'
2121
import type { resolveRoute } from '../routing/routing'
2222
import type { I18nHeadMetaInfo, I18nHeadOptions, SeoAttributesOptions } from '#internal-i18n-types'
23-
import type { HeadParam } from '../utils'
2423
import type { RouteLocationAsRelativeI18n, RouteLocationRaw, RouteLocationResolvedI18n, RouteMapI18n } from 'vue-router'
2524

2625
export * from 'vue-i18n'
@@ -42,7 +41,7 @@ export type SetI18nParamsFunction = (params: Partial<Record<Locale, unknown>>) =
4241
*/
4342
export function useSetI18nParams(seo?: SeoAttributesOptions): SetI18nParamsFunction {
4443
const common = initCommonComposableOptions()
45-
const head = getActiveHead()
44+
const head = useHead({})
4645
const router = common.router
4746

4847
// @ts-expect-error accepts more
@@ -80,28 +79,17 @@ export function useSetI18nParams(seo?: SeoAttributesOptions): SetI18nParamsFunct
8079
}
8180

8281
const setMeta = () => {
83-
const metaObject: HeadParam = {
84-
link: [],
85-
meta: []
82+
// Reset SEO Meta
83+
if (!ctx.locale || !ctx.locales) {
84+
head?.patch({})
85+
return
8686
}
8787

8888
// Adding SEO Meta
89-
if (ctx.locale && ctx.locales) {
90-
// prettier-ignore
91-
metaObject.link.push(
92-
...getHreflangLinks(common, ctx),
93-
...getCanonicalLink(common, ctx)
94-
)
95-
96-
// prettier-ignore
97-
metaObject.meta.push(
98-
...getOgUrl(common, ctx),
99-
...getCurrentOgLocale(ctx),
100-
...getAlternateOgLocales(ctx)
101-
)
102-
}
103-
104-
head?.push(metaObject)
89+
head?.patch({
90+
link: [...getHreflangLinks(common, ctx), ...getCanonicalLink(common, ctx)],
91+
meta: [...getOgUrl(common, ctx), ...getCurrentOgLocale(ctx), ...getAlternateOgLocales(ctx)]
92+
})
10593
}
10694

10795
return function (params: Partial<Record<Locale, unknown>>) {

0 commit comments

Comments
 (0)