Skip to content

Commit

Permalink
fix: NO_PREFIX - localePath with path returns route with prefix
Browse files Browse the repository at this point in the history
The case that was wrong was when calling `localePath` with
`{ path: '/about' }` argument when strategy was NO_PREFIX. Code
has prefixed result with a locale while it never should.

Case when passing component name to `localePath` was not affected
by the bug.

Resolves #457
  • Loading branch information
rchl committed Sep 18, 2019
1 parent c70e061 commit 4d4186c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/plugins/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function localePathFactory (i18nPath, routerPath) {
// don't prefix default locale
!(locale === defaultLocale && strategy === STRATEGIES.PREFIX_EXCEPT_DEFAULT) &&
// no prefix for any language
!(strategy === STRATEGIES.NO_REFIX) &&
!(strategy === STRATEGIES.NO_PREFIX) &&
// no prefix for different domains
!i18n.differentDomains
)
Expand Down
10 changes: 6 additions & 4 deletions test/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ describe('basic', () => {

test('localePath returns correct path', async () => {
const window = await nuxt.renderAndGetWindow(url('/'))
const newRoute = window.$nuxt.localePath('about')
expect(newRoute).toBe('/about-us')
expect(window.$nuxt.localePath('about')).toBe('/about-us')
expect(window.$nuxt.localePath('about', 'fr')).toBe('/fr/a-propos')
expect(window.$nuxt.localePath({ path: '/about' })).toBe('/about-us')
expect(window.$nuxt.localePath({ path: '/about/' })).toBe('/about-us')
})

test('redirects to existing route', async () => {
Expand Down Expand Up @@ -266,8 +268,8 @@ describe('no_prefix strategy', () => {

test('localePath returns correct path', async () => {
const window = await nuxt.renderAndGetWindow(url('/'))
const newRoute = window.$nuxt.localePath('about')
expect(newRoute).toBe('/about')
expect(window.$nuxt.localePath('about')).toBe('/about')
expect(window.$nuxt.localePath({ path: '/about' })).toBe('/about')
})

test('localePath with non-current locale triggers warning', async () => {
Expand Down

0 comments on commit 4d4186c

Please sign in to comment.