From dcd8a8fcaea46bd5a127088e232f8dd36604aedd Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 9 Aug 2019 14:59:22 +0200 Subject: [PATCH 1/4] fix #16594 --- .../-internals/routing/lib/system/router.ts | 5 +++- .../router_service_test/transitionTo_test.js | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/@ember/-internals/routing/lib/system/router.ts b/packages/@ember/-internals/routing/lib/system/router.ts index f41e3599438..e8e4f093805 100644 --- a/packages/@ember/-internals/routing/lib/system/router.ts +++ b/packages/@ember/-internals/routing/lib/system/router.ts @@ -1063,7 +1063,10 @@ class EmberRouter extends EmberObject { return true; } - if (_fromRouterService && presentProp !== false) { + if (_fromRouterService && presentProp !== false && qp.urlKey != qp.prop) { + // assumptions (mainly from current transitionTo_test): + // - this is only supposed to be run when there is an alias to a query param and the alias is used to set the param + // - when there is no alias: qp.urlKey == qp.prop return false; } diff --git a/packages/ember/tests/routing/router_service_test/transitionTo_test.js b/packages/ember/tests/routing/router_service_test/transitionTo_test.js index 4be05d10a45..cf276e91f44 100644 --- a/packages/ember/tests/routing/router_service_test/transitionTo_test.js +++ b/packages/ember/tests/routing/router_service_test/transitionTo_test.js @@ -6,6 +6,7 @@ import { run } from '@ember/runloop'; import { get } from '@ember/-internals/metal'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; import { InternalTransition as Transition } from 'router_js'; +import { inject as service } from '@ember/service'; moduleFor( 'Router Service - transitionTo', @@ -362,5 +363,31 @@ moduleFor( }, 'You passed the `cont_sort` query parameter during a transition into parent.child, please update to url_sort'); }); } + + ['@test RouterService#transitionTo with application query params when redirecting form a different route']( + assert + ) { + assert.expect(1); + + this.add( + 'route:parent.child', + Route.extend({ + router: service(), + beforeModel() { + this.router.transitionTo('parent'); + }, + }) + ); + this.add( + 'controller:parent', + Controller.extend({ + queryParams: ['url_sort'], + }) + ); + + return this.visit('/child?url_sort=a').then(() => { + assert.equal(this.routerService.get('currentURL'), '/?url_sort=a'); + }); + } } ); From b5b4c8a618b5c3bb401a19da0e706913e0f7d71b Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 9 Aug 2019 15:34:23 +0200 Subject: [PATCH 2/4] fix liniting --- packages/@ember/-internals/routing/lib/system/router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@ember/-internals/routing/lib/system/router.ts b/packages/@ember/-internals/routing/lib/system/router.ts index e8e4f093805..1361193713a 100644 --- a/packages/@ember/-internals/routing/lib/system/router.ts +++ b/packages/@ember/-internals/routing/lib/system/router.ts @@ -1063,7 +1063,7 @@ class EmberRouter extends EmberObject { return true; } - if (_fromRouterService && presentProp !== false && qp.urlKey != qp.prop) { + if (_fromRouterService && presentProp !== false && qp.urlKey !== qp.prop) { // assumptions (mainly from current transitionTo_test): // - this is only supposed to be run when there is an alias to a query param and the alias is used to set the param // - when there is no alias: qp.urlKey == qp.prop From 7dc7f4441fc188be6fdbc83b02b31266c8d3f98f Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 9 Aug 2019 14:59:22 +0200 Subject: [PATCH 3/4] fix #16594 --- .../-internals/routing/lib/system/router.ts | 5 +++- .../router_service_test/transitionTo_test.js | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/@ember/-internals/routing/lib/system/router.ts b/packages/@ember/-internals/routing/lib/system/router.ts index 8bc0150282a..ea8a877bae3 100644 --- a/packages/@ember/-internals/routing/lib/system/router.ts +++ b/packages/@ember/-internals/routing/lib/system/router.ts @@ -1063,7 +1063,10 @@ class EmberRouter extends EmberObject { return true; } - if (_fromRouterService && presentProp !== false) { + if (_fromRouterService && presentProp !== false && qp.urlKey != qp.prop) { + // assumptions (mainly from current transitionTo_test): + // - this is only supposed to be run when there is an alias to a query param and the alias is used to set the param + // - when there is no alias: qp.urlKey == qp.prop return false; } diff --git a/packages/ember/tests/routing/router_service_test/transitionTo_test.js b/packages/ember/tests/routing/router_service_test/transitionTo_test.js index 4be05d10a45..cf276e91f44 100644 --- a/packages/ember/tests/routing/router_service_test/transitionTo_test.js +++ b/packages/ember/tests/routing/router_service_test/transitionTo_test.js @@ -6,6 +6,7 @@ import { run } from '@ember/runloop'; import { get } from '@ember/-internals/metal'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; import { InternalTransition as Transition } from 'router_js'; +import { inject as service } from '@ember/service'; moduleFor( 'Router Service - transitionTo', @@ -362,5 +363,31 @@ moduleFor( }, 'You passed the `cont_sort` query parameter during a transition into parent.child, please update to url_sort'); }); } + + ['@test RouterService#transitionTo with application query params when redirecting form a different route']( + assert + ) { + assert.expect(1); + + this.add( + 'route:parent.child', + Route.extend({ + router: service(), + beforeModel() { + this.router.transitionTo('parent'); + }, + }) + ); + this.add( + 'controller:parent', + Controller.extend({ + queryParams: ['url_sort'], + }) + ); + + return this.visit('/child?url_sort=a').then(() => { + assert.equal(this.routerService.get('currentURL'), '/?url_sort=a'); + }); + } } ); From 26b3360d110dad94ed5b2d2837fbfde7fcfedb79 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 9 Aug 2019 15:34:23 +0200 Subject: [PATCH 4/4] fix liniting --- packages/@ember/-internals/routing/lib/system/router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@ember/-internals/routing/lib/system/router.ts b/packages/@ember/-internals/routing/lib/system/router.ts index ea8a877bae3..7e7006ea9b3 100644 --- a/packages/@ember/-internals/routing/lib/system/router.ts +++ b/packages/@ember/-internals/routing/lib/system/router.ts @@ -1063,7 +1063,7 @@ class EmberRouter extends EmberObject { return true; } - if (_fromRouterService && presentProp !== false && qp.urlKey != qp.prop) { + if (_fromRouterService && presentProp !== false && qp.urlKey !== qp.prop) { // assumptions (mainly from current transitionTo_test): // - this is only supposed to be run when there is an alias to a query param and the alias is used to set the param // - when there is no alias: qp.urlKey == qp.prop