2015-08-20 14:28:25 -07:00
|
|
|
import {CONST, Type} from 'angular2/src/core/facade/lang';
|
2015-07-13 16:12:48 -07:00
|
|
|
import {RouteDefinition} from './route_definition';
|
|
|
|
export {RouteDefinition} from './route_definition';
|
2015-04-17 09:59:56 -07:00
|
|
|
|
|
|
|
/**
|
2015-09-21 14:43:24 -07:00
|
|
|
* The `RouteConfig` decorator defines routes for a given component.
|
2015-05-01 05:53:38 -07:00
|
|
|
*
|
2015-09-21 14:43:24 -07:00
|
|
|
* It takes an array of {@link RouteDefinition}s.
|
2015-04-17 09:59:56 -07:00
|
|
|
*/
|
2015-05-29 14:58:41 -07:00
|
|
|
@CONST()
|
2015-04-17 09:59:56 -07:00
|
|
|
export class RouteConfig {
|
2015-08-28 11:29:19 -07:00
|
|
|
constructor(public configs: RouteDefinition[]) {}
|
2015-07-13 16:12:48 -07:00
|
|
|
}
|
|
|
|
|
2015-09-21 14:43:24 -07:00
|
|
|
/**
|
|
|
|
* `Route` is a type of {@link RouteDefinition} used to route a path to a component.
|
|
|
|
*
|
|
|
|
* It has the following properties:
|
|
|
|
* - `path` is a string that uses the route matcher DSL.
|
|
|
|
* - `component` a component type.
|
|
|
|
* - `as` is an optional `CamelCase` string representing the name of the route.
|
|
|
|
* - `data` is an optional property of any type representing arbitrary route metadata for the given
|
|
|
|
* route. It is injectable via the {@link ROUTE_DATA} token.
|
|
|
|
*
|
2015-10-19 15:37:32 +01:00
|
|
|
* ### Example
|
2015-09-21 14:43:24 -07:00
|
|
|
* ```
|
|
|
|
* import {RouteConfig} from 'angular2/router';
|
|
|
|
*
|
|
|
|
* @RouteConfig([
|
|
|
|
* {path: '/home', component: HomeCmp, as: 'HomeCmp' }
|
|
|
|
* ])
|
|
|
|
* class MyApp {}
|
|
|
|
* ```
|
|
|
|
*/
|
2015-07-13 16:12:48 -07:00
|
|
|
@CONST()
|
|
|
|
export class Route implements RouteDefinition {
|
2015-08-10 20:29:40 -04:00
|
|
|
data: any;
|
2015-07-13 16:12:48 -07:00
|
|
|
path: string;
|
|
|
|
component: Type;
|
|
|
|
as: string;
|
2015-07-29 20:09:54 -07:00
|
|
|
// added next two properties to work around https://github.com/Microsoft/TypeScript/issues/4107
|
|
|
|
loader: Function;
|
|
|
|
redirectTo: string;
|
2015-08-10 20:29:40 -04:00
|
|
|
constructor({path, component, as, data}:
|
|
|
|
{path: string, component: Type, as?: string, data?: any}) {
|
2015-07-13 16:12:48 -07:00
|
|
|
this.path = path;
|
|
|
|
this.component = component;
|
|
|
|
this.as = as;
|
2015-07-29 20:09:54 -07:00
|
|
|
this.loader = null;
|
|
|
|
this.redirectTo = null;
|
2015-08-10 20:29:40 -04:00
|
|
|
this.data = data;
|
2015-07-13 16:12:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 14:43:24 -07:00
|
|
|
/**
|
|
|
|
* `AuxRoute` is a type of {@link RouteDefinition} used to define an auxiliary route.
|
|
|
|
*
|
|
|
|
* It takes an object with the following properties:
|
|
|
|
* - `path` is a string that uses the route matcher DSL.
|
|
|
|
* - `component` a component type.
|
|
|
|
* - `as` is an optional `CamelCase` string representing the name of the route.
|
|
|
|
* - `data` is an optional property of any type representing arbitrary route metadata for the given
|
|
|
|
* route. It is injectable via the {@link ROUTE_DATA} token.
|
|
|
|
*
|
2015-10-19 15:37:32 +01:00
|
|
|
* ### Example
|
2015-09-21 14:43:24 -07:00
|
|
|
* ```
|
|
|
|
* import {RouteConfig, AuxRoute} from 'angular2/router';
|
|
|
|
*
|
|
|
|
* @RouteConfig([
|
|
|
|
* new AuxRoute({path: '/home', component: HomeCmp})
|
|
|
|
* ])
|
|
|
|
* class MyApp {}
|
|
|
|
* ```
|
|
|
|
*/
|
2015-07-17 13:36:53 -07:00
|
|
|
@CONST()
|
|
|
|
export class AuxRoute implements RouteDefinition {
|
2015-08-10 20:29:40 -04:00
|
|
|
data: any = null;
|
2015-07-17 13:36:53 -07:00
|
|
|
path: string;
|
|
|
|
component: Type;
|
|
|
|
as: string;
|
|
|
|
// added next two properties to work around https://github.com/Microsoft/TypeScript/issues/4107
|
|
|
|
loader: Function = null;
|
|
|
|
redirectTo: string = null;
|
|
|
|
constructor({path, component, as}: {path: string, component: Type, as?: string}) {
|
|
|
|
this.path = path;
|
|
|
|
this.component = component;
|
|
|
|
this.as = as;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 14:43:24 -07:00
|
|
|
/**
|
|
|
|
* `AsyncRoute` is a type of {@link RouteDefinition} used to route a path to an asynchronously
|
|
|
|
* loaded component.
|
|
|
|
*
|
|
|
|
* It has the following properties:
|
|
|
|
* - `path` is a string that uses the route matcher DSL.
|
|
|
|
* - `loader` is a function that returns a promise that resolves to a component.
|
|
|
|
* - `as` is an optional `CamelCase` string representing the name of the route.
|
|
|
|
* - `data` is an optional property of any type representing arbitrary route metadata for the given
|
|
|
|
* route. It is injectable via the {@link ROUTE_DATA} token.
|
|
|
|
*
|
2015-10-19 15:37:32 +01:00
|
|
|
* ### Example
|
2015-09-21 14:43:24 -07:00
|
|
|
* ```
|
|
|
|
* import {RouteConfig} from 'angular2/router';
|
|
|
|
*
|
|
|
|
* @RouteConfig([
|
|
|
|
* {path: '/home', loader: () => Promise.resolve(MyLoadedCmp), as: 'MyLoadedCmp'}
|
|
|
|
* ])
|
|
|
|
* class MyApp {}
|
|
|
|
* ```
|
|
|
|
*/
|
2015-07-13 16:12:48 -07:00
|
|
|
@CONST()
|
|
|
|
export class AsyncRoute implements RouteDefinition {
|
2015-08-10 20:29:40 -04:00
|
|
|
data: any;
|
2015-07-13 16:12:48 -07:00
|
|
|
path: string;
|
|
|
|
loader: Function;
|
|
|
|
as: string;
|
2015-08-10 20:29:40 -04:00
|
|
|
constructor({path, loader, as, data}: {path: string, loader: Function, as?: string, data?: any}) {
|
2015-07-13 16:12:48 -07:00
|
|
|
this.path = path;
|
|
|
|
this.loader = loader;
|
|
|
|
this.as = as;
|
2015-08-10 20:29:40 -04:00
|
|
|
this.data = data;
|
2015-07-13 16:12:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 14:43:24 -07:00
|
|
|
/**
|
|
|
|
* `Redirect` is a type of {@link RouteDefinition} used to route a path to an asynchronously loaded
|
|
|
|
* component.
|
|
|
|
*
|
|
|
|
* It has the following properties:
|
|
|
|
* - `path` is a string that uses the route matcher DSL.
|
|
|
|
* - `redirectTo` is a string representing the new URL to be matched against.
|
|
|
|
*
|
2015-10-19 15:37:32 +01:00
|
|
|
* ### Example
|
2015-09-21 14:43:24 -07:00
|
|
|
* ```
|
|
|
|
* import {RouteConfig} from 'angular2/router';
|
|
|
|
*
|
|
|
|
* @RouteConfig([
|
|
|
|
* {path: '/', redirectTo: '/home'},
|
|
|
|
* {path: '/home', component: HomeCmp}
|
|
|
|
* ])
|
|
|
|
* class MyApp {}
|
|
|
|
* ```
|
|
|
|
*/
|
2015-07-13 16:12:48 -07:00
|
|
|
@CONST()
|
|
|
|
export class Redirect implements RouteDefinition {
|
|
|
|
path: string;
|
|
|
|
redirectTo: string;
|
|
|
|
as: string = null;
|
2015-07-17 13:36:53 -07:00
|
|
|
// added next property to work around https://github.com/Microsoft/TypeScript/issues/4107
|
|
|
|
loader: Function = null;
|
2015-08-10 20:29:40 -04:00
|
|
|
data: any = null;
|
2015-07-13 16:12:48 -07:00
|
|
|
constructor({path, redirectTo}: {path: string, redirectTo: string}) {
|
|
|
|
this.path = path;
|
|
|
|
this.redirectTo = redirectTo;
|
|
|
|
}
|
2015-04-17 09:59:56 -07:00
|
|
|
}
|