fix(router): handle urls with only secondary top-level segments
This commit is contained in:
@ -494,6 +494,22 @@ describe('recognize', () => {
|
||||
checkActivatedRoute(c[1], 'c', {}, ComponentC, 'aux');
|
||||
});
|
||||
});
|
||||
|
||||
it('should work when split is at the root level', () => {
|
||||
checkRecognize(
|
||||
[
|
||||
{path: '', component: ComponentA}, {path: 'b', component: ComponentB},
|
||||
{path: 'c', component: ComponentC, outlet: 'aux'}
|
||||
],
|
||||
'(aux:c)', (s: RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.root, '', {}, RootComponent);
|
||||
|
||||
const children = s.children(s.root);
|
||||
expect(children.length).toEqual(2);
|
||||
checkActivatedRoute(children[0], '', {}, ComponentA);
|
||||
checkActivatedRoute(children[1], 'c', {}, ComponentC, 'aux');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('split at the end (right child)', () => {
|
||||
|
@ -6,7 +6,6 @@ describe('url serializer', () => {
|
||||
|
||||
it('should parse the root url', () => {
|
||||
const tree = url.parse('/');
|
||||
|
||||
expectSegment(tree.root, '');
|
||||
expect(url.serialize(tree)).toEqual('/');
|
||||
});
|
||||
@ -27,6 +26,26 @@ describe('url serializer', () => {
|
||||
expect(url.serialize(tree)).toEqual('/one/two(left:three//right:four)');
|
||||
});
|
||||
|
||||
it('should parse top-level nodes with only secondary segment', () => {
|
||||
const tree = url.parse('/(left:one)');
|
||||
|
||||
expect(tree.root.numberOfChildren).toEqual(1);
|
||||
expectSegment(tree.root.children['left'], 'one');
|
||||
|
||||
expect(url.serialize(tree)).toEqual('/(left:one)');
|
||||
});
|
||||
|
||||
it('should parse nodes with only secondary segment', () => {
|
||||
const tree = url.parse('/one/(left:two)');
|
||||
|
||||
const one = tree.root.children[PRIMARY_OUTLET];
|
||||
expectSegment(one, 'one', true);
|
||||
expect(one.numberOfChildren).toEqual(1);
|
||||
expectSegment(one.children['left'], 'two');
|
||||
|
||||
expect(url.serialize(tree)).toEqual('/one/(left:two)');
|
||||
});
|
||||
|
||||
it('should not parse empty path segments with params', () => {
|
||||
expect(() => url.parse('/one/two/(;a=1//right:;b=2)'))
|
||||
.toThrowError(/Empty path url segment cannot have parameters/);
|
||||
@ -167,6 +186,9 @@ describe('url serializer', () => {
|
||||
});
|
||||
|
||||
function expectSegment(segment: UrlSegment, expected: string, hasChildren: boolean = false): void {
|
||||
if (segment.pathsWithParams.filter(s => s.path === '').length > 0) {
|
||||
throw new Error(`UrlPathWithParams cannot be empty ${segment.pathsWithParams}`);
|
||||
}
|
||||
const p = segment.pathsWithParams.map(p => serializePath(p)).join('/');
|
||||
expect(p).toEqual(expected);
|
||||
expect(Object.keys(segment.children).length > 0).toEqual(hasChildren);
|
||||
|
Reference in New Issue
Block a user