From d2d36c61f3d8376489b4f99d2cb8ee68de444009 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Sun, 7 Aug 2016 18:34:12 -0700 Subject: [PATCH] fix(router): fix matrix params check to handle 'special' objects --- modules/@angular/router/src/create_url_tree.ts | 7 ++++++- modules/@angular/router/test/create_url_tree.spec.ts | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/@angular/router/src/create_url_tree.ts b/modules/@angular/router/src/create_url_tree.ts index 75d8704afb..cd05a1b0ea 100644 --- a/modules/@angular/router/src/create_url_tree.ts +++ b/modules/@angular/router/src/create_url_tree.ts @@ -35,11 +35,16 @@ export function createUrlTree( } function validateCommands(n: NormalizedNavigationCommands): void { - if (n.isAbsolute && n.commands.length > 0 && (typeof n.commands[0] === 'object')) { + if (n.isAbsolute && n.commands.length > 0 && isMatrixParams(n.commands[0])) { throw new Error('Root segment cannot have matrix parameters'); } } +function isMatrixParams(command: any): boolean { + return typeof command === 'object' && command.outlets === undefined && + command.segmentPath === undefined; +} + function tree( oldSegmentGroup: UrlSegmentGroup, newSegmentGroup: UrlSegmentGroup, urlTree: UrlTree, queryParams: Params, fragment: string): UrlTree { diff --git a/modules/@angular/router/test/create_url_tree.spec.ts b/modules/@angular/router/test/create_url_tree.spec.ts index 3a589e4e80..82a016083f 100644 --- a/modules/@angular/router/test/create_url_tree.spec.ts +++ b/modules/@angular/router/test/create_url_tree.spec.ts @@ -54,6 +54,12 @@ describe('createUrlTree', () => { expect(serializer.serialize(t)).toEqual('/a/11/d(right:c)'); }); + it('should support updating secondary segments (absolute)', () => { + const p = serializer.parse('/a(right:b)'); + const t = createRoot(p, ['/', {outlets: {right: ['c']}}]); + expect(serializer.serialize(t)).toEqual('/a(right:c)'); + }); + it('should support updating secondary segments', () => { const p = serializer.parse('/a(right:b)'); const t = createRoot(p, [{outlets: {right: ['c', 11, 'd']}}]);