fix(router): Fix _lastPathIndex in deeply nested empty paths (#22394)

PR Close #22394
This commit is contained in:
Adrien Samson
2018-02-23 10:24:51 +01:00
committed by Victor Berchet
parent 1e28495c89
commit 968f153491
5 changed files with 103 additions and 13 deletions

View File

@ -452,6 +452,45 @@ describe('recognize', () => {
});
});
it('should set url segment and index properly with the "corrected" option for nested empty-path segments',
() => {
const url = tree('a/b') as any;
recognize(
RootComponent, [{
path: 'a',
children: [{
path: 'b',
component: ComponentB,
children: [{
path: '',
component: ComponentC,
children: [{path: '', component: ComponentD}]
}]
}]
}],
url, 'a/b', 'emptyOnly', 'corrected')
.forEach((s: any) => {
expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1);
const a = s.firstChild(s.root) !;
expect(a._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(a._lastPathIndex).toBe(0);
const b = s.firstChild(a) !;
expect(b._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(b._lastPathIndex).toBe(1);
const c = s.firstChild(b) !;
expect(c._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(c._lastPathIndex).toBe(1);
const d = s.firstChild(c) !;
expect(d._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(d._lastPathIndex).toBe(1);
});
});
it('should set url segment and index properly when nested empty-path segments (2)', () => {
const url = tree('');
recognize(