Skip to content

Commit a3b9041

Browse files
committed
fix(router): fix RouterLinkActive to handle the case when the link has extra paths
1 parent 5781b96 commit a3b9041

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

modules/@angular/router/src/url_tree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ export function containsTree(container: UrlTree, containee: UrlTree, exact: bool
2323

2424
function equalSegments(container: UrlSegment, containee: UrlSegment): boolean {
2525
if (!equalPath(container.pathsWithParams, containee.pathsWithParams)) return false;
26-
if (Object.keys(container.children).length !== Object.keys(containee.children).length)
27-
return false;
26+
if (container.numberOfChildren !== containee.numberOfChildren) return false;
2827
for (let c in containee.children) {
2928
if (!container.children[c]) return false;
3029
if (!equalSegments(container.children[c], containee.children[c])) return false;
@@ -41,7 +40,7 @@ function containsSegmentHelper(
4140
if (container.pathsWithParams.length > containeePaths.length) {
4241
const current = container.pathsWithParams.slice(0, containeePaths.length);
4342
if (!equalPath(current, containeePaths)) return false;
44-
if (Object.keys(containee.children).length > 0) return false;
43+
if (containee.hasChildren()) return false;
4544
return true;
4645

4746
} else if (container.pathsWithParams.length === containeePaths.length) {
@@ -56,6 +55,7 @@ function containsSegmentHelper(
5655
const current = containeePaths.slice(0, container.pathsWithParams.length);
5756
const next = containeePaths.slice(container.pathsWithParams.length);
5857
if (!equalPath(container.pathsWithParams, current)) return false;
58+
if (!container.children[PRIMARY_OUTLET]) return false;
5959
return containsSegmentHelper(container.children[PRIMARY_OUTLET], containee, next);
6060
}
6161
}

modules/@angular/router/test/url_tree.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ describe('UrlTree', () => {
6262
const t2 = serializer.parse('/one/(two//right:four)');
6363
expect(containsTree(t1, t2, false)).toBe(false);
6464
});
65+
66+
it('should return false when containee has extra paths', () => {
67+
const t1 = serializer.parse('/one');
68+
const t2 = serializer.parse('/one/two');
69+
expect(containsTree(t1, t2, false)).toBe(false);
70+
});
6571
});
6672
});
6773
});

0 commit comments

Comments
 (0)