Skip to content

Commit

Permalink
fix: prevent strategy no_prefix redirect detection locale change at…
Browse files Browse the repository at this point in the history
…tempt (#2505)
  • Loading branch information
BobbieGoede committed Oct 19, 2023
1 parent 1fc1f02 commit b4a5692
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions specs/fixtures/basic/pages/category/[slug].vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<template>
<p>This is cateory page on '{{ $route.params.slug }}'</p>
<NuxtLinkLocale id="return-home-link" to="/">Home</NuxtLinkLocale>
</template>
20 changes: 20 additions & 0 deletions specs/routing_strategies/no_prefix.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,24 @@ describe('strategy: no_prefix', async () => {
// current locale
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('fr')
})

test('(#2493) should navigate from url with and without trailing slash', async () => {
const page = await createPage()
await page.goto(url('/category/nested/'))
await page.waitForURL('**/category/nested/')

await page.locator('#return-home-link').click()

await page.waitForURL(/:[0-9]+\/$/)

expect(page.url()).toEqual(url('/'))

await page.goto(url('/category/nested'))
await page.waitForURL('**/category/nested')

await page.locator('#return-home-link').click()
await page.waitForURL(/:[0-9]+\/$/)

expect(page.url()).toEqual(url('/'))
})
})
2 changes: 1 addition & 1 deletion src/runtime/plugins/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export default defineNuxtPlugin({
route: { to, from },
context: nuxtContext,
targetLocale: locale,
routeLocaleGetter: getLocaleFromRoute,
routeLocaleGetter: nuxtI18nOptions.strategy === 'no_prefix' ? () => locale : getLocaleFromRoute,
nuxtI18nOptions,
calledWithRouting: true
})
Expand Down

0 comments on commit b4a5692

Please sign in to comment.