From b732fb935b80a647d92753568b61e65cc6b2cc3f Mon Sep 17 00:00:00 2001 From: Mark Kennedy Date: Sun, 15 Oct 2017 14:48:20 -0500 Subject: [PATCH] fix(router): 'merge' queryParamHandling strategy should be able to remove query params (#19733) Closes #18463, #17202 PR Close #19733 --- packages/router/src/router.ts | 6 +++--- packages/router/test/integration.spec.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index cd2d68c35d..de38b0ecdc 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -400,6 +400,9 @@ export class Router { } else { q = preserveQueryParams ? this.currentUrlTree.queryParams : queryParams || null; } + if (q !== null) { + q = this.removeEmptyProps(q); + } return createUrlTree(a, this.currentUrlTree, commands, q !, f !); } @@ -455,9 +458,6 @@ export class Router { navigate(commands: any[], extras: NavigationExtras = {skipLocationChange: false}): Promise { validateCommands(commands); - if (typeof extras.queryParams === 'object' && extras.queryParams !== null) { - extras.queryParams = this.removeEmptyProps(extras.queryParams); - } return this.navigateByUrl(this.createUrlTree(commands, extras), extras); } diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 722f0ad133..a4ccdbab30 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -1289,7 +1289,7 @@ describe('Integration', () => { @Component({ selector: 'someRoot', template: - `Link` + `Link` }) class RootCmpWithLink { } @@ -1301,7 +1301,7 @@ describe('Integration', () => { const native = fixture.nativeElement.querySelector('a'); - router.navigateByUrl('/home?a=123'); + router.navigateByUrl('/home?a=123&removeMe=123'); advance(fixture); expect(native.getAttribute('href')).toEqual('/home?a=123&q=456'); }));