1 | "use strict";
|
2 | var common_1 = require('@angular/common');
|
3 | var core_1 = require('@angular/core');
|
4 | var exceptions_1 = require('../src/facade/exceptions');
|
5 | var route_registry_1 = require('./route_registry');
|
6 | var router_1 = require('./router');
|
7 |
|
8 |
|
9 |
|
10 | exports.ROUTER_PROVIDERS_COMMON = [
|
11 | route_registry_1.RouteRegistry,
|
12 | { provide: common_1.LocationStrategy, useClass: common_1.PathLocationStrategy }, common_1.Location, {
|
13 | provide: router_1.Router,
|
14 | useFactory: routerFactory,
|
15 | deps: [route_registry_1.RouteRegistry, common_1.Location, route_registry_1.ROUTER_PRIMARY_COMPONENT, core_1.ApplicationRef]
|
16 | },
|
17 | {
|
18 | provide: route_registry_1.ROUTER_PRIMARY_COMPONENT,
|
19 | useFactory: routerPrimaryComponentFactory,
|
20 | deps: ([core_1.ApplicationRef])
|
21 | }
|
22 | ];
|
23 | function routerFactory(registry, location, primaryComponent, appRef) {
|
24 | var rootRouter = new router_1.RootRouter(registry, location, primaryComponent);
|
25 | appRef.registerDisposeListener(function () { return rootRouter.dispose(); });
|
26 | return rootRouter;
|
27 | }
|
28 | function routerPrimaryComponentFactory(app) {
|
29 | if (app.componentTypes.length == 0) {
|
30 | throw new exceptions_1.BaseException('Bootstrap at least one component before injecting Router.');
|
31 | }
|
32 | return app.componentTypes[0];
|
33 | }
|
34 |
|
\ | No newline at end of file |