fix(router): traverse route config in depth-first order

Closes #17
This commit is contained in:
vsavkin
2016-06-06 10:15:23 -07:00
parent 793ac3f6b4
commit 9b356d9b86
2 changed files with 57 additions and 42 deletions

View File

@ -17,19 +17,6 @@ describe('recognize', () => {
});
});
it('should handle position args', () => {
recognize(RootComponent, [
{
path: 'a/:id', component: ComponentA, children: [
{ path: 'b/:id', component: ComponentB}
]
}
], tree("a/paramA/b/paramB")).forEach(s => {
checkActivatedRoute(s.root, "", {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root), "a/paramA", {id: 'paramA'}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "b/paramB", {id: 'paramB'}, ComponentB);
});
});
it('should support secondary routes', () => {
recognize(RootComponent, [
@ -44,6 +31,25 @@ describe('recognize', () => {
});
});
it('should match routes in the depth first order', () => {
recognize(RootComponent, [
{path: 'a', component: ComponentA, children: [{path: ':id', component: ComponentB}]},
{path: 'a/:id', component: ComponentC}
], tree("a/paramA")).forEach(s => {
checkActivatedRoute(s.root, "", {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "paramA", {id: 'paramA'}, ComponentB);
});
recognize(RootComponent, [
{path: 'a', component: ComponentA},
{path: 'a/:id', component: ComponentC}
], tree("a/paramA")).forEach(s => {
checkActivatedRoute(s.root, "", {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root), "a/paramA", {id: 'paramA'}, ComponentC);
});
});
it('should use outlet name when matching secondary routes', () => {
recognize(RootComponent, [
{ path: 'a', component: ComponentA },