Skip to content

Commit

Permalink
fix: warn when using SEO features without baseUrl (#3145)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Sep 30, 2024
1 parent c103d13 commit 35b45a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
import { useRequestHeaders, useCookie as useNuxtCookie } from '#imports'
import { ref, computed, watch, onUnmounted } from 'vue'
import { ref, computed, watch, onUnmounted, unref } from 'vue'
import { parseAcceptLanguage, wrapComposable, runtimeDetectBrowserLanguage } from '../internal'
import { DEFAULT_DYNAMIC_PARAMS_KEY, localeCodes, normalizedLocales } from '#build/i18n.options.mjs'
import { getActiveHead } from 'unhead'
Expand Down Expand Up @@ -80,6 +80,10 @@ export function useSetI18nParams(seo?: SeoAttributesOptions): SetI18nParamsFunct
const currentLocale = getNormalizedLocales(locales).find(l => l.code === locale) || { code: locale }
const currentLocaleLanguage = currentLocale.language

if (!unref(i18n.baseUrl)) {
console.warn('I18n `baseUrl` is required to generate valid SEO tag links.')
}

const setMeta = () => {
const metaObject: HeadParam = {
link: [],
Expand Down
7 changes: 6 additions & 1 deletion src/runtime/routing/compatibles/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ export function localeHead(
meta: []
}

const i18nBaseUrl = unref(i18n.baseUrl)
if (!i18nBaseUrl) {
console.warn('I18n `baseUrl` is required to generate valid SEO tag links.')
}

// skip if no locales or baseUrl is set
if (unref(i18n.locales) == null || unref(i18n.baseUrl) == null) {
if (unref(i18n.locales) == null || i18nBaseUrl == null) {
return metaObject
}

Expand Down

0 comments on commit 35b45a9

Please sign in to comment.