Skip to content

Commit

Permalink
fix: incorrect SEO links when vue-loader forces local i18n instance (#…
Browse files Browse the repository at this point in the history
…786)

Resolves #785
  • Loading branch information
rchl authored Jul 3, 2020
1 parent 90fe8d4 commit 8cf173d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/templates/plugin.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions test/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
}

Expand Down

0 comments on commit 8cf173d

Please sign in to comment.