fix(router): improve error messages for routes with no config

Closes #2323
This commit is contained in:
Brian Ford
2015-07-13 15:29:14 -07:00
parent ccb41632c7
commit 8bdca5c03e
2 changed files with 87 additions and 76 deletions

View File

@ -17,7 +17,8 @@ import {
isStringMap,
isFunction,
StringWrapper,
BaseException
BaseException,
getTypeNameForDebugging
} from 'angular2/src/facade/lang';
import {RouteConfig} from './route_config_impl';
import {reflector} from 'angular2/src/reflection/reflection';
@ -154,6 +155,9 @@ export class RouteRegistry {
let componentCursor = parentComponent;
for (let i = 0; i < linkParams.length; i += 1) {
let segment = linkParams[i];
if (isBlank(componentCursor)) {
throw new BaseException(`Could not find route named "${segment}".`);
}
if (!isString(segment)) {
throw new BaseException(`Unexpected segment "${segment}" in link DSL. Expected a string.`);
} else if (segment == '' || segment == '.' || segment == '..') {
@ -170,9 +174,13 @@ export class RouteRegistry {
var componentRecognizer = this._rules.get(componentCursor);
if (isBlank(componentRecognizer)) {
throw new BaseException(`Could not find route config for "${segment}".`);
throw new BaseException(`Component "${getTypeNameForDebugging(componentCursor)}" has no route config.`);
}
var response = componentRecognizer.generate(segment, params);
if (isBlank(response)) {
throw new BaseException(
`Component "${getTypeNameForDebugging(componentCursor)}" has no route named "${segment}".`);
}
url += response['url'];
componentCursor = response['nextComponent'];
}