UNPKG

6.03 kBTypeScriptView Raw
1/**
2 * `RouteParams` is an immutable map of parameters for the given route
3 * based on the url matcher and optional parameters for that route.
4 *
5 * You can inject `RouteParams` into the constructor of a component to use it.
6 *
7 * ### Example
8 *
9 * ```
10 * import {Component} from '@angular/core';
11 * import {bootstrap} from '@angular/platform-browser/browser';
12 * import {Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, RouteParams} from
13 * 'angular2/router';
14 *
15 * @Component({directives: [ROUTER_DIRECTIVES]})
16 * @RouteConfig([
17 * {path: '/user/:id', component: UserCmp, name: 'UserCmp'},
18 * ])
19 * class AppCmp {}
20 *
21 * @Component({ template: 'user: {{id}}' })
22 * class UserCmp {
23 * id: string;
24 * constructor(params: RouteParams) {
25 * this.id = params.get('id');
26 * }
27 * }
28 *
29 * bootstrap(AppCmp, ROUTER_PROVIDERS);
30 * ```
31 */
32export declare class RouteParams {
33 params: {
34 [key: string]: string;
35 };
36 constructor(params: {
37 [key: string]: string;
38 });
39 get(param: string): string;
40}
41/**
42 * `RouteData` is an immutable map of additional data you can configure in your {@link Route}.
43 *
44 * You can inject `RouteData` into the constructor of a component to use it.
45 *
46 * ### Example
47 *
48 * ```
49 * import {Component} from '@angular/core';
50 * import {bootstrap} from '@angular/platform-browser/browser';
51 * import {Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, RouteData} from
52 * 'angular2/router';
53 *
54 * @Component({directives: [ROUTER_DIRECTIVES]})
55 * @RouteConfig([
56 * {path: '/user/:id', component: UserCmp, name: 'UserCmp', data: {isAdmin: true}},
57 * ])
58 * class AppCmp {}
59 *
60 * @Component({
61 * ...,
62 * template: 'user: {{isAdmin}}'
63 * })
64 * class UserCmp {
65 * string: isAdmin;
66 * constructor(data: RouteData) {
67 * this.isAdmin = data.get('isAdmin');
68 * }
69 * }
70 *
71 * bootstrap(AppCmp, ROUTER_PROVIDERS);
72 * ```
73 */
74export declare class RouteData {
75 data: {
76 [key: string]: any;
77 };
78 constructor(data?: {
79 [key: string]: any;
80 });
81 get(key: string): any;
82}
83export declare var BLANK_ROUTE_DATA: RouteData;
84/**
85 * `Instruction` is a tree of {@link ComponentInstruction}s with all the information needed
86 * to transition each component in the app to a given route, including all auxiliary routes.
87 *
88 * `Instruction`s can be created using {@link Router#generate}, and can be used to
89 * perform route changes with {@link Router#navigateByInstruction}.
90 *
91 * ### Example
92 *
93 * ```
94 * import {Component} from '@angular/core';
95 * import {bootstrap} from '@angular/platform-browser/browser';
96 * import {Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig} from
97 * '@angular/router-deprecated';
98 *
99 * @Component({directives: [ROUTER_DIRECTIVES]})
100 * @RouteConfig([
101 * {...},
102 * ])
103 * class AppCmp {
104 * constructor(router: Router) {
105 * var instruction = router.generate(['/MyRoute']);
106 * router.navigateByInstruction(instruction);
107 * }
108 * }
109 *
110 * bootstrap(AppCmp, ROUTER_PROVIDERS);
111 * ```
112 */
113export declare abstract class Instruction {
114 component: ComponentInstruction;
115 child: Instruction;
116 auxInstruction: {
117 [key: string]: Instruction;
118 };
119 constructor(component: ComponentInstruction, child: Instruction, auxInstruction: {
120 [key: string]: Instruction;
121 });
122 urlPath: string;
123 urlParams: string[];
124 specificity: string;
125 abstract resolveComponent(): Promise<ComponentInstruction>;
126 /**
127 * converts the instruction into a URL string
128 */
129 toRootUrl(): string;
130 toUrlQuery(): string;
131 /**
132 * Returns a new instruction that shares the state of the existing instruction, but with
133 * the given child {@link Instruction} replacing the existing child.
134 */
135 replaceChild(child: Instruction): Instruction;
136 /**
137 * If the final URL for the instruction is ``
138 */
139 toUrlPath(): string;
140 toLinkUrl(): string;
141}
142/**
143 * a resolved instruction has an outlet instruction for itself, but maybe not for...
144 */
145export declare class ResolvedInstruction extends Instruction {
146 constructor(component: ComponentInstruction, child: Instruction, auxInstruction: {
147 [key: string]: Instruction;
148 });
149 resolveComponent(): Promise<ComponentInstruction>;
150}
151/**
152 * Represents a resolved default route
153 */
154export declare class DefaultInstruction extends ResolvedInstruction {
155 constructor(component: ComponentInstruction, child: DefaultInstruction);
156 toLinkUrl(): string;
157}
158/**
159 * Represents a component that may need to do some redirection or lazy loading at a later time.
160 */
161export declare class UnresolvedInstruction extends Instruction {
162 private _resolver;
163 private _urlPath;
164 private _urlParams;
165 constructor(_resolver: () => Promise<Instruction>, _urlPath?: string, _urlParams?: string[]);
166 urlPath: string;
167 urlParams: string[];
168 resolveComponent(): Promise<ComponentInstruction>;
169}
170export declare class RedirectInstruction extends ResolvedInstruction {
171 private _specificity;
172 constructor(component: ComponentInstruction, child: Instruction, auxInstruction: {
173 [key: string]: Instruction;
174 }, _specificity: string);
175 specificity: string;
176}
177/**
178 * A `ComponentInstruction` represents the route state for a single component.
179 *
180 * `ComponentInstructions` is a public API. Instances of `ComponentInstruction` are passed
181 * to route lifecycle hooks, like {@link CanActivate}.
182 *
183 * `ComponentInstruction`s are [hash consed](https://en.wikipedia.org/wiki/Hash_consing). You should
184 * never construct one yourself with "new." Instead, rely on router's internal recognizer to
185 * construct `ComponentInstruction`s.
186 *
187 * You should not modify this object. It should be treated as immutable.
188 */
189export declare class ComponentInstruction {
190 urlPath: string;
191 urlParams: string[];
192 componentType: any;
193 terminal: boolean;
194 specificity: string;
195 params: {
196 [key: string]: string;
197 };
198 routeName: string;
199 reuse: boolean;
200 routeData: RouteData;
201}
202
\No newline at end of file