Skip to content

Commit

Permalink
fix: resolveRoute losing query parameters for string routes (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede committed Aug 11, 2023
1 parent a16ce1b commit 90f942b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/vue-i18n-routing/src/__test__/compatibles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ describe('localePath', () => {
assert.equal(vm.localePath({ path: '/', query: { foo: 1 } }), '/ja?foo=1')
assert.equal(vm.localePath({ name: 'about', query: { foo: 1 } }), '/ja/about?foo=1')
assert.equal(vm.localePath({ path: '/about', query: { foo: 1 } }), '/ja/about?foo=1')
assert.equal(vm.localePath('/?foo=1'), '/ja?foo=1')
assert.equal(vm.localePath('/about?foo=1'), '/ja/about?foo=1')
assert.equal(vm.localePath('/about?foo=1&test=2'), '/ja/about?foo=1&test=2')

// no define path
assert.equal(vm.localePath('/vue-i18n'), '/ja/vue-i18n')
Expand Down Expand Up @@ -420,6 +423,11 @@ describe('switchLocalePath', () => {
assert.equal(vm.switchLocalePath('fr'), '/fr/about')
assert.equal(vm.switchLocalePath('vue-i18n'), '')

await router.push('/ja/about?foo=1&test=2')
assert.equal(vm.switchLocalePath('ja'), '/ja/about?foo=1&test=2')
assert.equal(vm.switchLocalePath('fr'), '/fr/about?foo=1&test=2')
assert.equal(vm.switchLocalePath('en'), '/en/about?foo=1&test=2')

await router.push('/ja/category/1')
assert.equal(vm.switchLocalePath('ja'), '/ja/category/japanese')
assert.equal(vm.switchLocalePath('en'), '/en/category/english')
Expand Down
4 changes: 3 additions & 1 deletion packages/vue-i18n-routing/src/compatibles/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ export function resolveRoute(this: RoutingProxy, route: any, locale?: Locale): a
if (isString(route)) {
if (_route[0] === '/') {
// if route parameter is a path, create route object with path.
_route = { path: route }
const [path, search] = route.split('?')
const query = Object.fromEntries(new URLSearchParams(search))
_route = { path, query }
} else {
// else use it as route name.
_route = { name: route }
Expand Down

0 comments on commit 90f942b

Please sign in to comment.