From d3d755234d800145c9e4a9e24d6bf69f4e1359b6 Mon Sep 17 00:00:00 2001 From: skirtle <65301168+skirtles-code@users.noreply.github.com> Date: Mon, 24 Apr 2023 06:35:09 +0100 Subject: [PATCH] fix: remove nullish params --- packages/router/__tests__/router.spec.ts | 25 ++++++++++++++---------- packages/router/src/router.ts | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/router/__tests__/router.spec.ts b/packages/router/__tests__/router.spec.ts index 5b7ea7b29..df6b37146 100644 --- a/packages/router/__tests__/router.spec.ts +++ b/packages/router/__tests__/router.spec.ts @@ -297,20 +297,25 @@ describe('Router', () => { expect(router.currentRoute.value).toMatchObject({ params: { p: '0' } }) }) - it('casts null/undefined params to empty strings', async () => { + it('removes null/undefined params', async () => { const { router } = await newRouter() - expect( - router.resolve({ name: 'optional', params: { p: undefined } }) - ).toMatchObject({ - params: {}, + + const route1 = router.resolve({ + name: 'optional', + params: { p: undefined }, }) - expect( - router.resolve({ name: 'optional', params: { p: null } }) - ).toMatchObject({ - params: {}, + expect(route1.path).toBe('/optional') + expect(route1.params).toEqual({}) + + const route2 = router.resolve({ + name: 'optional', + params: { p: null }, }) + expect(route2.path).toBe('/optional') + expect(route2.params).toEqual({}) + await router.push({ name: 'optional', params: { p: null } }) - expect(router.currentRoute.value).toMatchObject({ params: {} }) + expect(router.currentRoute.value.params).toEqual({}) await router.push({ name: 'optional', params: {} }) }) diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index a74289854..575c0bb7b 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -491,7 +491,7 @@ export function createRouter(options: RouterOptions): Router { } // pass encoded values to the matcher, so it can produce encoded path and fullPath matcherLocation = assign({}, rawLocation, { - params: encodeParams(rawLocation.params), + params: encodeParams(targetParams), }) // current location params are decoded, we need to encode them in case the // matcher merges the params