Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: warn when using SEO features without baseUrl #3145

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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