Skip to content

Commit

Permalink
fix: don't skip the cookie if no locale is detected in the route (#1235)
Browse files Browse the repository at this point in the history
  • Loading branch information
strebl committed Jul 21, 2021
1 parent 9fcebda commit 6c9b48f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/templates/plugin.main.js
Expand Up @@ -395,11 +395,13 @@ export default async (context) => {
} else if (options.strategy !== Constants.STRATEGIES.NO_PREFIX) {
const routeLocale = getLocaleFromRoute(route)
finalLocale = routeLocale
} else if (useCookie) {
finalLocale = app.i18n.getLocaleCookie()
}
}

if (!finalLocale && useCookie) {
finalLocale = app.i18n.getLocaleCookie()
}

if (!finalLocale) {
finalLocale = app.i18n.defaultLocale || ''
}
Expand Down
14 changes: 14 additions & 0 deletions test/browser.test.js
Expand Up @@ -1260,6 +1260,20 @@ describe(`${browserString} (onlyOnRoot + prefix)`, () => {
expect(await (await page.$('body'))?.textContent()).toContain('locale: en')
expect(await getRouteFullPath(page)).toBe('/en')
})

test('uses saved locale cookie when redirecting from root', async () => {
const page = await browser.newPage({ locale: 'fr' })

// Ensure the detected locale cookie is saved
await page.goto(url('/fr'))
expect(await (await page.$('body'))?.textContent()).toContain('locale: fr')
expect(await getRouteFullPath(page)).toBe('/fr')

// Verify that we navigate to saved locale
await page.goto(url('/'))
expect(await (await page.$('body'))?.textContent()).toContain('locale: fr')
expect(await getRouteFullPath(page)).toBe('/fr')
})
})

describe(`${browserString} (vuex disabled)`, () => {
Expand Down

0 comments on commit 6c9b48f

Please sign in to comment.