feat(router): allow async routes to be defined with "loader"
This commit is contained in:
parent
6d4bd5d901
commit
ee32b1bc37
|
@ -13,10 +13,13 @@ export function normalizeRouteConfig(config: RouteDefinition): RouteDefinition {
|
|||
return <RouteDefinition>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 = <ComponentDefinition>config.component;
|
||||
|
|
|
@ -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 { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
|
||||
@RouteConfig([
|
||||
{path: '/hello', loader: HelloLoader},
|
||||
])
|
||||
class ConciseAsyncAppCmp {
|
||||
constructor(public router: Router, public location: LocationStrategy) {}
|
||||
}
|
||||
|
||||
@Component({selector: 'app-cmp'})
|
||||
@View({template: `root { <router-outlet></router-outlet> }`, directives: ROUTER_DIRECTIVES})
|
||||
@RouteConfig([
|
||||
|
|
Loading…
Reference in New Issue