From b78aa98792e86e08b76eb879e496fe1c300c1e18 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 18 Apr 2024 11:55:53 +0200 Subject: [PATCH 1/2] fix: Revert "fix: avoid normalizing the fullPath (#2189)" This reverts commit c54fc8407bd1944a3b724fbcc7f6fbac5ff45f0f. Fix vuejs/router#2216 --- packages/router/__tests__/router.spec.ts | 24 +++++++++++++++--------- packages/router/src/router.ts | 20 +++++++------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/router/__tests__/router.spec.ts b/packages/router/__tests__/router.spec.ts index 3d86e1743..bd6b186e0 100644 --- a/packages/router/__tests__/router.spec.ts +++ b/packages/router/__tests__/router.spec.ts @@ -534,16 +534,22 @@ describe('Router', () => { }) }) - // https://github.com/vuejs/router/issues/2187 - it('keeps a consistent value on fullPath when resolving', async () => { + it('should be able to resolve a partially updated location', async () => { const { router } = await newRouter() - const targetLoc = '/search#/?redirect=%2F%3Fid%3D1%23%2Fabc' - expect(router.resolve(targetLoc).fullPath).toBe(targetLoc) - await router.push(targetLoc) - expect(router.currentRoute.value.fullPath).toBe(targetLoc) - await router.push('/') - await router.replace(targetLoc) - expect(router.currentRoute.value.fullPath).toBe(targetLoc) + expect( + router.resolve({ + // spread the current location + ...router.currentRoute.value, + // then update some stuff, creating inconsistencies, + query: { a: '1' }, + hash: '#a', + }) + ).toMatchObject({ + query: { a: '1' }, + path: '/', + fullPath: '/?a=1#a', + hash: '#a', + }) }) describe('navigation cancelled', () => { diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index dcf3369d6..20ab4d1e2 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -525,19 +525,13 @@ export function createRouter(options: RouterOptions): Router { // we need to run the decoding again matchedRoute.params = normalizeParams(decodeParams(matchedRoute.params)) - const fullPath = - // @ts-expect-error: the rawLocation doesn't normally have a fullPath - // but sometimes it gets noramlized before being passed to resolve and we can - // resue it to avoid encoding an unencoded path from the user in order to be closer - // to the URL constructor behavior. vuejs/router#2187 - rawLocation.fullPath || - stringifyURL( - stringifyQuery, - assign({}, rawLocation, { - hash: encodeHash(hash), - path: matchedRoute.path, - }) - ) + const fullPath = stringifyURL( + stringifyQuery, + assign({}, rawLocation, { + hash: encodeHash(hash), + path: matchedRoute.path, + }) + ) const href = routerHistory.createHref(fullPath) if (__DEV__) { From 960662db6497011b51a5dec729befd26fcee305a Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 18 Apr 2024 12:00:34 +0200 Subject: [PATCH 2/2] release: vue-router@4.3.2 --- packages/router/CHANGELOG.md | 6 ++++++ packages/router/package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/router/CHANGELOG.md b/packages/router/CHANGELOG.md index 99b60b040..d66bd41dd 100644 --- a/packages/router/CHANGELOG.md +++ b/packages/router/CHANGELOG.md @@ -1,3 +1,9 @@ +## [4.3.2](https://github.com/vuejs/router/compare/v4.3.1...v4.3.2) (2024-04-18) + +### Bug Fixes + +- Revert "fix: avoid normalizing the fullPath ([#2189](https://github.com/vuejs/router/issues/2189))" ([b78aa98](https://github.com/vuejs/router/commit/b78aa98792e86e08b76eb879e496fe1c300c1e18)), closes [vuejs/router#2216](https://github.com/vuejs/router/issues/2216). This was creating other bugs when reusing a normalized location (common pattern). The original issue wasn't a problem in practice as the consistent values are the query, params, and hash. + ## [4.3.1](https://github.com/vuejs/router/compare/v4.3.0...v4.3.1) (2024-04-17) ### Bug Fixes diff --git a/packages/router/package.json b/packages/router/package.json index b6f3604a0..f6af92949 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -1,6 +1,6 @@ { "name": "vue-router", - "version": "4.3.1", + "version": "4.3.2", "main": "index.js", "unpkg": "dist/vue-router.global.js", "jsdelivr": "dist/vue-router.global.js",