feat(router): enforce usage of ... syntax for parent to child component routes

This commit is contained in:
Matias Niemelä
2015-06-17 11:57:38 -07:00
parent fa7a3e3449
commit 2d2ae9b8d8
8 changed files with 103 additions and 27 deletions

View File

@ -53,12 +53,17 @@ export class RouteRegistry {
config, {'component': normalizeComponentDeclaration(config['component'])});
var component = config['component'];
this.configFromComponent(component);
var terminal = recognizer.addConfig(config['path'], config, config['as']);
recognizer.addConfig(config['path'], config, config['as']);
if (component['type'] == 'constructor') {
if (terminal) {
assertTerminalComponent(component['constructor'], config['path']);
} else {
this.configFromComponent(component['constructor']);
}
}
}
/**
* Reads the annotations of a component and configures the registry based on them
*/
@ -221,3 +226,21 @@ function mostSpecific(instructions: List<Instruction>): Instruction {
}
return mostSpecificSolution;
}
function assertTerminalComponent(component, path) {
if (!isType(component)) {
return;
}
var annotations = reflector.annotations(component);
if (isPresent(annotations)) {
for (var i = 0; i < annotations.length; i++) {
var annotation = annotations[i];
if (annotation instanceof RouteConfig) {
throw new BaseException(
`Child routes are not allowed for "${path}". Use "..." on the parent's route path.`);
}
}
}
}