docs(router): improve docs for RouteDefinition classes
This commit is contained in:
parent
9c4ab2b2b8
commit
5c0a9eff62
|
@ -3,20 +3,35 @@ import {RouteDefinition} from './route_definition';
|
||||||
export {RouteDefinition} from './route_definition';
|
export {RouteDefinition} from './route_definition';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You use the RouteConfig annotation to add routes to a component.
|
* The `RouteConfig` decorator defines routes for a given component.
|
||||||
*
|
*
|
||||||
* Supported keys:
|
* It takes an array of {@link RouteDefinition}s.
|
||||||
* - `path` (required)
|
|
||||||
* - `component`, `loader`, `redirectTo` (requires exactly one of these)
|
|
||||||
* - `as` (optional)
|
|
||||||
* - `data` (optional)
|
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class RouteConfig {
|
export class RouteConfig {
|
||||||
constructor(public configs: RouteDefinition[]) {}
|
constructor(public configs: RouteDefinition[]) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `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.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
* ```
|
||||||
|
* import {RouteConfig} from 'angular2/router';
|
||||||
|
*
|
||||||
|
* @RouteConfig([
|
||||||
|
* {path: '/home', component: HomeCmp, as: 'HomeCmp' }
|
||||||
|
* ])
|
||||||
|
* class MyApp {}
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Route implements RouteDefinition {
|
export class Route implements RouteDefinition {
|
||||||
data: any;
|
data: any;
|
||||||
|
@ -37,8 +52,26 @@ export class Route implements RouteDefinition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `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.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
* ```
|
||||||
|
* import {RouteConfig, AuxRoute} from 'angular2/router';
|
||||||
|
*
|
||||||
|
* @RouteConfig([
|
||||||
|
* new AuxRoute({path: '/home', component: HomeCmp})
|
||||||
|
* ])
|
||||||
|
* class MyApp {}
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class AuxRoute implements RouteDefinition {
|
export class AuxRoute implements RouteDefinition {
|
||||||
data: any = null;
|
data: any = null;
|
||||||
|
@ -55,6 +88,27 @@ export class AuxRoute implements RouteDefinition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `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.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
* ```
|
||||||
|
* import {RouteConfig} from 'angular2/router';
|
||||||
|
*
|
||||||
|
* @RouteConfig([
|
||||||
|
* {path: '/home', loader: () => Promise.resolve(MyLoadedCmp), as: 'MyLoadedCmp'}
|
||||||
|
* ])
|
||||||
|
* class MyApp {}
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class AsyncRoute implements RouteDefinition {
|
export class AsyncRoute implements RouteDefinition {
|
||||||
data: any;
|
data: any;
|
||||||
|
@ -69,6 +123,25 @@ export class AsyncRoute implements RouteDefinition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `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.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
* ```
|
||||||
|
* import {RouteConfig} from 'angular2/router';
|
||||||
|
*
|
||||||
|
* @RouteConfig([
|
||||||
|
* {path: '/', redirectTo: '/home'},
|
||||||
|
* {path: '/home', component: HomeCmp}
|
||||||
|
* ])
|
||||||
|
* class MyApp {}
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Redirect implements RouteDefinition {
|
export class Redirect implements RouteDefinition {
|
||||||
path: string;
|
path: string;
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
import {CONST, Type} from 'angular2/src/core/facade/lang';
|
import {CONST, Type} from 'angular2/src/core/facade/lang';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `RouteDefinition` defines a route within a {@link RouteConfig} decorator.
|
||||||
|
*
|
||||||
|
* Supported keys:
|
||||||
|
* - `path` (required)
|
||||||
|
* - `component`, `loader`, `redirectTo` (requires exactly one of these)
|
||||||
|
* - `as` (optional)
|
||||||
|
* - `data` (optional)
|
||||||
|
*
|
||||||
|
* See also {@link Route}, {@link AsyncRoute}, {@link AuxRoute}, and {@link Redirect}.
|
||||||
|
*/
|
||||||
export interface RouteDefinition {
|
export interface RouteDefinition {
|
||||||
path: string;
|
path: string;
|
||||||
component?: Type | ComponentDefinition;
|
component?: Type | ComponentDefinition;
|
||||||
|
|
Loading…
Reference in New Issue