diff --git a/src/util/route.js b/src/util/route.js index e18fb5e36..9fee9c099 100644 --- a/src/util/route.js +++ b/src/util/route.js @@ -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 { diff --git a/test/unit/specs/route.spec.js b/test/unit/specs/route.spec.js index b9c864e5f..e15f550f4 100644 --- a/test/unit/specs/route.spec.js +++ b/test/unit/specs/route.spec.js @@ -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', () => {