Skip to content

Commit

Permalink
fix(routing): resolve localePath with fullPath instead of href
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnvh authored and paulgv committed Jul 20, 2019
1 parent 76c9978 commit b827681
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/plugins/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,8 @@ function localePathFactory (i18nPath, routerPath) {

// Resolve localized route
const router = this[routerPath]
const resolved = router.resolve(localizedRoute)
let { href } = resolved

// Remove baseUrl from href (will be added back by nuxt-link)
if (router.options.base) {
const regexp = new RegExp(router.options.base)
href = href.replace(regexp, '/')
}

return href
const { route: { fullPath } } = router.resolve(localizedRoute)
return fullPath
}
}

Expand Down
30 changes: 30 additions & 0 deletions test/fixtures/basic/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,34 @@ describe('basic', () => {
const html = await get('/fr/imbrication-dynamique/1/2/3')
expect(cleanUpScripts(html)).toMatchSnapshot()
})

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

describe('hash mode', () => {
let nuxt

beforeAll(async () => {
config.router = {
mode: 'hash'
}

nuxt = new Nuxt(config)
await new Builder(nuxt).build()
await nuxt.listen(process.env.PORT)
})

afterAll(async () => {
await nuxt.close()
})

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

0 comments on commit b827681

Please sign in to comment.