Skip to content

Commit

Permalink
fix: change route on setLocale (#2511)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede committed Oct 20, 2023
1 parent d485f7f commit 7454a4c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions specs/fixtures/basic/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ watchEffect(() => {
refresh()
})
useHead({
useHead(() => ({
title: t('home'),
htmlAttrs: {
lang: i18nHead.value.htmlAttrs!.lang,
dir: i18nHead.value.htmlAttrs!.dir
},
link: [...(i18nHead.value.link || [])],
meta: [...(i18nHead.value.meta || [])]
})
}))
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion specs/issues/2288.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('#2288', async () => {
})

// TODO: Fix setLocale
test.fails('change route with setLocale', async () => {
test('change route with setLocale', async () => {
const home = url('/')
const page = await createPage()
await page.goto(home)
Expand Down
6 changes: 4 additions & 2 deletions specs/routing_strategies/prefix_and_default.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ describe('strategy: prefix_and_default', async () => {
expect(res!.status()).toBe(404) // eslint-disable-line @typescript-eslint/no-non-null-assertion
})

// TODO: Fix setLocale
test.fails('reactivity', async () => {
test('reactivity', async () => {
const { page } = await renderPage('/')

// click `fr` lang switch link with NuxtLink
Expand All @@ -119,8 +118,11 @@ describe('strategy: prefix_and_default', async () => {
// click `en` and `fr` lang switch link with setLocale
await page.locator('#set-locale-link-en').click()
await waitForURL(page, '/')
expect(await getText(page, 'title')).toEqual('Homepage')

await page.locator('#set-locale-link-fr').click()
await waitForURL(page, '/fr')
expect(await getText(page, 'title')).toEqual('Accueil')

// navigation URL
expect(await page.url()).toEqual(url('/fr'))
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export function detectRedirect<Context extends NuxtApp = NuxtApp>({
if (
!isStaticGenerate &&
!differentDomains &&
(calledWithRouting || (strategy !== 'no_prefix' && strategy !== 'prefix_and_default')) &&
(calledWithRouting || strategy !== 'no_prefix') &&
routeLocaleGetter(route.to) !== targetLocale
) {
// the current route could be 404 in which case attempt to find matching route using the full path
Expand Down

0 comments on commit 7454a4c

Please sign in to comment.