]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix: check query and hash when navigating
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 3 Apr 2020 09:44:25 +0000 (11:44 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 3 Apr 2020 09:44:25 +0000 (11:44 +0200)
__tests__/router.spec.ts
src/router.ts

index 76593fbf44deefd5a49e0a6632af19f513c4f8b2..f32cbc4e9f474032afde84259605f10cc6f247fb 100644 (file)
@@ -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()
index 07287deb6f1fa375435c54731c0118cbf6aafbf5..43f3745e2787edfd381fca1150f48ae3fb1d39f1 100644 (file)
@@ -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
   )
 }