fix(router): correctly sort route matches with children by specificity

This changes the way we calculate specificity. Instead of using a number,
we use a string, so that combining specificity across parent-child instructions
becomes a matter of concatenating them

Fixes #5848

Closes #6011
This commit is contained in:
Brian Ford
2015-12-18 10:05:55 -08:00
parent e748adda2e
commit b2bc50dbd1
7 changed files with 80 additions and 26 deletions

View File

@ -181,6 +181,21 @@ export function main() {
});
}));
it('should prefer routes with high specificity over routes with children with lower specificity',
inject([AsyncTestCompleter], (async) => {
registry.config(RootHostCmp, new Route({path: '/first', component: DummyCmpA}));
// terminates to DummyCmpB
registry.config(RootHostCmp,
new Route({path: '/:second/...', component: SingleSlashChildCmp}));
registry.recognize('/first', [])
.then((instruction) => {
expect(instruction.component.componentType).toBe(DummyCmpA);
async.done();
});
}));
it('should match the full URL using child components', inject([AsyncTestCompleter], (async) => {
registry.config(RootHostCmp, new Route({path: '/first/...', component: DummyParentCmp}));
@ -322,6 +337,10 @@ class DummyCmpB {}
class DefaultRouteCmp {
}
@RouteConfig([new Route({path: '/', component: DummyCmpB, name: 'ThirdCmp'})])
class SingleSlashChildCmp {
}
@RouteConfig([
new Route(

View File

@ -33,8 +33,8 @@ import {
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
import {ResolvedInstruction} from 'angular2/src/router/instruction';
let dummyInstruction =
new ResolvedInstruction(new ComponentInstruction('detail', [], null, null, true, 0), null, {});
let dummyInstruction = new ResolvedInstruction(
new ComponentInstruction('detail', [], null, null, true, '0'), null, {});
export function main() {
describe('routerLink directive', function() {