Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5c0a9ef

Browse files
committed
docs(router): improve docs for RouteDefinition classes
1 parent 9c4ab2b commit 5c0a9ef

File tree

2 files changed

+93
-9
lines changed

2 files changed

+93
-9
lines changed

modules/angular2/src/router/route_config_impl.ts

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,35 @@ import {RouteDefinition} from './route_definition';
33
export {RouteDefinition} from './route_definition';
44

55
/**
6-
* You use the RouteConfig annotation to add routes to a component.
6+
* The `RouteConfig` decorator defines routes for a given component.
77
*
8-
* Supported keys:
9-
* - `path` (required)
10-
* - `component`, `loader`, `redirectTo` (requires exactly one of these)
11-
* - `as` (optional)
12-
* - `data` (optional)
8+
* It takes an array of {@link RouteDefinition}s.
139
*/
1410
@CONST()
1511
export class RouteConfig {
1612
constructor(public configs: RouteDefinition[]) {}
1713
}
1814

19-
15+
/**
16+
* `Route` is a type of {@link RouteDefinition} used to route a path to a component.
17+
*
18+
* It has the following properties:
19+
* - `path` is a string that uses the route matcher DSL.
20+
* - `component` a component type.
21+
* - `as` is an optional `CamelCase` string representing the name of the route.
22+
* - `data` is an optional property of any type representing arbitrary route metadata for the given
23+
* route. It is injectable via the {@link ROUTE_DATA} token.
24+
*
25+
* ## Example
26+
* ```
27+
* import {RouteConfig} from 'angular2/router';
28+
*
29+
* @RouteConfig([
30+
* {path: '/home', component: HomeCmp, as: 'HomeCmp' }
31+
* ])
32+
* class MyApp {}
33+
* ```
34+
*/
2035
@CONST()
2136
export class Route implements RouteDefinition {
2237
data: any;
@@ -37,8 +52,26 @@ export class Route implements RouteDefinition {
3752
}
3853
}
3954

40-
41-
55+
/**
56+
* `AuxRoute` is a type of {@link RouteDefinition} used to define an auxiliary route.
57+
*
58+
* It takes an object with the following properties:
59+
* - `path` is a string that uses the route matcher DSL.
60+
* - `component` a component type.
61+
* - `as` is an optional `CamelCase` string representing the name of the route.
62+
* - `data` is an optional property of any type representing arbitrary route metadata for the given
63+
* route. It is injectable via the {@link ROUTE_DATA} token.
64+
*
65+
* ## Example
66+
* ```
67+
* import {RouteConfig, AuxRoute} from 'angular2/router';
68+
*
69+
* @RouteConfig([
70+
* new AuxRoute({path: '/home', component: HomeCmp})
71+
* ])
72+
* class MyApp {}
73+
* ```
74+
*/
4275
@CONST()
4376
export class AuxRoute implements RouteDefinition {
4477
data: any = null;
@@ -55,6 +88,27 @@ export class AuxRoute implements RouteDefinition {
5588
}
5689
}
5790

91+
/**
92+
* `AsyncRoute` is a type of {@link RouteDefinition} used to route a path to an asynchronously
93+
* loaded component.
94+
*
95+
* It has the following properties:
96+
* - `path` is a string that uses the route matcher DSL.
97+
* - `loader` is a function that returns a promise that resolves to a component.
98+
* - `as` is an optional `CamelCase` string representing the name of the route.
99+
* - `data` is an optional property of any type representing arbitrary route metadata for the given
100+
* route. It is injectable via the {@link ROUTE_DATA} token.
101+
*
102+
* ## Example
103+
* ```
104+
* import {RouteConfig} from 'angular2/router';
105+
*
106+
* @RouteConfig([
107+
* {path: '/home', loader: () => Promise.resolve(MyLoadedCmp), as: 'MyLoadedCmp'}
108+
* ])
109+
* class MyApp {}
110+
* ```
111+
*/
58112
@CONST()
59113
export class AsyncRoute implements RouteDefinition {
60114
data: any;
@@ -69,6 +123,25 @@ export class AsyncRoute implements RouteDefinition {
69123
}
70124
}
71125

126+
/**
127+
* `Redirect` is a type of {@link RouteDefinition} used to route a path to an asynchronously loaded
128+
* component.
129+
*
130+
* It has the following properties:
131+
* - `path` is a string that uses the route matcher DSL.
132+
* - `redirectTo` is a string representing the new URL to be matched against.
133+
*
134+
* ## Example
135+
* ```
136+
* import {RouteConfig} from 'angular2/router';
137+
*
138+
* @RouteConfig([
139+
* {path: '/', redirectTo: '/home'},
140+
* {path: '/home', component: HomeCmp}
141+
* ])
142+
* class MyApp {}
143+
* ```
144+
*/
72145
@CONST()
73146
export class Redirect implements RouteDefinition {
74147
path: string;

modules/angular2/src/router/route_definition.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import {CONST, Type} from 'angular2/src/core/facade/lang';
22

3+
/**
4+
* `RouteDefinition` defines a route within a {@link RouteConfig} decorator.
5+
*
6+
* Supported keys:
7+
* - `path` (required)
8+
* - `component`, `loader`, `redirectTo` (requires exactly one of these)
9+
* - `as` (optional)
10+
* - `data` (optional)
11+
*
12+
* See also {@link Route}, {@link AsyncRoute}, {@link AuxRoute}, and {@link Redirect}.
13+
*/
314
export interface RouteDefinition {
415
path: string;
516
component?: Type | ComponentDefinition;

0 commit comments

Comments
 (0)