forked from ngrx/router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute.ts
42 lines (33 loc) · 1.14 KB
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Route and IndexRoute interfaces are similar to react-router's interfaces.
*/
import { Observable } from 'rxjs/Observable';
import { Provider, Type, OpaqueToken } from 'angular2/core';
import { Async } from './resource-loader';
export type Routes = Array<Route>;
export interface SimpleRoute {
component?: Type;
loadComponent?: Async<Type>;
}
export interface IndexRoute extends SimpleRoute {
components?: { [name: string]: Type };
loadComponents?: { [name: string]: Async<Type> };
redirectTo?: string;
}
export interface Route extends IndexRoute {
path?: string;
guards?: Provider[];
indexRoute?: IndexRoute;
loadIndexRoute?: Async<IndexRoute>;
children?: Routes;
loadChildren?: Async<Routes>;
}
export const ROUTES = new OpaqueToken('@ngrx/router Init Routes');
export function getNamedComponents(route: IndexRoute, name?: string): SimpleRoute {
if (!name) {
return { component: route.component, loadComponent: route.loadComponent };
}
const components = route.components || {};
const loadComponents = route.loadComponents || {};
return { component: components[name], loadComponent: loadComponents[name] };
}