diff --git a/src/navigation-instruction.js b/src/navigation-instruction.js index f9f0a11f..15e209d3 100644 --- a/src/navigation-instruction.js +++ b/src/navigation-instruction.js @@ -6,7 +6,8 @@ interface NavigationInstructionInit { config: RouteConfig, parentInstruction: NavigationInstruction, previousInstruction: NavigationInstruction, - router: Router + router: Router, + options: Object } export class CommitChangesStep { @@ -64,6 +65,8 @@ export class NavigationInstruction { plan: Object = null; + options: Object = {}; + constructor(init: NavigationInstructionInit) { Object.assign(this, init); diff --git a/src/navigation-plan.js b/src/navigation-plan.js index 0939a98e..fe91f952 100644 --- a/src/navigation-plan.js +++ b/src/navigation-plan.js @@ -121,6 +121,24 @@ function hasDifferentParameterValues(prev: NavigationInstruction, next: Navigati } } + if (!next.options.compareQueryParams) { + return false; + } + + let prevQueryParams = prev.queryParams; + let nextQueryParams = next.queryParams; + for (let key in nextQueryParams) { + if (prevQueryParams[key] !== nextQueryParams[key]) { + return true; + } + } + + for (let key in prevQueryParams) { + if (prevQueryParams[key] !== nextQueryParams[key]) { + return true; + } + } + return false; } diff --git a/src/router.js b/src/router.js index 230a91a7..bb336d15 100644 --- a/src/router.js +++ b/src/router.js @@ -51,6 +51,8 @@ export class Router { */ parent: Router = null; + options: Object = {}; + /** * @param container The [[Container]] to use when child routers. * @param history The [[History]] implementation to delegate navigation requests to. @@ -369,7 +371,10 @@ export class Router { config: null, parentInstruction, previousInstruction: this.currentInstruction, - router: this + router: this, + options: { + compareQueryParams: this.options.compareQueryParams + } }; if (results && results.length) { diff --git a/test/navigation-plan.spec.js b/test/navigation-plan.spec.js index d56d0879..6f81660d 100644 --- a/test/navigation-plan.spec.js +++ b/test/navigation-plan.spec.js @@ -141,5 +141,19 @@ describe('NavigationPlanStep', () => { done(); }); }); + + it('is invoke-lifecycle when query params change and ignoreQueryParams is false', (done) => { + firstInstruction.queryParams = { param: 'foo' }; + sameAsFirstInstruction.queryParams = { param: 'bar' }; + sameAsFirstInstruction.options.compareQueryParams = true; + firstInstruction.addViewPortInstruction('default', 'ignored', './first', { viewModel: {}}); + + step.run(sameAsFirstInstruction, state.next) + .then(() => { + expect(state.result).toBe(true); + expect(sameAsFirstInstruction.plan.default.strategy).toBe('invoke-lifecycle'); + done(); + }); + }); }); });