fix(router): throw when component in route config is not defined
Close #3265 Closes #3569
This commit is contained in:
@ -19,9 +19,17 @@ import {
|
||||
isFunction,
|
||||
StringWrapper,
|
||||
BaseException,
|
||||
Type,
|
||||
getTypeNameForDebugging
|
||||
} from 'angular2/src/facade/lang';
|
||||
import {RouteConfig, AsyncRoute, Route, Redirect, RouteDefinition} from './route_config_impl';
|
||||
import {
|
||||
RouteConfig,
|
||||
AsyncRoute,
|
||||
Route,
|
||||
AuxRoute,
|
||||
Redirect,
|
||||
RouteDefinition
|
||||
} from './route_config_impl';
|
||||
import {reflector} from 'angular2/src/reflection/reflection';
|
||||
import {Injectable} from 'angular2/di';
|
||||
import {normalizeRouteConfig} from './route_config_nomalizer';
|
||||
@ -44,6 +52,13 @@ export class RouteRegistry {
|
||||
config(parentComponent: any, config: RouteDefinition): void {
|
||||
config = normalizeRouteConfig(config);
|
||||
|
||||
// this is here because Dart type guard reasons
|
||||
if (config instanceof Route) {
|
||||
assertComponentExists(config.component, config.path);
|
||||
} else if (config instanceof AuxRoute) {
|
||||
assertComponentExists(config.component, config.path);
|
||||
}
|
||||
|
||||
var recognizer: RouteRecognizer = this._rules.get(parentComponent);
|
||||
|
||||
if (isBlank(recognizer)) {
|
||||
@ -269,3 +284,9 @@ function assertTerminalComponent(component, path) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function assertComponentExists(component: Type, path: string): void {
|
||||
if (!isType(component)) {
|
||||
throw new BaseException(`Component for route "${path}" is not defined, or is not a class.`);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user