From a3b90411aaabe13a12c68dba883f0fff38227966 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Wed, 29 Jun 2016 16:07:35 -0700 Subject: [PATCH] fix(router): fix RouterLinkActive to handle the case when the link has extra paths --- modules/@angular/router/src/url_tree.ts | 6 +++--- modules/@angular/router/test/url_tree.spec.ts | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/@angular/router/src/url_tree.ts b/modules/@angular/router/src/url_tree.ts index e4ef4b96cd..b78fb00e53 100644 --- a/modules/@angular/router/src/url_tree.ts +++ b/modules/@angular/router/src/url_tree.ts @@ -23,8 +23,7 @@ export function containsTree(container: UrlTree, containee: UrlTree, exact: bool function equalSegments(container: UrlSegment, containee: UrlSegment): boolean { if (!equalPath(container.pathsWithParams, containee.pathsWithParams)) return false; - if (Object.keys(container.children).length !== Object.keys(containee.children).length) - return false; + if (container.numberOfChildren !== containee.numberOfChildren) return false; for (let c in containee.children) { if (!container.children[c]) return false; if (!equalSegments(container.children[c], containee.children[c])) return false; @@ -41,7 +40,7 @@ function containsSegmentHelper( if (container.pathsWithParams.length > containeePaths.length) { const current = container.pathsWithParams.slice(0, containeePaths.length); if (!equalPath(current, containeePaths)) return false; - if (Object.keys(containee.children).length > 0) return false; + if (containee.hasChildren()) return false; return true; } else if (container.pathsWithParams.length === containeePaths.length) { @@ -56,6 +55,7 @@ function containsSegmentHelper( const current = containeePaths.slice(0, container.pathsWithParams.length); const next = containeePaths.slice(container.pathsWithParams.length); if (!equalPath(container.pathsWithParams, current)) return false; + if (!container.children[PRIMARY_OUTLET]) return false; return containsSegmentHelper(container.children[PRIMARY_OUTLET], containee, next); } } diff --git a/modules/@angular/router/test/url_tree.spec.ts b/modules/@angular/router/test/url_tree.spec.ts index bf8c7b3a6b..9a24679c35 100644 --- a/modules/@angular/router/test/url_tree.spec.ts +++ b/modules/@angular/router/test/url_tree.spec.ts @@ -62,6 +62,12 @@ describe('UrlTree', () => { const t2 = serializer.parse('/one/(two//right:four)'); expect(containsTree(t1, t2, false)).toBe(false); }); + + it('should return false when containee has extra paths', () => { + const t1 = serializer.parse('/one'); + const t2 = serializer.parse('/one/two'); + expect(containsTree(t1, t2, false)).toBe(false); + }); }); }); }); \ No newline at end of file