diff --git a/src/templates/plugin.main.js b/src/templates/plugin.main.js index b2ec77deb..b7f8d91c7 100644 --- a/src/templates/plugin.main.js +++ b/src/templates/plugin.main.js @@ -200,6 +200,7 @@ export default async (context) => { i18n.setLocaleCookie = locale => setLocaleCookie(locale, res, { useCookie, cookieDomain, cookieKey }) i18n.getLocaleCookie = () => getLocaleCookie(req, { useCookie, cookieKey, localeCodes }) i18n.setLocale = (locale) => loadAndSetLocale(locale) + i18n.__baseUrl = app.i18n.__baseUrl } // Set instance options diff --git a/test/module.test.js b/test/module.test.js index 1e52bb7d2..5a5fa1a72 100644 --- a/test/module.test.js +++ b/test/module.test.js @@ -428,6 +428,45 @@ for (const trailingSlash of TRAILING_SLASHES) { } ]) }) + + test('baseUrl is set correctly in component local i18n instance', async () => { + const html = await getRespectingTrailingSlash('/loader-yaml') + const dom = getDom(html) + const seoTags = getSeoTags(dom) + + const expectedSeoTags = [ + { + tagName: 'meta', + property: 'og:locale', + content: 'en' + }, + { + tagName: 'meta', + property: 'og:locale:alternate', + content: 'fr_FR' + }, + { + tagName: 'link', + rel: 'alternate', + href: pathRespectingTrailingSlash('nuxt-app.localhost/loader-yaml'), + hreflang: 'en' + }, + { + tagName: 'link', + rel: 'alternate', + href: pathRespectingTrailingSlash('nuxt-app.localhost/fr/loader-yaml'), + hreflang: 'fr' + }, + { + tagName: 'link', + rel: 'alternate', + href: pathRespectingTrailingSlash('nuxt-app.localhost/fr/loader-yaml'), + hreflang: 'fr-FR' + } + ] + + expect(seoTags).toEqual(expectedSeoTags) + }) }) }