From: Eduardo San Martin Morote Date: Fri, 3 Apr 2020 09:44:25 +0000 (+0200) Subject: fix: check query and hash when navigating X-Git-Tag: v4.0.0-alpha.5~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3862ad924bbc734a835577c3a3c71bc3550db29c;p=thirdparty%2Fvuejs%2Frouter.git fix: check query and hash when navigating --- diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index 76593fbf..f32cbc4e 100644 --- a/__tests__/router.spec.ts +++ b/__tests__/router.spec.ts @@ -195,6 +195,22 @@ describe('Router', () => { expect(spy).toHaveBeenCalled() }) + it('navigates to same route record but different query', async () => { + const { router } = await newRouter() + await router.push('/?q=1') + expect(router.currentRoute.value.query).toEqual({ q: '1' }) + await router.push('/?q=2') + expect(router.currentRoute.value.query).toEqual({ q: '2' }) + }) + + it('navigates to same route record but different hash', async () => { + const { router } = await newRouter() + await router.push('/#one') + expect(router.currentRoute.value.hash).toBe('#one') + await router.push('/#two') + expect(router.currentRoute.value.hash).toBe('#two') + }) + describe('alias', () => { it('does not navigate to alias if already on original record', async () => { const { router } = await newRouter() @@ -484,8 +500,6 @@ describe('Router', () => { }) }) - // it('redirects with route record redirect') - describe('Dynamic Routing', () => { it('resolves new added routes', async () => { const { router } = await newRouter() diff --git a/src/router.ts b/src/router.ts index 07287deb..43f3745e 100644 --- a/src/router.ts +++ b/src/router.ts @@ -632,6 +632,7 @@ function extractChangingRecords( return [leavingRecords, updatingRecords, enteringRecords] } +// TODO: move to utils and test function isSameRouteLocation(a: RouteLocation, b: RouteLocation): boolean { let aLastIndex = a.matched.length - 1 let bLastIndex = b.matched.length - 1 @@ -640,6 +641,8 @@ function isSameRouteLocation(a: RouteLocation, b: RouteLocation): boolean { aLastIndex > -1 && aLastIndex === bLastIndex && isSameRouteRecord(a.matched[aLastIndex], b.matched[bLastIndex]) && - isSameLocationObject(a.params, b.params) + isSameLocationObject(a.params, b.params) && + isSameLocationObject(a.query, b.query) && + a.hash === b.hash ) }