router.d.ts
13.8 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Location } from '@angular/common';
import { Compiler, Injector, NgModuleFactoryLoader, Type } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Routes } from './config';
import { DetachedRouteHandle, RouteReuseStrategy } from './route_reuse_strategy';
import { RouterOutletMap } from './router_outlet_map';
import { ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot } from './router_state';
import { Params } from './shared';
import { UrlHandlingStrategy } from './url_handling_strategy';
import { UrlSerializer, UrlTree } from './url_tree';
import { TreeNode } from './utils/tree';
/**
* @whatItDoes Represents the extra options used during navigation.
*
* @stable
*/
export interface NavigationExtras {
/**
* Enables relative navigation from the current ActivatedRoute.
*
* Configuration:
*
* ```
* [{
* path: 'parent',
* component: ParentComponent,
* children: [{
* path: 'list',
* component: ListComponent
* },{
* path: 'child',
* component: ChildComponent
* }]
* }]
* ```
*
* Navigate to list route from child route:
*
* ```
* @Component({...})
* class ChildComponent {
* constructor(private router: Router, private route: ActivatedRoute) {}
*
* go() {
* this.router.navigate(['../list'], { relativeTo: this.route });
* }
* }
* ```
*/
relativeTo?: ActivatedRoute;
/**
* Sets query parameters to the URL.
*
* ```
* // Navigate to /results?page=1
* this.router.navigate(['/results'], { queryParams: { page: 1 } });
* ```
*/
queryParams?: Params;
/**
* Sets the hash fragment for the URL.
*
* ```
* // Navigate to /results#top
* this.router.navigate(['/results'], { fragment: 'top' });
* ```
*/
fragment?: string;
/**
* Preserves the query parameters for the next navigation.
*
* ```
* // Preserve query params from /results?page=1 to /view?page=1
* this.router.navigate(['/view'], { preserveQueryParams: true });
* ```
*/
preserveQueryParams?: boolean;
/**
* Preserves the fragment for the next navigation
*
* ```
* // Preserve fragment from /results#top to /view#top
* this.router.navigate(['/view'], { preserveFragment: true });
* ```
*/
preserveFragment?: boolean;
/**
* Navigates without pushing a new state into history.
*
* ```
* // Navigate silently to /view
* this.router.navigate(['/view'], { skipLocationChange: true });
* ```
*/
skipLocationChange?: boolean;
/**
* Navigates while replacing the current state in history.
*
* ```
* // Navigate to /view
* this.router.navigate(['/view'], { replaceUrl: true });
* ```
*/
replaceUrl?: boolean;
}
/**
* @whatItDoes Represents an event triggered when a navigation starts.
*
* @stable
*/
export declare class NavigationStart {
/** @docsNotRequired */
id: number;
/** @docsNotRequired */
url: string;
constructor(
/** @docsNotRequired */
id: number,
/** @docsNotRequired */
url: string);
/** @docsNotRequired */
toString(): string;
}
/**
* @whatItDoes Represents an event triggered when a navigation ends successfully.
*
* @stable
*/
export declare class NavigationEnd {
/** @docsNotRequired */
id: number;
/** @docsNotRequired */
url: string;
/** @docsNotRequired */
urlAfterRedirects: string;
constructor(
/** @docsNotRequired */
id: number,
/** @docsNotRequired */
url: string,
/** @docsNotRequired */
urlAfterRedirects: string);
/** @docsNotRequired */
toString(): string;
}
/**
* @whatItDoes Represents an event triggered when a navigation is canceled.
*
* @stable
*/
export declare class NavigationCancel {
/** @docsNotRequired */
id: number;
/** @docsNotRequired */
url: string;
/** @docsNotRequired */
reason: string;
constructor(
/** @docsNotRequired */
id: number,
/** @docsNotRequired */
url: string,
/** @docsNotRequired */
reason: string);
/** @docsNotRequired */
toString(): string;
}
/**
* @whatItDoes Represents an event triggered when a navigation fails due to an unexpected error.
*
* @stable
*/
export declare class NavigationError {
/** @docsNotRequired */
id: number;
/** @docsNotRequired */
url: string;
/** @docsNotRequired */
error: any;
constructor(
/** @docsNotRequired */
id: number,
/** @docsNotRequired */
url: string,
/** @docsNotRequired */
error: any);
/** @docsNotRequired */
toString(): string;
}
/**
* @whatItDoes Represents an event triggered when routes are recognized.
*
* @stable
*/
export declare class RoutesRecognized {
/** @docsNotRequired */
id: number;
/** @docsNotRequired */
url: string;
/** @docsNotRequired */
urlAfterRedirects: string;
/** @docsNotRequired */
state: RouterStateSnapshot;
constructor(
/** @docsNotRequired */
id: number,
/** @docsNotRequired */
url: string,
/** @docsNotRequired */
urlAfterRedirects: string,
/** @docsNotRequired */
state: RouterStateSnapshot);
/** @docsNotRequired */
toString(): string;
}
/**
* @whatItDoes Represents a router event.
*
* Please see {@link NavigationStart}, {@link NavigationEnd}, {@link NavigationCancel}, {@link
* NavigationError},
* {@link RoutesRecognized} for more information.
*
* @stable
*/
export declare type Event = NavigationStart | NavigationEnd | NavigationCancel | NavigationError | RoutesRecognized;
/**
* @whatItDoes Error handler that is invoked when a navigation errors.
*
* @description
* If the handler returns a value, the navigation promise will be resolved with this value.
* If the handler throws an exception, the navigation promise will be rejected with
* the exception.
*
* @stable
*/
export declare type ErrorHandler = (error: any) => any;
/**
* Does not detach any subtrees. Reuses routes as long as their route config is the same.
*/
export declare class DefaultRouteReuseStrategy implements RouteReuseStrategy {
shouldDetach(route: ActivatedRouteSnapshot): boolean;
store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void;
shouldAttach(route: ActivatedRouteSnapshot): boolean;
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle;
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean;
}
/**
* @whatItDoes Provides the navigation and url manipulation capabilities.
*
* See {@link Routes} for more details and examples.
*
* @ngModule RouterModule
*
* @stable
*/
export declare class Router {
private rootComponentType;
private urlSerializer;
private outletMap;
private location;
private injector;
config: Routes;
private currentUrlTree;
private rawUrlTree;
private navigations;
private routerEvents;
private currentRouterState;
private locationSubscription;
private navigationId;
private configLoader;
/**
* Error handler that is invoked when a navigation errors.
*
* See {@link ErrorHandler} for more information.
*/
errorHandler: ErrorHandler;
/**
* Indicates if at least one navigation happened.
*/
navigated: boolean;
/**
* Extracts and merges URLs. Used for Angular 1 to Angular 2 migrations.
*/
urlHandlingStrategy: UrlHandlingStrategy;
routeReuseStrategy: RouteReuseStrategy;
/**
* Creates the router service.
*/
constructor(rootComponentType: Type<any>, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Routes);
/**
* Sets up the location change listener and performs the initial navigation.
*/
initialNavigation(): void;
/**
* Sets up the location change listener.
*/
setUpLocationChangeListener(): void;
/** The current route state */
routerState: RouterState;
/** The current url */
url: string;
/** An observable of router events */
events: Observable<Event>;
/**
* Resets the configuration used for navigation and generating links.
*
* ### Usage
*
* ```
* router.resetConfig([
* { path: 'team/:id', component: TeamCmp, children: [
* { path: 'simple', component: SimpleCmp },
* { path: 'user/:name', component: UserCmp }
* ]}
* ]);
* ```
*/
resetConfig(config: Routes): void;
/** @docsNotRequired */
ngOnDestroy(): void;
/** Disposes of the router */
dispose(): void;
/**
* Applies an array of commands to the current url tree and creates a new url tree.
*
* When given an activate route, applies the given commands starting from the route.
* When not given a route, applies the given command starting from the root.
*
* ### Usage
*
* ```
* // create /team/33/user/11
* router.createUrlTree(['/team', 33, 'user', 11]);
*
* // create /team/33;expand=true/user/11
* router.createUrlTree(['/team', 33, {expand: true}, 'user', 11]);
*
* // you can collapse static segments like this (this works only with the first passed-in value):
* router.createUrlTree(['/team/33/user', userId]);
*
* // If the first segment can contain slashes, and you do not want the router to split it, you
* // can do the following:
*
* router.createUrlTree([{segmentPath: '/one/two'}]);
*
* // create /team/33/(user/11//right:chat)
* router.createUrlTree(['/team', 33, {outlets: {primary: 'user/11', right: 'chat'}}]);
*
* // remove the right secondary node
* router.createUrlTree(['/team', 33, {outlets: {primary: 'user/11', right: null}}]);
*
* // assuming the current url is `/team/33/user/11` and the route points to `user/11`
*
* // navigate to /team/33/user/11/details
* router.createUrlTree(['details'], {relativeTo: route});
*
* // navigate to /team/33/user/22
* router.createUrlTree(['../22'], {relativeTo: route});
*
* // navigate to /team/44/user/22
* router.createUrlTree(['../../team/44/user/22'], {relativeTo: route});
* ```
*/
createUrlTree(commands: any[], {relativeTo, queryParams, fragment, preserveQueryParams, preserveFragment}?: NavigationExtras): UrlTree;
/**
* Navigate based on the provided url. This navigation is always absolute.
*
* Returns a promise that:
* - resolves to 'true' when navigation succeeds,
* - resolves to 'false' when navigation fails,
* - is rejected when an error happens.
*
* ### Usage
*
* ```
* router.navigateByUrl("/team/33/user/11");
*
* // Navigate without updating the URL
* router.navigateByUrl("/team/33/user/11", { skipLocationChange: true });
* ```
*
* In opposite to `navigate`, `navigateByUrl` takes a whole URL
* and does not apply any delta to the current one.
*/
navigateByUrl(url: string | UrlTree, extras?: NavigationExtras): Promise<boolean>;
/**
* Navigate based on the provided array of commands and a starting point.
* If no starting route is provided, the navigation is absolute.
*
* Returns a promise that:
* - resolves to 'true' when navigation succeeds,
* - resolves to 'false' when navigation fails,
* - is rejected when an error happens.
*
* ### Usage
*
* ```
* router.navigate(['team', 33, 'user', 11], {relativeTo: route});
*
* // Navigate without updating the URL
* router.navigate(['team', 33, 'user', 11], {relativeTo: route, skipLocationChange: true});
* ```
*
* In opposite to `navigateByUrl`, `navigate` always takes a delta that is applied to the current
* URL.
*/
navigate(commands: any[], extras?: NavigationExtras): Promise<boolean>;
/** Serializes a {@link UrlTree} into a string */
serializeUrl(url: UrlTree): string;
/** Parses a string into a {@link UrlTree} */
parseUrl(url: string): UrlTree;
/** Returns whether the url is activated */
isActive(url: string | UrlTree, exact: boolean): boolean;
private removeEmptyProps(params);
private processNavigations();
private scheduleNavigation(rawUrl, source, extras);
private executeScheduledNavigation({id, rawUrl, extras, resolve, reject});
private runNavigate(url, rawUrl, shouldPreventPushState, shouldReplaceUrl, id, precreatedState);
private resetUrlToCurrentUrlTree();
}
export declare class PreActivation {
private future;
private curr;
private injector;
private checks;
constructor(future: RouterStateSnapshot, curr: RouterStateSnapshot, injector: Injector);
traverse(parentOutletMap: RouterOutletMap): void;
checkGuards(): Observable<boolean>;
resolveData(): Observable<any>;
private traverseChildRoutes(futureNode, currNode, outletMap, futurePath);
traverseRoutes(futureNode: TreeNode<ActivatedRouteSnapshot>, currNode: TreeNode<ActivatedRouteSnapshot>, parentOutletMap: RouterOutletMap, futurePath: ActivatedRouteSnapshot[]): void;
private deactiveRouteAndItsChildren(route, outlet);
private runCanActivate(future);
private runCanActivateChild(path);
private extractCanActivateChild(p);
private runCanDeactivate(component, curr);
private runResolve(future);
private resolveNode(resolve, future);
private getToken(token, snapshot);
}