diff --git a/modules/angular2/src/router/route_config_nomalizer.ts b/modules/angular2/src/router/route_config_nomalizer.ts index d3eca00ad0..15f511f2c2 100644 --- a/modules/angular2/src/router/route_config_nomalizer.ts +++ b/modules/angular2/src/router/route_config_nomalizer.ts @@ -13,10 +13,13 @@ export function normalizeRouteConfig(config: RouteDefinition): RouteDefinition { return config; } - if ((!config.component) == (!config.redirectTo)) { + if ((+!!config.component) + (+!!config.redirectTo) + (+!!config.loader) != 1) { throw new BaseException( `Route config should contain exactly one "component", "loader", or "redirectTo" property.`); } + if (config.loader) { + return new AsyncRoute({path: config.path, loader: config.loader, as: config.as}); + } if (config.component) { if (typeof config.component == 'object') { let componentDefinitionObject = config.component; diff --git a/modules/angular2/test/router/route_config_spec.ts b/modules/angular2/test/router/route_config_spec.ts index 70d5aa3361..a709edc504 100644 --- a/modules/angular2/test/router/route_config_spec.ts +++ b/modules/angular2/test/router/route_config_spec.ts @@ -100,6 +100,22 @@ export function main() { })); + it('should work in an app with async components defined with "loader"', + inject([AsyncTestCompleter], (async) => { + bootstrap(ConciseAsyncAppCmp, + [bind(ROUTER_PRIMARY_COMPONENT).toValue(AsyncAppCmp), testBindings]) + .then((applicationRef) => { + var router = applicationRef.hostComponent.router; + router.subscribe((_) => { + expect(el).toHaveText('root { hello }'); + expect(applicationRef.hostComponent.location.path()).toEqual('/hello'); + async.done(); + }); + router.navigateByUrl('/hello'); + }); + })); + + it('should work in an app with a constructor component', inject([AsyncTestCompleter], (async) => { bootstrap( @@ -187,6 +203,15 @@ class AsyncAppCmp { constructor(public router: Router, public location: LocationStrategy) {} } +@Component({selector: 'app-cmp'}) +@View({template: `root { }`, directives: ROUTER_DIRECTIVES}) +@RouteConfig([ + {path: '/hello', loader: HelloLoader}, +]) +class ConciseAsyncAppCmp { + constructor(public router: Router, public location: LocationStrategy) {} +} + @Component({selector: 'app-cmp'}) @View({template: `root { }`, directives: ROUTER_DIRECTIVES}) @RouteConfig([