Skip to content

Commit 90f942b

Browse files
authored
fix: resolveRoute losing query parameters for string routes (#43)
1 parent a16ce1b commit 90f942b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/vue-i18n-routing/src/__test__/compatibles.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ describe('localePath', () => {
103103
assert.equal(vm.localePath({ path: '/', query: { foo: 1 } }), '/ja?foo=1')
104104
assert.equal(vm.localePath({ name: 'about', query: { foo: 1 } }), '/ja/about?foo=1')
105105
assert.equal(vm.localePath({ path: '/about', query: { foo: 1 } }), '/ja/about?foo=1')
106+
assert.equal(vm.localePath('/?foo=1'), '/ja?foo=1')
107+
assert.equal(vm.localePath('/about?foo=1'), '/ja/about?foo=1')
108+
assert.equal(vm.localePath('/about?foo=1&test=2'), '/ja/about?foo=1&test=2')
106109

107110
// no define path
108111
assert.equal(vm.localePath('/vue-i18n'), '/ja/vue-i18n')
@@ -420,6 +423,11 @@ describe('switchLocalePath', () => {
420423
assert.equal(vm.switchLocalePath('fr'), '/fr/about')
421424
assert.equal(vm.switchLocalePath('vue-i18n'), '')
422425

426+
await router.push('/ja/about?foo=1&test=2')
427+
assert.equal(vm.switchLocalePath('ja'), '/ja/about?foo=1&test=2')
428+
assert.equal(vm.switchLocalePath('fr'), '/fr/about?foo=1&test=2')
429+
assert.equal(vm.switchLocalePath('en'), '/en/about?foo=1&test=2')
430+
423431
await router.push('/ja/category/1')
424432
assert.equal(vm.switchLocalePath('ja'), '/ja/category/japanese')
425433
assert.equal(vm.switchLocalePath('en'), '/en/category/english')

packages/vue-i18n-routing/src/compatibles/routing.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ export function resolveRoute(this: RoutingProxy, route: any, locale?: Locale): a
165165
if (isString(route)) {
166166
if (_route[0] === '/') {
167167
// if route parameter is a path, create route object with path.
168-
_route = { path: route }
168+
const [path, search] = route.split('?')
169+
const query = Object.fromEntries(new URLSearchParams(search))
170+
_route = { path, query }
169171
} else {
170172
// else use it as route name.
171173
_route = { name: route }

0 commit comments

Comments
 (0)