Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/util/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ function isObjectEqual (a = {}, b = {}): boolean {
if (aKeys.length !== bKeys.length) {
return false
}
return aKeys.every(key => String(a[key]) === String(b[key]))
return aKeys.every(key => {
const aVal = a[key]
const bVal = b[key]
// check nested equality
if (typeof aVal === 'object' && typeof bVal === 'object') {
return isObjectEqual(aVal, bVal)
}
return String(aVal) === String(bVal)
})
}

export function isIncludedRoute (current: Route, target: Route): boolean {
Expand Down
17 changes: 17 additions & 0 deletions test/unit/specs/route.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ describe('Route utils', () => {
}
expect(isSameRoute(a, b)).toBe(true)
})

it('nested query', () => {
const a = {
path: '/abc',
query: { foo: { bar: 'bar' }, arr: [1, 2] }
}
const b = {
path: '/abc',
query: { arr: [1, 2], foo: { bar: 'bar' } }
}
const c = {
path: '/abc',
query: { arr: [1, 2], foo: { bar: 'not bar' } }
}
expect(isSameRoute(a, b)).toBe(true)
expect(isSameRoute(a, c)).toBe(false)
})
})

describe('isIncludedRoute', () => {
Expand Down