Skip to content

Commit 35b45a9

Browse files
authored
fix: warn when using SEO features without baseUrl (#3145)
1 parent c103d13 commit 35b45a9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/runtime/composables/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
22
import { useRequestHeaders, useCookie as useNuxtCookie } from '#imports'
3-
import { ref, computed, watch, onUnmounted } from 'vue'
3+
import { ref, computed, watch, onUnmounted, unref } from 'vue'
44
import { parseAcceptLanguage, wrapComposable, runtimeDetectBrowserLanguage } from '../internal'
55
import { DEFAULT_DYNAMIC_PARAMS_KEY, localeCodes, normalizedLocales } from '#build/i18n.options.mjs'
66
import { getActiveHead } from 'unhead'
@@ -80,6 +80,10 @@ export function useSetI18nParams(seo?: SeoAttributesOptions): SetI18nParamsFunct
8080
const currentLocale = getNormalizedLocales(locales).find(l => l.code === locale) || { code: locale }
8181
const currentLocaleLanguage = currentLocale.language
8282

83+
if (!unref(i18n.baseUrl)) {
84+
console.warn('I18n `baseUrl` is required to generate valid SEO tag links.')
85+
}
86+
8387
const setMeta = () => {
8488
const metaObject: HeadParam = {
8589
link: [],

src/runtime/routing/compatibles/head.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ export function localeHead(
3333
meta: []
3434
}
3535

36+
const i18nBaseUrl = unref(i18n.baseUrl)
37+
if (!i18nBaseUrl) {
38+
console.warn('I18n `baseUrl` is required to generate valid SEO tag links.')
39+
}
40+
3641
// skip if no locales or baseUrl is set
37-
if (unref(i18n.locales) == null || unref(i18n.baseUrl) == null) {
42+
if (unref(i18n.locales) == null || i18nBaseUrl == null) {
3843
return metaObject
3944
}
4045

0 commit comments

Comments
 (0)