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