Skip to content

Commit fd2fb67

Browse files
posvayyx990803
authored andcommitted
Fix nested object comparison for queries (#1425)
Fix #1421
1 parent 27247b7 commit fd2fb67

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/util/route.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,15 @@ function isObjectEqual (a = {}, b = {}): boolean {
7979
if (aKeys.length !== bKeys.length) {
8080
return false
8181
}
82-
return aKeys.every(key => String(a[key]) === String(b[key]))
82+
return aKeys.every(key => {
83+
const aVal = a[key]
84+
const bVal = b[key]
85+
// check nested equality
86+
if (typeof aVal === 'object' && typeof bVal === 'object') {
87+
return isObjectEqual(aVal, bVal)
88+
}
89+
return String(aVal) === String(bVal)
90+
})
8391
}
8492

8593
export function isIncludedRoute (current: Route, target: Route): boolean {

test/unit/specs/route.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ describe('Route utils', () => {
3030
}
3131
expect(isSameRoute(a, b)).toBe(true)
3232
})
33+
34+
it('nested query', () => {
35+
const a = {
36+
path: '/abc',
37+
query: { foo: { bar: 'bar' }, arr: [1, 2] }
38+
}
39+
const b = {
40+
path: '/abc',
41+
query: { arr: [1, 2], foo: { bar: 'bar' } }
42+
}
43+
const c = {
44+
path: '/abc',
45+
query: { arr: [1, 2], foo: { bar: 'not bar' } }
46+
}
47+
expect(isSameRoute(a, b)).toBe(true)
48+
expect(isSameRoute(a, c)).toBe(false)
49+
})
3350
})
3451

3552
describe('isIncludedRoute', () => {

0 commit comments

Comments
 (0)