2016-05-02 17:11:21 +00:00
|
|
|
import {OpaqueToken, ComponentResolver} from '@angular/core';
|
2016-04-29 00:50:03 +00:00
|
|
|
import {LocationStrategy, PathLocationStrategy, Location} from '@angular/common';
|
2016-05-02 17:11:21 +00:00
|
|
|
import {Router, RouterOutletMap} from './router';
|
2016-05-04 21:40:17 +00:00
|
|
|
import {RouteSegment} from './segments';
|
2016-05-02 17:11:21 +00:00
|
|
|
import {RouterUrlSerializer, DefaultRouterUrlSerializer} from './router_url_serializer';
|
|
|
|
|
import {ApplicationRef} from '@angular/core';
|
|
|
|
|
import {BaseException} from '@angular/core';
|
2016-01-21 17:58:28 +00:00
|
|
|
|
2016-05-03 18:35:07 +00:00
|
|
|
/**
|
|
|
|
|
* The Platform agnostic ROUTER PROVIDERS
|
|
|
|
|
*/
|
2016-04-26 04:47:33 +00:00
|
|
|
export const ROUTER_PROVIDERS_COMMON: any[] = /*@ts2dart_const*/[
|
2016-05-02 17:11:21 +00:00
|
|
|
RouterOutletMap,
|
|
|
|
|
/*@ts2dart_Provider*/ {provide: RouterUrlSerializer, useClass: DefaultRouterUrlSerializer},
|
|
|
|
|
/*@ts2dart_Provider*/ {provide: LocationStrategy, useClass: PathLocationStrategy}, Location,
|
|
|
|
|
/*@ts2dart_Provider*/ {
|
2016-04-26 05:25:21 +00:00
|
|
|
provide: Router,
|
|
|
|
|
useFactory: routerFactory,
|
2016-05-02 17:11:21 +00:00
|
|
|
deps: /*@ts2dart_const*/
|
|
|
|
|
[ApplicationRef, ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location],
|
2016-04-26 05:25:21 +00:00
|
|
|
},
|
2016-05-04 21:40:17 +00:00
|
|
|
/*@ts2dart_Provider*/ {provide: RouteSegment, useFactory: (r) => r.routeTree.root, deps: [Router]}
|
2016-04-26 04:47:33 +00:00
|
|
|
];
|
2016-01-21 17:58:28 +00:00
|
|
|
|
2016-05-02 17:11:21 +00:00
|
|
|
function routerFactory(app: ApplicationRef, componentResolver: ComponentResolver,
|
|
|
|
|
urlSerializer: RouterUrlSerializer, routerOutletMap: RouterOutletMap,
|
|
|
|
|
location: Location): Router {
|
2016-01-21 17:58:28 +00:00
|
|
|
if (app.componentTypes.length == 0) {
|
2016-04-12 16:40:37 +00:00
|
|
|
throw new BaseException("Bootstrap at least one component before injecting Router.");
|
2016-01-21 17:58:28 +00:00
|
|
|
}
|
2016-05-02 17:11:21 +00:00
|
|
|
// TODO: vsavkin this should not be null
|
|
|
|
|
let router = new Router(null, app.componentTypes[0], componentResolver, urlSerializer,
|
|
|
|
|
routerOutletMap, location);
|
|
|
|
|
app.registerDisposeListener(() => router.dispose());
|
|
|
|
|
return router;
|
2016-01-21 17:58:28 +00:00
|
|
|
}
|