Skip to content

fix: route resolve loses query parameters #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/vue-i18n-routing/src/__test__/compatibles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ describe('localePath', () => {
assert.equal(vm.localePath({ state: { foo: 1 } }), '/en')
await router.push('/ja')
assert.equal(vm.localePath({ state: { foo: 1 } }), '/ja')

// preserve query parameters
assert.equal(vm.localePath({ query: { foo: 1 } }), '/ja?foo=1')
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')

// no define path
assert.equal(vm.localePath('/vue-i18n'), '/ja/vue-i18n')
// no define name
Expand Down
6 changes: 3 additions & 3 deletions packages/vue-i18n-routing/src/compatibles/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export function resolve(router: Router | VueRouter, route: any, strategy: Strate
if (_route == null) {
return route
} else {
const _resolevableRoute = assign({}, _route)
_resolevableRoute.path = targetPath
return router.resolve(_resolevableRoute)
const _resolvableRoute = assign({}, route, _route)
_resolvableRoute.path = targetPath
return router.resolve(_resolvableRoute)
}
} else {
return router.resolve(route)
Expand Down