router_link.js
10.7 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
/**
* @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 { LocationStrategy } from '@angular/common';
import { Directive, HostBinding, HostListener, Input } from '@angular/core';
import { NavigationEnd, Router } from '../router';
import { ActivatedRoute } from '../router_state';
/**
* \@whatItDoes Lets you link to specific parts of your app.
*
* \@howToUse
*
* Consider the following route configuration:
* `[{ path: 'user/:name', component: UserCmp }]`
*
* When linking to this `user/:name` route, you can write:
* `<a routerLink='/user/bob'>link to user component</a>`
*
* \@description
*
* The RouterLink directives let you link to specific parts of your app.
*
* When the link is static, you can use the directive as follows:
* `<a routerLink="/user/bob">link to user component</a>`
*
* If you use dynamic values to generate the link, you can pass an array of path
* segments, followed by the params for each segment.
*
* For instance `['/team', teamId, 'user', userName, {details: true}]`
* means that we want to generate a link to `/team/11/user/bob;details=true`.
*
* Multiple static segments can be merged into one
* (e.g., `['/team/11/user', userName, {details: true}]`).
*
* The first segment name can be prepended with `/`, `./`, or `../`:
* * If the first segment begins with `/`, the router will look up the route from the root of the
* app.
* * If the first segment begins with `./`, or doesn't begin with a slash, the router will
* instead look in the children of the current activated route.
* * And if the first segment begins with `../`, the router will go up one level.
*
* You can set query params and fragment as follows:
*
* ```
* <a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" fragment="education">
* link to user component
* </a>
* ```
* RouterLink will use these to generate this link: `/user/bob#education?debug=true`.
*
* You can also tell the directive to preserve the current query params and fragment:
*
* ```
* <a [routerLink]="['/user/bob']" preserveQueryParams preserveFragment>
* link to user component
* </a>
* ```
*
* The router link directive always treats the provided input as a delta to the current url.
*
* For instance, if the current url is `/user/(box//aux:team)`.
*
* Then the following link `<a [routerLink]="['/user/jim']">Jim</a>` will generate the link
* `/user/(jim//aux:team)`.
*
* \@selector ':not(a)[routerLink]'
* \@ngModule RouterModule
*
* See {\@link Router.createUrlTree} for more information.
*
* \@stable
*/
export var RouterLink = (function () {
/**
* @param {?} router
* @param {?} route
*/
function RouterLink(router, route) {
this.router = router;
this.route = route;
this.commands = [];
}
Object.defineProperty(RouterLink.prototype, "routerLink", {
/**
* @param {?} commands
* @return {?}
*/
set: function (commands) {
if (commands != null) {
this.commands = Array.isArray(commands) ? commands : [commands];
}
else {
this.commands = [];
}
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
RouterLink.prototype.onClick = function () {
var /** @type {?} */ extras = {
skipLocationChange: attrBoolValue(this.skipLocationChange),
replaceUrl: attrBoolValue(this.replaceUrl),
};
this.router.navigateByUrl(this.urlTree, extras);
return true;
};
Object.defineProperty(RouterLink.prototype, "urlTree", {
/**
* @return {?}
*/
get: function () {
return this.router.createUrlTree(this.commands, {
relativeTo: this.route,
queryParams: this.queryParams,
fragment: this.fragment,
preserveQueryParams: attrBoolValue(this.preserveQueryParams),
preserveFragment: attrBoolValue(this.preserveFragment),
});
},
enumerable: true,
configurable: true
});
RouterLink.decorators = [
{ type: Directive, args: [{ selector: ':not(a)[routerLink]' },] },
];
/** @nocollapse */
RouterLink.ctorParameters = function () { return [
{ type: Router, },
{ type: ActivatedRoute, },
]; };
RouterLink.propDecorators = {
'queryParams': [{ type: Input },],
'fragment': [{ type: Input },],
'preserveQueryParams': [{ type: Input },],
'preserveFragment': [{ type: Input },],
'skipLocationChange': [{ type: Input },],
'replaceUrl': [{ type: Input },],
'routerLink': [{ type: Input },],
'onClick': [{ type: HostListener, args: ['click',] },],
};
return RouterLink;
}());
function RouterLink_tsickle_Closure_declarations() {
/** @type {?} */
RouterLink.decorators;
/**
* @nocollapse
* @type {?}
*/
RouterLink.ctorParameters;
/** @type {?} */
RouterLink.propDecorators;
/** @type {?} */
RouterLink.prototype.queryParams;
/** @type {?} */
RouterLink.prototype.fragment;
/** @type {?} */
RouterLink.prototype.preserveQueryParams;
/** @type {?} */
RouterLink.prototype.preserveFragment;
/** @type {?} */
RouterLink.prototype.skipLocationChange;
/** @type {?} */
RouterLink.prototype.replaceUrl;
/** @type {?} */
RouterLink.prototype.commands;
/** @type {?} */
RouterLink.prototype.router;
/** @type {?} */
RouterLink.prototype.route;
}
/**
* \@whatItDoes Lets you link to specific parts of your app.
*
* See {\@link RouterLink} for more information.
*
* \@selector 'a[routerLink]'
* \@ngModule RouterModule
*
* \@stable
*/
export var RouterLinkWithHref = (function () {
/**
* @param {?} router
* @param {?} route
* @param {?} locationStrategy
*/
function RouterLinkWithHref(router, route, locationStrategy) {
var _this = this;
this.router = router;
this.route = route;
this.locationStrategy = locationStrategy;
this.commands = [];
this.subscription = router.events.subscribe(function (s) {
if (s instanceof NavigationEnd) {
_this.updateTargetUrlAndHref();
}
});
}
Object.defineProperty(RouterLinkWithHref.prototype, "routerLink", {
/**
* @param {?} commands
* @return {?}
*/
set: function (commands) {
if (commands != null) {
this.commands = Array.isArray(commands) ? commands : [commands];
}
else {
this.commands = [];
}
},
enumerable: true,
configurable: true
});
/**
* @param {?} changes
* @return {?}
*/
RouterLinkWithHref.prototype.ngOnChanges = function (changes) { this.updateTargetUrlAndHref(); };
/**
* @return {?}
*/
RouterLinkWithHref.prototype.ngOnDestroy = function () { this.subscription.unsubscribe(); };
/**
* @param {?} button
* @param {?} ctrlKey
* @param {?} metaKey
* @return {?}
*/
RouterLinkWithHref.prototype.onClick = function (button, ctrlKey, metaKey) {
if (button !== 0 || ctrlKey || metaKey) {
return true;
}
if (typeof this.target === 'string' && this.target != '_self') {
return true;
}
var /** @type {?} */ extras = {
skipLocationChange: attrBoolValue(this.skipLocationChange),
replaceUrl: attrBoolValue(this.replaceUrl),
};
this.router.navigateByUrl(this.urlTree, extras);
return false;
};
/**
* @return {?}
*/
RouterLinkWithHref.prototype.updateTargetUrlAndHref = function () {
this.href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.urlTree));
};
Object.defineProperty(RouterLinkWithHref.prototype, "urlTree", {
/**
* @return {?}
*/
get: function () {
return this.router.createUrlTree(this.commands, {
relativeTo: this.route,
queryParams: this.queryParams,
fragment: this.fragment,
preserveQueryParams: attrBoolValue(this.preserveQueryParams),
preserveFragment: attrBoolValue(this.preserveFragment),
});
},
enumerable: true,
configurable: true
});
RouterLinkWithHref.decorators = [
{ type: Directive, args: [{ selector: 'a[routerLink]' },] },
];
/** @nocollapse */
RouterLinkWithHref.ctorParameters = function () { return [
{ type: Router, },
{ type: ActivatedRoute, },
{ type: LocationStrategy, },
]; };
RouterLinkWithHref.propDecorators = {
'target': [{ type: HostBinding, args: ['attr.target',] }, { type: Input },],
'queryParams': [{ type: Input },],
'fragment': [{ type: Input },],
'preserveQueryParams': [{ type: Input },],
'preserveFragment': [{ type: Input },],
'skipLocationChange': [{ type: Input },],
'replaceUrl': [{ type: Input },],
'href': [{ type: HostBinding },],
'routerLink': [{ type: Input },],
'onClick': [{ type: HostListener, args: ['click', ['$event.button', '$event.ctrlKey', '$event.metaKey'],] },],
};
return RouterLinkWithHref;
}());
function RouterLinkWithHref_tsickle_Closure_declarations() {
/** @type {?} */
RouterLinkWithHref.decorators;
/**
* @nocollapse
* @type {?}
*/
RouterLinkWithHref.ctorParameters;
/** @type {?} */
RouterLinkWithHref.propDecorators;
/** @type {?} */
RouterLinkWithHref.prototype.target;
/** @type {?} */
RouterLinkWithHref.prototype.queryParams;
/** @type {?} */
RouterLinkWithHref.prototype.fragment;
/** @type {?} */
RouterLinkWithHref.prototype.preserveQueryParams;
/** @type {?} */
RouterLinkWithHref.prototype.preserveFragment;
/** @type {?} */
RouterLinkWithHref.prototype.skipLocationChange;
/** @type {?} */
RouterLinkWithHref.prototype.replaceUrl;
/** @type {?} */
RouterLinkWithHref.prototype.commands;
/** @type {?} */
RouterLinkWithHref.prototype.subscription;
/** @type {?} */
RouterLinkWithHref.prototype.href;
/** @type {?} */
RouterLinkWithHref.prototype.router;
/** @type {?} */
RouterLinkWithHref.prototype.route;
/** @type {?} */
RouterLinkWithHref.prototype.locationStrategy;
}
/**
* @param {?} s
* @return {?}
*/
function attrBoolValue(s) {
return s === '' || !!s;
}
//# sourceMappingURL=router_link.js.map