UNPKG

273 kBJavaScriptView Raw
1/**
2 * @license Angular v10.0.3
3 * (c) 2010-2020 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7(function (global, factory) {
8 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('rxjs'), require('rxjs/operators')) :
9 typeof define === 'function' && define.amd ? define('@angular/router', ['exports', '@angular/common', '@angular/core', 'rxjs', 'rxjs/operators'], factory) :
10 (global = global || self, factory((global.ng = global.ng || {}, global.ng.router = {}), global.ng.common, global.ng.core, global.rxjs, global.rxjs.operators));
11}(this, (function (exports, common, core, rxjs, operators) { 'use strict';
12
13 /*! *****************************************************************************
14 Copyright (c) Microsoft Corporation.
15
16 Permission to use, copy, modify, and/or distribute this software for any
17 purpose with or without fee is hereby granted.
18
19 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25 PERFORMANCE OF THIS SOFTWARE.
26 ***************************************************************************** */
27 /* global Reflect, Promise */
28
29 var extendStatics = function(d, b) {
30 extendStatics = Object.setPrototypeOf ||
31 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
32 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
33 return extendStatics(d, b);
34 };
35
36 function __extends(d, b) {
37 extendStatics(d, b);
38 function __() { this.constructor = d; }
39 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
40 }
41
42 var __assign = function() {
43 __assign = Object.assign || function __assign(t) {
44 for (var s, i = 1, n = arguments.length; i < n; i++) {
45 s = arguments[i];
46 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
47 }
48 return t;
49 };
50 return __assign.apply(this, arguments);
51 };
52
53 function __rest(s, e) {
54 var t = {};
55 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
56 t[p] = s[p];
57 if (s != null && typeof Object.getOwnPropertySymbols === "function")
58 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
59 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
60 t[p[i]] = s[p[i]];
61 }
62 return t;
63 }
64
65 function __decorate(decorators, target, key, desc) {
66 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
67 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
68 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
69 return c > 3 && r && Object.defineProperty(target, key, r), r;
70 }
71
72 function __param(paramIndex, decorator) {
73 return function (target, key) { decorator(target, key, paramIndex); }
74 }
75
76 function __metadata(metadataKey, metadataValue) {
77 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
78 }
79
80 function __awaiter(thisArg, _arguments, P, generator) {
81 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
82 return new (P || (P = Promise))(function (resolve, reject) {
83 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
84 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
85 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
86 step((generator = generator.apply(thisArg, _arguments || [])).next());
87 });
88 }
89
90 function __generator(thisArg, body) {
91 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
92 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
93 function verb(n) { return function (v) { return step([n, v]); }; }
94 function step(op) {
95 if (f) throw new TypeError("Generator is already executing.");
96 while (_) try {
97 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
98 if (y = 0, t) op = [op[0] & 2, t.value];
99 switch (op[0]) {
100 case 0: case 1: t = op; break;
101 case 4: _.label++; return { value: op[1], done: false };
102 case 5: _.label++; y = op[1]; op = [0]; continue;
103 case 7: op = _.ops.pop(); _.trys.pop(); continue;
104 default:
105 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
106 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
107 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
108 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
109 if (t[2]) _.ops.pop();
110 _.trys.pop(); continue;
111 }
112 op = body.call(thisArg, _);
113 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
114 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
115 }
116 }
117
118 var __createBinding = Object.create ? (function(o, m, k, k2) {
119 if (k2 === undefined) k2 = k;
120 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
121 }) : (function(o, m, k, k2) {
122 if (k2 === undefined) k2 = k;
123 o[k2] = m[k];
124 });
125
126 function __exportStar(m, exports) {
127 for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
128 }
129
130 function __values(o) {
131 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
132 if (m) return m.call(o);
133 if (o && typeof o.length === "number") return {
134 next: function () {
135 if (o && i >= o.length) o = void 0;
136 return { value: o && o[i++], done: !o };
137 }
138 };
139 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
140 }
141
142 function __read(o, n) {
143 var m = typeof Symbol === "function" && o[Symbol.iterator];
144 if (!m) return o;
145 var i = m.call(o), r, ar = [], e;
146 try {
147 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
148 }
149 catch (error) { e = { error: error }; }
150 finally {
151 try {
152 if (r && !r.done && (m = i["return"])) m.call(i);
153 }
154 finally { if (e) throw e.error; }
155 }
156 return ar;
157 }
158
159 function __spread() {
160 for (var ar = [], i = 0; i < arguments.length; i++)
161 ar = ar.concat(__read(arguments[i]));
162 return ar;
163 }
164
165 function __spreadArrays() {
166 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
167 for (var r = Array(s), k = 0, i = 0; i < il; i++)
168 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
169 r[k] = a[j];
170 return r;
171 };
172
173 function __await(v) {
174 return this instanceof __await ? (this.v = v, this) : new __await(v);
175 }
176
177 function __asyncGenerator(thisArg, _arguments, generator) {
178 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
179 var g = generator.apply(thisArg, _arguments || []), i, q = [];
180 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
181 function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
182 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
183 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
184 function fulfill(value) { resume("next", value); }
185 function reject(value) { resume("throw", value); }
186 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
187 }
188
189 function __asyncDelegator(o) {
190 var i, p;
191 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
192 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
193 }
194
195 function __asyncValues(o) {
196 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
197 var m = o[Symbol.asyncIterator], i;
198 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
199 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
200 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
201 }
202
203 function __makeTemplateObject(cooked, raw) {
204 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
205 return cooked;
206 };
207
208 var __setModuleDefault = Object.create ? (function(o, v) {
209 Object.defineProperty(o, "default", { enumerable: true, value: v });
210 }) : function(o, v) {
211 o["default"] = v;
212 };
213
214 function __importStar(mod) {
215 if (mod && mod.__esModule) return mod;
216 var result = {};
217 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
218 __setModuleDefault(result, mod);
219 return result;
220 }
221
222 function __importDefault(mod) {
223 return (mod && mod.__esModule) ? mod : { default: mod };
224 }
225
226 function __classPrivateFieldGet(receiver, privateMap) {
227 if (!privateMap.has(receiver)) {
228 throw new TypeError("attempted to get private field on non-instance");
229 }
230 return privateMap.get(receiver);
231 }
232
233 function __classPrivateFieldSet(receiver, privateMap, value) {
234 if (!privateMap.has(receiver)) {
235 throw new TypeError("attempted to set private field on non-instance");
236 }
237 privateMap.set(receiver, value);
238 return value;
239 }
240
241 /**
242 * @license
243 * Copyright Google LLC All Rights Reserved.
244 *
245 * Use of this source code is governed by an MIT-style license that can be
246 * found in the LICENSE file at https://angular.io/license
247 */
248 /**
249 * Base for events the router goes through, as opposed to events tied to a specific
250 * route. Fired one time for any given navigation.
251 *
252 * @usageNotes
253 *
254 * ```ts
255 * class MyService {
256 * constructor(public router: Router, logger: Logger) {
257 * router.events.pipe(
258 * filter((e: Event): e is RouterEvent => e instanceof RouterEvent)
259 * ).subscribe((e: RouterEvent) => {
260 * logger.log(e.id, e.url);
261 * });
262 * }
263 * }
264 * ```
265 *
266 * @see `Event`
267 * @publicApi
268 */
269 var RouterEvent = /** @class */ (function () {
270 function RouterEvent(
271 /** A unique ID that the router assigns to every router navigation. */
272 id,
273 /** The URL that is the destination for this navigation. */
274 url) {
275 this.id = id;
276 this.url = url;
277 }
278 return RouterEvent;
279 }());
280 /**
281 * An event triggered when a navigation starts.
282 *
283 * @publicApi
284 */
285 var NavigationStart = /** @class */ (function (_super) {
286 __extends(NavigationStart, _super);
287 function NavigationStart(
288 /** @docsNotRequired */
289 id,
290 /** @docsNotRequired */
291 url,
292 /** @docsNotRequired */
293 navigationTrigger,
294 /** @docsNotRequired */
295 restoredState) {
296 if (navigationTrigger === void 0) { navigationTrigger = 'imperative'; }
297 if (restoredState === void 0) { restoredState = null; }
298 var _this = _super.call(this, id, url) || this;
299 _this.navigationTrigger = navigationTrigger;
300 _this.restoredState = restoredState;
301 return _this;
302 }
303 /** @docsNotRequired */
304 NavigationStart.prototype.toString = function () {
305 return "NavigationStart(id: " + this.id + ", url: '" + this.url + "')";
306 };
307 return NavigationStart;
308 }(RouterEvent));
309 /**
310 * An event triggered when a navigation ends successfully.
311 *
312 * @publicApi
313 */
314 var NavigationEnd = /** @class */ (function (_super) {
315 __extends(NavigationEnd, _super);
316 function NavigationEnd(
317 /** @docsNotRequired */
318 id,
319 /** @docsNotRequired */
320 url,
321 /** @docsNotRequired */
322 urlAfterRedirects) {
323 var _this = _super.call(this, id, url) || this;
324 _this.urlAfterRedirects = urlAfterRedirects;
325 return _this;
326 }
327 /** @docsNotRequired */
328 NavigationEnd.prototype.toString = function () {
329 return "NavigationEnd(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "')";
330 };
331 return NavigationEnd;
332 }(RouterEvent));
333 /**
334 * An event triggered when a navigation is canceled, directly or indirectly.
335 *
336 * This can happen when a [route guard](guide/router#milestone-5-route-guards)
337 * returns `false` or initiates a redirect by returning a `UrlTree`.
338 *
339 * @publicApi
340 */
341 var NavigationCancel = /** @class */ (function (_super) {
342 __extends(NavigationCancel, _super);
343 function NavigationCancel(
344 /** @docsNotRequired */
345 id,
346 /** @docsNotRequired */
347 url,
348 /** @docsNotRequired */
349 reason) {
350 var _this = _super.call(this, id, url) || this;
351 _this.reason = reason;
352 return _this;
353 }
354 /** @docsNotRequired */
355 NavigationCancel.prototype.toString = function () {
356 return "NavigationCancel(id: " + this.id + ", url: '" + this.url + "')";
357 };
358 return NavigationCancel;
359 }(RouterEvent));
360 /**
361 * An event triggered when a navigation fails due to an unexpected error.
362 *
363 * @publicApi
364 */
365 var NavigationError = /** @class */ (function (_super) {
366 __extends(NavigationError, _super);
367 function NavigationError(
368 /** @docsNotRequired */
369 id,
370 /** @docsNotRequired */
371 url,
372 /** @docsNotRequired */
373 error) {
374 var _this = _super.call(this, id, url) || this;
375 _this.error = error;
376 return _this;
377 }
378 /** @docsNotRequired */
379 NavigationError.prototype.toString = function () {
380 return "NavigationError(id: " + this.id + ", url: '" + this.url + "', error: " + this.error + ")";
381 };
382 return NavigationError;
383 }(RouterEvent));
384 /**
385 *An event triggered when routes are recognized.
386 *
387 * @publicApi
388 */
389 var RoutesRecognized = /** @class */ (function (_super) {
390 __extends(RoutesRecognized, _super);
391 function RoutesRecognized(
392 /** @docsNotRequired */
393 id,
394 /** @docsNotRequired */
395 url,
396 /** @docsNotRequired */
397 urlAfterRedirects,
398 /** @docsNotRequired */
399 state) {
400 var _this = _super.call(this, id, url) || this;
401 _this.urlAfterRedirects = urlAfterRedirects;
402 _this.state = state;
403 return _this;
404 }
405 /** @docsNotRequired */
406 RoutesRecognized.prototype.toString = function () {
407 return "RoutesRecognized(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")";
408 };
409 return RoutesRecognized;
410 }(RouterEvent));
411 /**
412 * An event triggered at the start of the Guard phase of routing.
413 *
414 * @publicApi
415 */
416 var GuardsCheckStart = /** @class */ (function (_super) {
417 __extends(GuardsCheckStart, _super);
418 function GuardsCheckStart(
419 /** @docsNotRequired */
420 id,
421 /** @docsNotRequired */
422 url,
423 /** @docsNotRequired */
424 urlAfterRedirects,
425 /** @docsNotRequired */
426 state) {
427 var _this = _super.call(this, id, url) || this;
428 _this.urlAfterRedirects = urlAfterRedirects;
429 _this.state = state;
430 return _this;
431 }
432 GuardsCheckStart.prototype.toString = function () {
433 return "GuardsCheckStart(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")";
434 };
435 return GuardsCheckStart;
436 }(RouterEvent));
437 /**
438 * An event triggered at the end of the Guard phase of routing.
439 *
440 * @publicApi
441 */
442 var GuardsCheckEnd = /** @class */ (function (_super) {
443 __extends(GuardsCheckEnd, _super);
444 function GuardsCheckEnd(
445 /** @docsNotRequired */
446 id,
447 /** @docsNotRequired */
448 url,
449 /** @docsNotRequired */
450 urlAfterRedirects,
451 /** @docsNotRequired */
452 state,
453 /** @docsNotRequired */
454 shouldActivate) {
455 var _this = _super.call(this, id, url) || this;
456 _this.urlAfterRedirects = urlAfterRedirects;
457 _this.state = state;
458 _this.shouldActivate = shouldActivate;
459 return _this;
460 }
461 GuardsCheckEnd.prototype.toString = function () {
462 return "GuardsCheckEnd(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ", shouldActivate: " + this.shouldActivate + ")";
463 };
464 return GuardsCheckEnd;
465 }(RouterEvent));
466 /**
467 * An event triggered at the the start of the Resolve phase of routing.
468 *
469 * Runs in the "resolve" phase whether or not there is anything to resolve.
470 * In future, may change to only run when there are things to be resolved.
471 *
472 * @publicApi
473 */
474 var ResolveStart = /** @class */ (function (_super) {
475 __extends(ResolveStart, _super);
476 function ResolveStart(
477 /** @docsNotRequired */
478 id,
479 /** @docsNotRequired */
480 url,
481 /** @docsNotRequired */
482 urlAfterRedirects,
483 /** @docsNotRequired */
484 state) {
485 var _this = _super.call(this, id, url) || this;
486 _this.urlAfterRedirects = urlAfterRedirects;
487 _this.state = state;
488 return _this;
489 }
490 ResolveStart.prototype.toString = function () {
491 return "ResolveStart(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")";
492 };
493 return ResolveStart;
494 }(RouterEvent));
495 /**
496 * An event triggered at the end of the Resolve phase of routing.
497 * @see `ResolveStart`.
498 *
499 * @publicApi
500 */
501 var ResolveEnd = /** @class */ (function (_super) {
502 __extends(ResolveEnd, _super);
503 function ResolveEnd(
504 /** @docsNotRequired */
505 id,
506 /** @docsNotRequired */
507 url,
508 /** @docsNotRequired */
509 urlAfterRedirects,
510 /** @docsNotRequired */
511 state) {
512 var _this = _super.call(this, id, url) || this;
513 _this.urlAfterRedirects = urlAfterRedirects;
514 _this.state = state;
515 return _this;
516 }
517 ResolveEnd.prototype.toString = function () {
518 return "ResolveEnd(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")";
519 };
520 return ResolveEnd;
521 }(RouterEvent));
522 /**
523 * An event triggered before lazy loading a route configuration.
524 *
525 * @publicApi
526 */
527 var RouteConfigLoadStart = /** @class */ (function () {
528 function RouteConfigLoadStart(
529 /** @docsNotRequired */
530 route) {
531 this.route = route;
532 }
533 RouteConfigLoadStart.prototype.toString = function () {
534 return "RouteConfigLoadStart(path: " + this.route.path + ")";
535 };
536 return RouteConfigLoadStart;
537 }());
538 /**
539 * An event triggered when a route has been lazy loaded.
540 *
541 * @publicApi
542 */
543 var RouteConfigLoadEnd = /** @class */ (function () {
544 function RouteConfigLoadEnd(
545 /** @docsNotRequired */
546 route) {
547 this.route = route;
548 }
549 RouteConfigLoadEnd.prototype.toString = function () {
550 return "RouteConfigLoadEnd(path: " + this.route.path + ")";
551 };
552 return RouteConfigLoadEnd;
553 }());
554 /**
555 * An event triggered at the start of the child-activation
556 * part of the Resolve phase of routing.
557 * @see `ChildActivationEnd`
558 * @see `ResolveStart`
559 *
560 * @publicApi
561 */
562 var ChildActivationStart = /** @class */ (function () {
563 function ChildActivationStart(
564 /** @docsNotRequired */
565 snapshot) {
566 this.snapshot = snapshot;
567 }
568 ChildActivationStart.prototype.toString = function () {
569 var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
570 return "ChildActivationStart(path: '" + path + "')";
571 };
572 return ChildActivationStart;
573 }());
574 /**
575 * An event triggered at the end of the child-activation part
576 * of the Resolve phase of routing.
577 * @see `ChildActivationStart`
578 * @see `ResolveStart` *
579 * @publicApi
580 */
581 var ChildActivationEnd = /** @class */ (function () {
582 function ChildActivationEnd(
583 /** @docsNotRequired */
584 snapshot) {
585 this.snapshot = snapshot;
586 }
587 ChildActivationEnd.prototype.toString = function () {
588 var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
589 return "ChildActivationEnd(path: '" + path + "')";
590 };
591 return ChildActivationEnd;
592 }());
593 /**
594 * An event triggered at the start of the activation part
595 * of the Resolve phase of routing.
596 * @see ActivationEnd`
597 * @see `ResolveStart`
598 *
599 * @publicApi
600 */
601 var ActivationStart = /** @class */ (function () {
602 function ActivationStart(
603 /** @docsNotRequired */
604 snapshot) {
605 this.snapshot = snapshot;
606 }
607 ActivationStart.prototype.toString = function () {
608 var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
609 return "ActivationStart(path: '" + path + "')";
610 };
611 return ActivationStart;
612 }());
613 /**
614 * An event triggered at the end of the activation part
615 * of the Resolve phase of routing.
616 * @see `ActivationStart`
617 * @see `ResolveStart`
618 *
619 * @publicApi
620 */
621 var ActivationEnd = /** @class */ (function () {
622 function ActivationEnd(
623 /** @docsNotRequired */
624 snapshot) {
625 this.snapshot = snapshot;
626 }
627 ActivationEnd.prototype.toString = function () {
628 var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
629 return "ActivationEnd(path: '" + path + "')";
630 };
631 return ActivationEnd;
632 }());
633 /**
634 * An event triggered by scrolling.
635 *
636 * @publicApi
637 */
638 var Scroll = /** @class */ (function () {
639 function Scroll(
640 /** @docsNotRequired */
641 routerEvent,
642 /** @docsNotRequired */
643 position,
644 /** @docsNotRequired */
645 anchor) {
646 this.routerEvent = routerEvent;
647 this.position = position;
648 this.anchor = anchor;
649 }
650 Scroll.prototype.toString = function () {
651 var pos = this.position ? this.position[0] + ", " + this.position[1] : null;
652 return "Scroll(anchor: '" + this.anchor + "', position: '" + pos + "')";
653 };
654 return Scroll;
655 }());
656
657 /**
658 * @license
659 * Copyright Google LLC All Rights Reserved.
660 *
661 * Use of this source code is governed by an MIT-style license that can be
662 * found in the LICENSE file at https://angular.io/license
663 */
664 /**
665 * This component is used internally within the router to be a placeholder when an empty
666 * router-outlet is needed. For example, with a config such as:
667 *
668 * `{path: 'parent', outlet: 'nav', children: [...]}`
669 *
670 * In order to render, there needs to be a component on this config, which will default
671 * to this `EmptyOutletComponent`.
672 */
673 var ɵEmptyOutletComponent = /** @class */ (function () {
674 function ɵEmptyOutletComponent() {
675 }
676 ɵEmptyOutletComponent.decorators = [
677 { type: core.Component, args: [{ template: "<router-outlet></router-outlet>" },] }
678 ];
679 return ɵEmptyOutletComponent;
680 }());
681
682 /**
683 * @license
684 * Copyright Google LLC All Rights Reserved.
685 *
686 * Use of this source code is governed by an MIT-style license that can be
687 * found in the LICENSE file at https://angular.io/license
688 */
689 /**
690 * The primary routing outlet.
691 *
692 * @publicApi
693 */
694 var PRIMARY_OUTLET = 'primary';
695 var ParamsAsMap = /** @class */ (function () {
696 function ParamsAsMap(params) {
697 this.params = params || {};
698 }
699 ParamsAsMap.prototype.has = function (name) {
700 return Object.prototype.hasOwnProperty.call(this.params, name);
701 };
702 ParamsAsMap.prototype.get = function (name) {
703 if (this.has(name)) {
704 var v = this.params[name];
705 return Array.isArray(v) ? v[0] : v;
706 }
707 return null;
708 };
709 ParamsAsMap.prototype.getAll = function (name) {
710 if (this.has(name)) {
711 var v = this.params[name];
712 return Array.isArray(v) ? v : [v];
713 }
714 return [];
715 };
716 Object.defineProperty(ParamsAsMap.prototype, "keys", {
717 get: function () {
718 return Object.keys(this.params);
719 },
720 enumerable: false,
721 configurable: true
722 });
723 return ParamsAsMap;
724 }());
725 /**
726 * Converts a `Params` instance to a `ParamMap`.
727 * @param params The instance to convert.
728 * @returns The new map instance.
729 *
730 * @publicApi
731 */
732 function convertToParamMap(params) {
733 return new ParamsAsMap(params);
734 }
735 var NAVIGATION_CANCELING_ERROR = 'ngNavigationCancelingError';
736 function navigationCancelingError(message) {
737 var error = Error('NavigationCancelingError: ' + message);
738 error[NAVIGATION_CANCELING_ERROR] = true;
739 return error;
740 }
741 function isNavigationCancelingError(error) {
742 return error && error[NAVIGATION_CANCELING_ERROR];
743 }
744 // Matches the route configuration (`route`) against the actual URL (`segments`).
745 function defaultUrlMatcher(segments, segmentGroup, route) {
746 var parts = route.path.split('/');
747 if (parts.length > segments.length) {
748 // The actual URL is shorter than the config, no match
749 return null;
750 }
751 if (route.pathMatch === 'full' &&
752 (segmentGroup.hasChildren() || parts.length < segments.length)) {
753 // The config is longer than the actual URL but we are looking for a full match, return null
754 return null;
755 }
756 var posParams = {};
757 // Check each config part against the actual URL
758 for (var index = 0; index < parts.length; index++) {
759 var part = parts[index];
760 var segment = segments[index];
761 var isParameter = part.startsWith(':');
762 if (isParameter) {
763 posParams[part.substring(1)] = segment;
764 }
765 else if (part !== segment.path) {
766 // The actual URL part does not match the config, no match
767 return null;
768 }
769 }
770 return { consumed: segments.slice(0, parts.length), posParams: posParams };
771 }
772
773 /**
774 * @license
775 * Copyright Google LLC All Rights Reserved.
776 *
777 * Use of this source code is governed by an MIT-style license that can be
778 * found in the LICENSE file at https://angular.io/license
779 */
780 var LoadedRouterConfig = /** @class */ (function () {
781 function LoadedRouterConfig(routes, module) {
782 this.routes = routes;
783 this.module = module;
784 }
785 return LoadedRouterConfig;
786 }());
787 function validateConfig(config, parentPath) {
788 if (parentPath === void 0) { parentPath = ''; }
789 // forEach doesn't iterate undefined values
790 for (var i = 0; i < config.length; i++) {
791 var route = config[i];
792 var fullPath = getFullPath(parentPath, route);
793 validateNode(route, fullPath);
794 }
795 }
796 function validateNode(route, fullPath) {
797 if (!route) {
798 throw new Error("\n Invalid configuration of route '" + fullPath + "': Encountered undefined route.\n The reason might be an extra comma.\n\n Example:\n const routes: Routes = [\n { path: '', redirectTo: '/dashboard', pathMatch: 'full' },\n { path: 'dashboard', component: DashboardComponent },, << two commas\n { path: 'detail/:id', component: HeroDetailComponent }\n ];\n ");
799 }
800 if (Array.isArray(route)) {
801 throw new Error("Invalid configuration of route '" + fullPath + "': Array cannot be specified");
802 }
803 if (!route.component && !route.children && !route.loadChildren &&
804 (route.outlet && route.outlet !== PRIMARY_OUTLET)) {
805 throw new Error("Invalid configuration of route '" + fullPath + "': a componentless route without children or loadChildren cannot have a named outlet set");
806 }
807 if (route.redirectTo && route.children) {
808 throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and children cannot be used together");
809 }
810 if (route.redirectTo && route.loadChildren) {
811 throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and loadChildren cannot be used together");
812 }
813 if (route.children && route.loadChildren) {
814 throw new Error("Invalid configuration of route '" + fullPath + "': children and loadChildren cannot be used together");
815 }
816 if (route.redirectTo && route.component) {
817 throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and component cannot be used together");
818 }
819 if (route.path && route.matcher) {
820 throw new Error("Invalid configuration of route '" + fullPath + "': path and matcher cannot be used together");
821 }
822 if (route.redirectTo === void 0 && !route.component && !route.children && !route.loadChildren) {
823 throw new Error("Invalid configuration of route '" + fullPath + "'. One of the following must be provided: component, redirectTo, children or loadChildren");
824 }
825 if (route.path === void 0 && route.matcher === void 0) {
826 throw new Error("Invalid configuration of route '" + fullPath + "': routes must have either a path or a matcher specified");
827 }
828 if (typeof route.path === 'string' && route.path.charAt(0) === '/') {
829 throw new Error("Invalid configuration of route '" + fullPath + "': path cannot start with a slash");
830 }
831 if (route.path === '' && route.redirectTo !== void 0 && route.pathMatch === void 0) {
832 var exp = "The default value of 'pathMatch' is 'prefix', but often the intent is to use 'full'.";
833 throw new Error("Invalid configuration of route '{path: \"" + fullPath + "\", redirectTo: \"" + route.redirectTo + "\"}': please provide 'pathMatch'. " + exp);
834 }
835 if (route.pathMatch !== void 0 && route.pathMatch !== 'full' && route.pathMatch !== 'prefix') {
836 throw new Error("Invalid configuration of route '" + fullPath + "': pathMatch can only be set to 'prefix' or 'full'");
837 }
838 if (route.children) {
839 validateConfig(route.children, fullPath);
840 }
841 }
842 function getFullPath(parentPath, currentRoute) {
843 if (!currentRoute) {
844 return parentPath;
845 }
846 if (!parentPath && !currentRoute.path) {
847 return '';
848 }
849 else if (parentPath && !currentRoute.path) {
850 return parentPath + "/";
851 }
852 else if (!parentPath && currentRoute.path) {
853 return currentRoute.path;
854 }
855 else {
856 return parentPath + "/" + currentRoute.path;
857 }
858 }
859 /**
860 * Makes a copy of the config and adds any default required properties.
861 */
862 function standardizeConfig(r) {
863 var children = r.children && r.children.map(standardizeConfig);
864 var c = children ? __assign(__assign({}, r), { children: children }) : __assign({}, r);
865 if (!c.component && (children || c.loadChildren) && (c.outlet && c.outlet !== PRIMARY_OUTLET)) {
866 c.component = ɵEmptyOutletComponent;
867 }
868 return c;
869 }
870
871 /**
872 * @license
873 * Copyright Google LLC All Rights Reserved.
874 *
875 * Use of this source code is governed by an MIT-style license that can be
876 * found in the LICENSE file at https://angular.io/license
877 */
878 function shallowEqualArrays(a, b) {
879 if (a.length !== b.length)
880 return false;
881 for (var i = 0; i < a.length; ++i) {
882 if (!shallowEqual(a[i], b[i]))
883 return false;
884 }
885 return true;
886 }
887 function shallowEqual(a, b) {
888 // Casting Object.keys return values to include `undefined` as there are some cases
889 // in IE 11 where this can happen. Cannot provide a test because the behavior only
890 // exists in certain circumstances in IE 11, therefore doing this cast ensures the
891 // logic is correct for when this edge case is hit.
892 var k1 = Object.keys(a);
893 var k2 = Object.keys(b);
894 if (!k1 || !k2 || k1.length != k2.length) {
895 return false;
896 }
897 var key;
898 for (var i = 0; i < k1.length; i++) {
899 key = k1[i];
900 if (!equalArraysOrString(a[key], b[key])) {
901 return false;
902 }
903 }
904 return true;
905 }
906 /**
907 * Test equality for arrays of strings or a string.
908 */
909 function equalArraysOrString(a, b) {
910 if (Array.isArray(a) && Array.isArray(b)) {
911 if (a.length != b.length)
912 return false;
913 return a.every(function (aItem) { return b.indexOf(aItem) > -1; });
914 }
915 else {
916 return a === b;
917 }
918 }
919 /**
920 * Flattens single-level nested arrays.
921 */
922 function flatten(arr) {
923 return Array.prototype.concat.apply([], arr);
924 }
925 /**
926 * Return the last element of an array.
927 */
928 function last(a) {
929 return a.length > 0 ? a[a.length - 1] : null;
930 }
931 /**
932 * Verifys all booleans in an array are `true`.
933 */
934 function and(bools) {
935 return !bools.some(function (v) { return !v; });
936 }
937 function forEach(map, callback) {
938 for (var prop in map) {
939 if (map.hasOwnProperty(prop)) {
940 callback(map[prop], prop);
941 }
942 }
943 }
944 function waitForMap(obj, fn) {
945 if (Object.keys(obj).length === 0) {
946 return rxjs.of({});
947 }
948 var waitHead = [];
949 var waitTail = [];
950 var res = {};
951 forEach(obj, function (a, k) {
952 var mapped = fn(k, a).pipe(operators.map(function (r) { return res[k] = r; }));
953 if (k === PRIMARY_OUTLET) {
954 waitHead.push(mapped);
955 }
956 else {
957 waitTail.push(mapped);
958 }
959 });
960 // Closure compiler has problem with using spread operator here. So we use "Array.concat".
961 // Note that we also need to cast the new promise because TypeScript cannot infer the type
962 // when calling the "of" function through "Function.apply"
963 return rxjs.of.apply(null, waitHead.concat(waitTail))
964 .pipe(operators.concatAll(), operators.last(), operators.map(function () { return res; }));
965 }
966 function wrapIntoObservable(value) {
967 if (core.ɵisObservable(value)) {
968 return value;
969 }
970 if (core.ɵisPromise(value)) {
971 // Use `Promise.resolve()` to wrap promise-like instances.
972 // Required ie when a Resolver returns a AngularJS `$q` promise to correctly trigger the
973 // change detection.
974 return rxjs.from(Promise.resolve(value));
975 }
976 return rxjs.of(value);
977 }
978
979 /**
980 * @license
981 * Copyright Google LLC All Rights Reserved.
982 *
983 * Use of this source code is governed by an MIT-style license that can be
984 * found in the LICENSE file at https://angular.io/license
985 */
986 function createEmptyUrlTree() {
987 return new UrlTree(new UrlSegmentGroup([], {}), {}, null);
988 }
989 function containsTree(container, containee, exact) {
990 if (exact) {
991 return equalQueryParams(container.queryParams, containee.queryParams) &&
992 equalSegmentGroups(container.root, containee.root);
993 }
994 return containsQueryParams(container.queryParams, containee.queryParams) &&
995 containsSegmentGroup(container.root, containee.root);
996 }
997 function equalQueryParams(container, containee) {
998 // TODO: This does not handle array params correctly.
999 return shallowEqual(container, containee);
1000 }
1001 function equalSegmentGroups(container, containee) {
1002 if (!equalPath(container.segments, containee.segments))
1003 return false;
1004 if (container.numberOfChildren !== containee.numberOfChildren)
1005 return false;
1006 for (var c in containee.children) {
1007 if (!container.children[c])
1008 return false;
1009 if (!equalSegmentGroups(container.children[c], containee.children[c]))
1010 return false;
1011 }
1012 return true;
1013 }
1014 function containsQueryParams(container, containee) {
1015 // TODO: This does not handle array params correctly.
1016 return Object.keys(containee).length <= Object.keys(container).length &&
1017 Object.keys(containee).every(function (key) { return equalArraysOrString(container[key], containee[key]); });
1018 }
1019 function containsSegmentGroup(container, containee) {
1020 return containsSegmentGroupHelper(container, containee, containee.segments);
1021 }
1022 function containsSegmentGroupHelper(container, containee, containeePaths) {
1023 if (container.segments.length > containeePaths.length) {
1024 var current = container.segments.slice(0, containeePaths.length);
1025 if (!equalPath(current, containeePaths))
1026 return false;
1027 if (containee.hasChildren())
1028 return false;
1029 return true;
1030 }
1031 else if (container.segments.length === containeePaths.length) {
1032 if (!equalPath(container.segments, containeePaths))
1033 return false;
1034 for (var c in containee.children) {
1035 if (!container.children[c])
1036 return false;
1037 if (!containsSegmentGroup(container.children[c], containee.children[c]))
1038 return false;
1039 }
1040 return true;
1041 }
1042 else {
1043 var current = containeePaths.slice(0, container.segments.length);
1044 var next = containeePaths.slice(container.segments.length);
1045 if (!equalPath(container.segments, current))
1046 return false;
1047 if (!container.children[PRIMARY_OUTLET])
1048 return false;
1049 return containsSegmentGroupHelper(container.children[PRIMARY_OUTLET], containee, next);
1050 }
1051 }
1052 /**
1053 * @description
1054 *
1055 * Represents the parsed URL.
1056 *
1057 * Since a router state is a tree, and the URL is nothing but a serialized state, the URL is a
1058 * serialized tree.
1059 * UrlTree is a data structure that provides a lot of affordances in dealing with URLs
1060 *
1061 * @usageNotes
1062 * ### Example
1063 *
1064 * ```
1065 * @Component({templateUrl:'template.html'})
1066 * class MyComponent {
1067 * constructor(router: Router) {
1068 * const tree: UrlTree =
1069 * router.parseUrl('/team/33/(user/victor//support:help)?debug=true#fragment');
1070 * const f = tree.fragment; // return 'fragment'
1071 * const q = tree.queryParams; // returns {debug: 'true'}
1072 * const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET];
1073 * const s: UrlSegment[] = g.segments; // returns 2 segments 'team' and '33'
1074 * g.children[PRIMARY_OUTLET].segments; // returns 2 segments 'user' and 'victor'
1075 * g.children['support'].segments; // return 1 segment 'help'
1076 * }
1077 * }
1078 * ```
1079 *
1080 * @publicApi
1081 */
1082 var UrlTree = /** @class */ (function () {
1083 /** @internal */
1084 function UrlTree(
1085 /** The root segment group of the URL tree */
1086 root,
1087 /** The query params of the URL */
1088 queryParams,
1089 /** The fragment of the URL */
1090 fragment) {
1091 this.root = root;
1092 this.queryParams = queryParams;
1093 this.fragment = fragment;
1094 }
1095 Object.defineProperty(UrlTree.prototype, "queryParamMap", {
1096 get: function () {
1097 if (!this._queryParamMap) {
1098 this._queryParamMap = convertToParamMap(this.queryParams);
1099 }
1100 return this._queryParamMap;
1101 },
1102 enumerable: false,
1103 configurable: true
1104 });
1105 /** @docsNotRequired */
1106 UrlTree.prototype.toString = function () {
1107 return DEFAULT_SERIALIZER.serialize(this);
1108 };
1109 return UrlTree;
1110 }());
1111 /**
1112 * @description
1113 *
1114 * Represents the parsed URL segment group.
1115 *
1116 * See `UrlTree` for more information.
1117 *
1118 * @publicApi
1119 */
1120 var UrlSegmentGroup = /** @class */ (function () {
1121 function UrlSegmentGroup(
1122 /** The URL segments of this group. See `UrlSegment` for more information */
1123 segments,
1124 /** The list of children of this group */
1125 children) {
1126 var _this = this;
1127 this.segments = segments;
1128 this.children = children;
1129 /** The parent node in the url tree */
1130 this.parent = null;
1131 forEach(children, function (v, k) { return v.parent = _this; });
1132 }
1133 /** Whether the segment has child segments */
1134 UrlSegmentGroup.prototype.hasChildren = function () {
1135 return this.numberOfChildren > 0;
1136 };
1137 Object.defineProperty(UrlSegmentGroup.prototype, "numberOfChildren", {
1138 /** Number of child segments */
1139 get: function () {
1140 return Object.keys(this.children).length;
1141 },
1142 enumerable: false,
1143 configurable: true
1144 });
1145 /** @docsNotRequired */
1146 UrlSegmentGroup.prototype.toString = function () {
1147 return serializePaths(this);
1148 };
1149 return UrlSegmentGroup;
1150 }());
1151 /**
1152 * @description
1153 *
1154 * Represents a single URL segment.
1155 *
1156 * A UrlSegment is a part of a URL between the two slashes. It contains a path and the matrix
1157 * parameters associated with the segment.
1158 *
1159 * @usageNotes
1160 * ### Example
1161 *
1162 * ```
1163 * @Component({templateUrl:'template.html'})
1164 * class MyComponent {
1165 * constructor(router: Router) {
1166 * const tree: UrlTree = router.parseUrl('/team;id=33');
1167 * const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET];
1168 * const s: UrlSegment[] = g.segments;
1169 * s[0].path; // returns 'team'
1170 * s[0].parameters; // returns {id: 33}
1171 * }
1172 * }
1173 * ```
1174 *
1175 * @publicApi
1176 */
1177 var UrlSegment = /** @class */ (function () {
1178 function UrlSegment(
1179 /** The path part of a URL segment */
1180 path,
1181 /** The matrix parameters associated with a segment */
1182 parameters) {
1183 this.path = path;
1184 this.parameters = parameters;
1185 }
1186 Object.defineProperty(UrlSegment.prototype, "parameterMap", {
1187 get: function () {
1188 if (!this._parameterMap) {
1189 this._parameterMap = convertToParamMap(this.parameters);
1190 }
1191 return this._parameterMap;
1192 },
1193 enumerable: false,
1194 configurable: true
1195 });
1196 /** @docsNotRequired */
1197 UrlSegment.prototype.toString = function () {
1198 return serializePath(this);
1199 };
1200 return UrlSegment;
1201 }());
1202 function equalSegments(as, bs) {
1203 return equalPath(as, bs) && as.every(function (a, i) { return shallowEqual(a.parameters, bs[i].parameters); });
1204 }
1205 function equalPath(as, bs) {
1206 if (as.length !== bs.length)
1207 return false;
1208 return as.every(function (a, i) { return a.path === bs[i].path; });
1209 }
1210 function mapChildrenIntoArray(segment, fn) {
1211 var res = [];
1212 forEach(segment.children, function (child, childOutlet) {
1213 if (childOutlet === PRIMARY_OUTLET) {
1214 res = res.concat(fn(child, childOutlet));
1215 }
1216 });
1217 forEach(segment.children, function (child, childOutlet) {
1218 if (childOutlet !== PRIMARY_OUTLET) {
1219 res = res.concat(fn(child, childOutlet));
1220 }
1221 });
1222 return res;
1223 }
1224 /**
1225 * @description
1226 *
1227 * Serializes and deserializes a URL string into a URL tree.
1228 *
1229 * The url serialization strategy is customizable. You can
1230 * make all URLs case insensitive by providing a custom UrlSerializer.
1231 *
1232 * See `DefaultUrlSerializer` for an example of a URL serializer.
1233 *
1234 * @publicApi
1235 */
1236 var UrlSerializer = /** @class */ (function () {
1237 function UrlSerializer() {
1238 }
1239 return UrlSerializer;
1240 }());
1241 /**
1242 * @description
1243 *
1244 * A default implementation of the `UrlSerializer`.
1245 *
1246 * Example URLs:
1247 *
1248 * ```
1249 * /inbox/33(popup:compose)
1250 * /inbox/33;open=true/messages/44
1251 * ```
1252 *
1253 * DefaultUrlSerializer uses parentheses to serialize secondary segments (e.g., popup:compose), the
1254 * colon syntax to specify the outlet, and the ';parameter=value' syntax (e.g., open=true) to
1255 * specify route specific parameters.
1256 *
1257 * @publicApi
1258 */
1259 var DefaultUrlSerializer = /** @class */ (function () {
1260 function DefaultUrlSerializer() {
1261 }
1262 /** Parses a url into a `UrlTree` */
1263 DefaultUrlSerializer.prototype.parse = function (url) {
1264 var p = new UrlParser(url);
1265 return new UrlTree(p.parseRootSegment(), p.parseQueryParams(), p.parseFragment());
1266 };
1267 /** Converts a `UrlTree` into a url */
1268 DefaultUrlSerializer.prototype.serialize = function (tree) {
1269 var segment = "/" + serializeSegment(tree.root, true);
1270 var query = serializeQueryParams(tree.queryParams);
1271 var fragment = typeof tree.fragment === "string" ? "#" + encodeUriFragment(tree.fragment) : '';
1272 return "" + segment + query + fragment;
1273 };
1274 return DefaultUrlSerializer;
1275 }());
1276 var DEFAULT_SERIALIZER = new DefaultUrlSerializer();
1277 function serializePaths(segment) {
1278 return segment.segments.map(function (p) { return serializePath(p); }).join('/');
1279 }
1280 function serializeSegment(segment, root) {
1281 if (!segment.hasChildren()) {
1282 return serializePaths(segment);
1283 }
1284 if (root) {
1285 var primary = segment.children[PRIMARY_OUTLET] ?
1286 serializeSegment(segment.children[PRIMARY_OUTLET], false) :
1287 '';
1288 var children_1 = [];
1289 forEach(segment.children, function (v, k) {
1290 if (k !== PRIMARY_OUTLET) {
1291 children_1.push(k + ":" + serializeSegment(v, false));
1292 }
1293 });
1294 return children_1.length > 0 ? primary + "(" + children_1.join('//') + ")" : primary;
1295 }
1296 else {
1297 var children = mapChildrenIntoArray(segment, function (v, k) {
1298 if (k === PRIMARY_OUTLET) {
1299 return [serializeSegment(segment.children[PRIMARY_OUTLET], false)];
1300 }
1301 return [k + ":" + serializeSegment(v, false)];
1302 });
1303 return serializePaths(segment) + "/(" + children.join('//') + ")";
1304 }
1305 }
1306 /**
1307 * Encodes a URI string with the default encoding. This function will only ever be called from
1308 * `encodeUriQuery` or `encodeUriSegment` as it's the base set of encodings to be used. We need
1309 * a custom encoding because encodeURIComponent is too aggressive and encodes stuff that doesn't
1310 * have to be encoded per https://url.spec.whatwg.org.
1311 */
1312 function encodeUriString(s) {
1313 return encodeURIComponent(s)
1314 .replace(/%40/g, '@')
1315 .replace(/%3A/gi, ':')
1316 .replace(/%24/g, '$')
1317 .replace(/%2C/gi, ',');
1318 }
1319 /**
1320 * This function should be used to encode both keys and values in a query string key/value. In
1321 * the following URL, you need to call encodeUriQuery on "k" and "v":
1322 *
1323 * http://www.site.org/html;mk=mv?k=v#f
1324 */
1325 function encodeUriQuery(s) {
1326 return encodeUriString(s).replace(/%3B/gi, ';');
1327 }
1328 /**
1329 * This function should be used to encode a URL fragment. In the following URL, you need to call
1330 * encodeUriFragment on "f":
1331 *
1332 * http://www.site.org/html;mk=mv?k=v#f
1333 */
1334 function encodeUriFragment(s) {
1335 return encodeURI(s);
1336 }
1337 /**
1338 * This function should be run on any URI segment as well as the key and value in a key/value
1339 * pair for matrix params. In the following URL, you need to call encodeUriSegment on "html",
1340 * "mk", and "mv":
1341 *
1342 * http://www.site.org/html;mk=mv?k=v#f
1343 */
1344 function encodeUriSegment(s) {
1345 return encodeUriString(s).replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/%26/gi, '&');
1346 }
1347 function decode(s) {
1348 return decodeURIComponent(s);
1349 }
1350 // Query keys/values should have the "+" replaced first, as "+" in a query string is " ".
1351 // decodeURIComponent function will not decode "+" as a space.
1352 function decodeQuery(s) {
1353 return decode(s.replace(/\+/g, '%20'));
1354 }
1355 function serializePath(path) {
1356 return "" + encodeUriSegment(path.path) + serializeMatrixParams(path.parameters);
1357 }
1358 function serializeMatrixParams(params) {
1359 return Object.keys(params)
1360 .map(function (key) { return ";" + encodeUriSegment(key) + "=" + encodeUriSegment(params[key]); })
1361 .join('');
1362 }
1363 function serializeQueryParams(params) {
1364 var strParams = Object.keys(params).map(function (name) {
1365 var value = params[name];
1366 return Array.isArray(value) ?
1367 value.map(function (v) { return encodeUriQuery(name) + "=" + encodeUriQuery(v); }).join('&') :
1368 encodeUriQuery(name) + "=" + encodeUriQuery(value);
1369 });
1370 return strParams.length ? "?" + strParams.join('&') : '';
1371 }
1372 var SEGMENT_RE = /^[^\/()?;=#]+/;
1373 function matchSegments(str) {
1374 var match = str.match(SEGMENT_RE);
1375 return match ? match[0] : '';
1376 }
1377 var QUERY_PARAM_RE = /^[^=?&#]+/;
1378 // Return the name of the query param at the start of the string or an empty string
1379 function matchQueryParams(str) {
1380 var match = str.match(QUERY_PARAM_RE);
1381 return match ? match[0] : '';
1382 }
1383 var QUERY_PARAM_VALUE_RE = /^[^?&#]+/;
1384 // Return the value of the query param at the start of the string or an empty string
1385 function matchUrlQueryParamValue(str) {
1386 var match = str.match(QUERY_PARAM_VALUE_RE);
1387 return match ? match[0] : '';
1388 }
1389 var UrlParser = /** @class */ (function () {
1390 function UrlParser(url) {
1391 this.url = url;
1392 this.remaining = url;
1393 }
1394 UrlParser.prototype.parseRootSegment = function () {
1395 this.consumeOptional('/');
1396 if (this.remaining === '' || this.peekStartsWith('?') || this.peekStartsWith('#')) {
1397 return new UrlSegmentGroup([], {});
1398 }
1399 // The root segment group never has segments
1400 return new UrlSegmentGroup([], this.parseChildren());
1401 };
1402 UrlParser.prototype.parseQueryParams = function () {
1403 var params = {};
1404 if (this.consumeOptional('?')) {
1405 do {
1406 this.parseQueryParam(params);
1407 } while (this.consumeOptional('&'));
1408 }
1409 return params;
1410 };
1411 UrlParser.prototype.parseFragment = function () {
1412 return this.consumeOptional('#') ? decodeURIComponent(this.remaining) : null;
1413 };
1414 UrlParser.prototype.parseChildren = function () {
1415 if (this.remaining === '') {
1416 return {};
1417 }
1418 this.consumeOptional('/');
1419 var segments = [];
1420 if (!this.peekStartsWith('(')) {
1421 segments.push(this.parseSegment());
1422 }
1423 while (this.peekStartsWith('/') && !this.peekStartsWith('//') && !this.peekStartsWith('/(')) {
1424 this.capture('/');
1425 segments.push(this.parseSegment());
1426 }
1427 var children = {};
1428 if (this.peekStartsWith('/(')) {
1429 this.capture('/');
1430 children = this.parseParens(true);
1431 }
1432 var res = {};
1433 if (this.peekStartsWith('(')) {
1434 res = this.parseParens(false);
1435 }
1436 if (segments.length > 0 || Object.keys(children).length > 0) {
1437 res[PRIMARY_OUTLET] = new UrlSegmentGroup(segments, children);
1438 }
1439 return res;
1440 };
1441 // parse a segment with its matrix parameters
1442 // ie `name;k1=v1;k2`
1443 UrlParser.prototype.parseSegment = function () {
1444 var path = matchSegments(this.remaining);
1445 if (path === '' && this.peekStartsWith(';')) {
1446 throw new Error("Empty path url segment cannot have parameters: '" + this.remaining + "'.");
1447 }
1448 this.capture(path);
1449 return new UrlSegment(decode(path), this.parseMatrixParams());
1450 };
1451 UrlParser.prototype.parseMatrixParams = function () {
1452 var params = {};
1453 while (this.consumeOptional(';')) {
1454 this.parseParam(params);
1455 }
1456 return params;
1457 };
1458 UrlParser.prototype.parseParam = function (params) {
1459 var key = matchSegments(this.remaining);
1460 if (!key) {
1461 return;
1462 }
1463 this.capture(key);
1464 var value = '';
1465 if (this.consumeOptional('=')) {
1466 var valueMatch = matchSegments(this.remaining);
1467 if (valueMatch) {
1468 value = valueMatch;
1469 this.capture(value);
1470 }
1471 }
1472 params[decode(key)] = decode(value);
1473 };
1474 // Parse a single query parameter `name[=value]`
1475 UrlParser.prototype.parseQueryParam = function (params) {
1476 var key = matchQueryParams(this.remaining);
1477 if (!key) {
1478 return;
1479 }
1480 this.capture(key);
1481 var value = '';
1482 if (this.consumeOptional('=')) {
1483 var valueMatch = matchUrlQueryParamValue(this.remaining);
1484 if (valueMatch) {
1485 value = valueMatch;
1486 this.capture(value);
1487 }
1488 }
1489 var decodedKey = decodeQuery(key);
1490 var decodedVal = decodeQuery(value);
1491 if (params.hasOwnProperty(decodedKey)) {
1492 // Append to existing values
1493 var currentVal = params[decodedKey];
1494 if (!Array.isArray(currentVal)) {
1495 currentVal = [currentVal];
1496 params[decodedKey] = currentVal;
1497 }
1498 currentVal.push(decodedVal);
1499 }
1500 else {
1501 // Create a new value
1502 params[decodedKey] = decodedVal;
1503 }
1504 };
1505 // parse `(a/b//outlet_name:c/d)`
1506 UrlParser.prototype.parseParens = function (allowPrimary) {
1507 var segments = {};
1508 this.capture('(');
1509 while (!this.consumeOptional(')') && this.remaining.length > 0) {
1510 var path = matchSegments(this.remaining);
1511 var next = this.remaining[path.length];
1512 // if is is not one of these characters, then the segment was unescaped
1513 // or the group was not closed
1514 if (next !== '/' && next !== ')' && next !== ';') {
1515 throw new Error("Cannot parse url '" + this.url + "'");
1516 }
1517 var outletName = undefined;
1518 if (path.indexOf(':') > -1) {
1519 outletName = path.substr(0, path.indexOf(':'));
1520 this.capture(outletName);
1521 this.capture(':');
1522 }
1523 else if (allowPrimary) {
1524 outletName = PRIMARY_OUTLET;
1525 }
1526 var children = this.parseChildren();
1527 segments[outletName] = Object.keys(children).length === 1 ? children[PRIMARY_OUTLET] :
1528 new UrlSegmentGroup([], children);
1529 this.consumeOptional('//');
1530 }
1531 return segments;
1532 };
1533 UrlParser.prototype.peekStartsWith = function (str) {
1534 return this.remaining.startsWith(str);
1535 };
1536 // Consumes the prefix when it is present and returns whether it has been consumed
1537 UrlParser.prototype.consumeOptional = function (str) {
1538 if (this.peekStartsWith(str)) {
1539 this.remaining = this.remaining.substring(str.length);
1540 return true;
1541 }
1542 return false;
1543 };
1544 UrlParser.prototype.capture = function (str) {
1545 if (!this.consumeOptional(str)) {
1546 throw new Error("Expected \"" + str + "\".");
1547 }
1548 };
1549 return UrlParser;
1550 }());
1551
1552 /**
1553 * @license
1554 * Copyright Google LLC All Rights Reserved.
1555 *
1556 * Use of this source code is governed by an MIT-style license that can be
1557 * found in the LICENSE file at https://angular.io/license
1558 */
1559 var Tree = /** @class */ (function () {
1560 function Tree(root) {
1561 this._root = root;
1562 }
1563 Object.defineProperty(Tree.prototype, "root", {
1564 get: function () {
1565 return this._root.value;
1566 },
1567 enumerable: false,
1568 configurable: true
1569 });
1570 /**
1571 * @internal
1572 */
1573 Tree.prototype.parent = function (t) {
1574 var p = this.pathFromRoot(t);
1575 return p.length > 1 ? p[p.length - 2] : null;
1576 };
1577 /**
1578 * @internal
1579 */
1580 Tree.prototype.children = function (t) {
1581 var n = findNode(t, this._root);
1582 return n ? n.children.map(function (t) { return t.value; }) : [];
1583 };
1584 /**
1585 * @internal
1586 */
1587 Tree.prototype.firstChild = function (t) {
1588 var n = findNode(t, this._root);
1589 return n && n.children.length > 0 ? n.children[0].value : null;
1590 };
1591 /**
1592 * @internal
1593 */
1594 Tree.prototype.siblings = function (t) {
1595 var p = findPath(t, this._root);
1596 if (p.length < 2)
1597 return [];
1598 var c = p[p.length - 2].children.map(function (c) { return c.value; });
1599 return c.filter(function (cc) { return cc !== t; });
1600 };
1601 /**
1602 * @internal
1603 */
1604 Tree.prototype.pathFromRoot = function (t) {
1605 return findPath(t, this._root).map(function (s) { return s.value; });
1606 };
1607 return Tree;
1608 }());
1609 // DFS for the node matching the value
1610 function findNode(value, node) {
1611 var e_1, _a;
1612 if (value === node.value)
1613 return node;
1614 try {
1615 for (var _b = __values(node.children), _c = _b.next(); !_c.done; _c = _b.next()) {
1616 var child = _c.value;
1617 var node_1 = findNode(value, child);
1618 if (node_1)
1619 return node_1;
1620 }
1621 }
1622 catch (e_1_1) { e_1 = { error: e_1_1 }; }
1623 finally {
1624 try {
1625 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1626 }
1627 finally { if (e_1) throw e_1.error; }
1628 }
1629 return null;
1630 }
1631 // Return the path to the node with the given value using DFS
1632 function findPath(value, node) {
1633 var e_2, _a;
1634 if (value === node.value)
1635 return [node];
1636 try {
1637 for (var _b = __values(node.children), _c = _b.next(); !_c.done; _c = _b.next()) {
1638 var child = _c.value;
1639 var path = findPath(value, child);
1640 if (path.length) {
1641 path.unshift(node);
1642 return path;
1643 }
1644 }
1645 }
1646 catch (e_2_1) { e_2 = { error: e_2_1 }; }
1647 finally {
1648 try {
1649 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1650 }
1651 finally { if (e_2) throw e_2.error; }
1652 }
1653 return [];
1654 }
1655 var TreeNode = /** @class */ (function () {
1656 function TreeNode(value, children) {
1657 this.value = value;
1658 this.children = children;
1659 }
1660 TreeNode.prototype.toString = function () {
1661 return "TreeNode(" + this.value + ")";
1662 };
1663 return TreeNode;
1664 }());
1665 // Return the list of T indexed by outlet name
1666 function nodeChildrenAsMap(node) {
1667 var map = {};
1668 if (node) {
1669 node.children.forEach(function (child) { return map[child.value.outlet] = child; });
1670 }
1671 return map;
1672 }
1673
1674 /**
1675 * @license
1676 * Copyright Google LLC All Rights Reserved.
1677 *
1678 * Use of this source code is governed by an MIT-style license that can be
1679 * found in the LICENSE file at https://angular.io/license
1680 */
1681 /**
1682 * Represents the state of the router as a tree of activated routes.
1683 *
1684 * @usageNotes
1685 *
1686 * Every node in the route tree is an `ActivatedRoute` instance
1687 * that knows about the "consumed" URL segments, the extracted parameters,
1688 * and the resolved data.
1689 * Use the `ActivatedRoute` properties to traverse the tree from any node.
1690 *
1691 * ### Example
1692 *
1693 * ```
1694 * @Component({templateUrl:'template.html'})
1695 * class MyComponent {
1696 * constructor(router: Router) {
1697 * const state: RouterState = router.routerState;
1698 * const root: ActivatedRoute = state.root;
1699 * const child = root.firstChild;
1700 * const id: Observable<string> = child.params.map(p => p.id);
1701 * //...
1702 * }
1703 * }
1704 * ```
1705 *
1706 * @see `ActivatedRoute`
1707 *
1708 * @publicApi
1709 */
1710 var RouterState = /** @class */ (function (_super) {
1711 __extends(RouterState, _super);
1712 /** @internal */
1713 function RouterState(root,
1714 /** The current snapshot of the router state */
1715 snapshot) {
1716 var _this = _super.call(this, root) || this;
1717 _this.snapshot = snapshot;
1718 setRouterState(_this, root);
1719 return _this;
1720 }
1721 RouterState.prototype.toString = function () {
1722 return this.snapshot.toString();
1723 };
1724 return RouterState;
1725 }(Tree));
1726 function createEmptyState(urlTree, rootComponent) {
1727 var snapshot = createEmptyStateSnapshot(urlTree, rootComponent);
1728 var emptyUrl = new rxjs.BehaviorSubject([new UrlSegment('', {})]);
1729 var emptyParams = new rxjs.BehaviorSubject({});
1730 var emptyData = new rxjs.BehaviorSubject({});
1731 var emptyQueryParams = new rxjs.BehaviorSubject({});
1732 var fragment = new rxjs.BehaviorSubject('');
1733 var activated = new ActivatedRoute(emptyUrl, emptyParams, emptyQueryParams, fragment, emptyData, PRIMARY_OUTLET, rootComponent, snapshot.root);
1734 activated.snapshot = snapshot.root;
1735 return new RouterState(new TreeNode(activated, []), snapshot);
1736 }
1737 function createEmptyStateSnapshot(urlTree, rootComponent) {
1738 var emptyParams = {};
1739 var emptyData = {};
1740 var emptyQueryParams = {};
1741 var fragment = '';
1742 var activated = new ActivatedRouteSnapshot([], emptyParams, emptyQueryParams, fragment, emptyData, PRIMARY_OUTLET, rootComponent, null, urlTree.root, -1, {});
1743 return new RouterStateSnapshot('', new TreeNode(activated, []));
1744 }
1745 /**
1746 * Provides access to information about a route associated with a component
1747 * that is loaded in an outlet.
1748 * Use to traverse the `RouterState` tree and extract information from nodes.
1749 *
1750 * {@example router/activated-route/module.ts region="activated-route"
1751 * header="activated-route.component.ts"}
1752 *
1753 * @publicApi
1754 */
1755 var ActivatedRoute = /** @class */ (function () {
1756 /** @internal */
1757 function ActivatedRoute(
1758 /** An observable of the URL segments matched by this route. */
1759 url,
1760 /** An observable of the matrix parameters scoped to this route. */
1761 params,
1762 /** An observable of the query parameters shared by all the routes. */
1763 queryParams,
1764 /** An observable of the URL fragment shared by all the routes. */
1765 fragment,
1766 /** An observable of the static and resolved data of this route. */
1767 data,
1768 /** The outlet name of the route, a constant. */
1769 outlet,
1770 /** The component of the route, a constant. */
1771 // TODO(vsavkin): remove |string
1772 component, futureSnapshot) {
1773 this.url = url;
1774 this.params = params;
1775 this.queryParams = queryParams;
1776 this.fragment = fragment;
1777 this.data = data;
1778 this.outlet = outlet;
1779 this.component = component;
1780 this._futureSnapshot = futureSnapshot;
1781 }
1782 Object.defineProperty(ActivatedRoute.prototype, "routeConfig", {
1783 /** The configuration used to match this route. */
1784 get: function () {
1785 return this._futureSnapshot.routeConfig;
1786 },
1787 enumerable: false,
1788 configurable: true
1789 });
1790 Object.defineProperty(ActivatedRoute.prototype, "root", {
1791 /** The root of the router state. */
1792 get: function () {
1793 return this._routerState.root;
1794 },
1795 enumerable: false,
1796 configurable: true
1797 });
1798 Object.defineProperty(ActivatedRoute.prototype, "parent", {
1799 /** The parent of this route in the router state tree. */
1800 get: function () {
1801 return this._routerState.parent(this);
1802 },
1803 enumerable: false,
1804 configurable: true
1805 });
1806 Object.defineProperty(ActivatedRoute.prototype, "firstChild", {
1807 /** The first child of this route in the router state tree. */
1808 get: function () {
1809 return this._routerState.firstChild(this);
1810 },
1811 enumerable: false,
1812 configurable: true
1813 });
1814 Object.defineProperty(ActivatedRoute.prototype, "children", {
1815 /** The children of this route in the router state tree. */
1816 get: function () {
1817 return this._routerState.children(this);
1818 },
1819 enumerable: false,
1820 configurable: true
1821 });
1822 Object.defineProperty(ActivatedRoute.prototype, "pathFromRoot", {
1823 /** The path from the root of the router state tree to this route. */
1824 get: function () {
1825 return this._routerState.pathFromRoot(this);
1826 },
1827 enumerable: false,
1828 configurable: true
1829 });
1830 Object.defineProperty(ActivatedRoute.prototype, "paramMap", {
1831 /**
1832 * An Observable that contains a map of the required and optional parameters
1833 * specific to the route.
1834 * The map supports retrieving single and multiple values from the same parameter.
1835 */
1836 get: function () {
1837 if (!this._paramMap) {
1838 this._paramMap = this.params.pipe(operators.map(function (p) { return convertToParamMap(p); }));
1839 }
1840 return this._paramMap;
1841 },
1842 enumerable: false,
1843 configurable: true
1844 });
1845 Object.defineProperty(ActivatedRoute.prototype, "queryParamMap", {
1846 /**
1847 * An Observable that contains a map of the query parameters available to all routes.
1848 * The map supports retrieving single and multiple values from the query parameter.
1849 */
1850 get: function () {
1851 if (!this._queryParamMap) {
1852 this._queryParamMap =
1853 this.queryParams.pipe(operators.map(function (p) { return convertToParamMap(p); }));
1854 }
1855 return this._queryParamMap;
1856 },
1857 enumerable: false,
1858 configurable: true
1859 });
1860 ActivatedRoute.prototype.toString = function () {
1861 return this.snapshot ? this.snapshot.toString() : "Future(" + this._futureSnapshot + ")";
1862 };
1863 return ActivatedRoute;
1864 }());
1865 /**
1866 * Returns the inherited params, data, and resolve for a given route.
1867 * By default, this only inherits values up to the nearest path-less or component-less route.
1868 * @internal
1869 */
1870 function inheritedParamsDataResolve(route, paramsInheritanceStrategy) {
1871 if (paramsInheritanceStrategy === void 0) { paramsInheritanceStrategy = 'emptyOnly'; }
1872 var pathFromRoot = route.pathFromRoot;
1873 var inheritingStartingFrom = 0;
1874 if (paramsInheritanceStrategy !== 'always') {
1875 inheritingStartingFrom = pathFromRoot.length - 1;
1876 while (inheritingStartingFrom >= 1) {
1877 var current = pathFromRoot[inheritingStartingFrom];
1878 var parent_1 = pathFromRoot[inheritingStartingFrom - 1];
1879 // current route is an empty path => inherits its parent's params and data
1880 if (current.routeConfig && current.routeConfig.path === '') {
1881 inheritingStartingFrom--;
1882 // parent is componentless => current route should inherit its params and data
1883 }
1884 else if (!parent_1.component) {
1885 inheritingStartingFrom--;
1886 }
1887 else {
1888 break;
1889 }
1890 }
1891 }
1892 return flattenInherited(pathFromRoot.slice(inheritingStartingFrom));
1893 }
1894 /** @internal */
1895 function flattenInherited(pathFromRoot) {
1896 return pathFromRoot.reduce(function (res, curr) {
1897 var params = __assign(__assign({}, res.params), curr.params);
1898 var data = __assign(__assign({}, res.data), curr.data);
1899 var resolve = __assign(__assign({}, res.resolve), curr._resolvedData);
1900 return { params: params, data: data, resolve: resolve };
1901 }, { params: {}, data: {}, resolve: {} });
1902 }
1903 /**
1904 * @description
1905 *
1906 * Contains the information about a route associated with a component loaded in an
1907 * outlet at a particular moment in time. ActivatedRouteSnapshot can also be used to
1908 * traverse the router state tree.
1909 *
1910 * ```
1911 * @Component({templateUrl:'./my-component.html'})
1912 * class MyComponent {
1913 * constructor(route: ActivatedRoute) {
1914 * const id: string = route.snapshot.params.id;
1915 * const url: string = route.snapshot.url.join('');
1916 * const user = route.snapshot.data.user;
1917 * }
1918 * }
1919 * ```
1920 *
1921 * @publicApi
1922 */
1923 var ActivatedRouteSnapshot = /** @class */ (function () {
1924 /** @internal */
1925 function ActivatedRouteSnapshot(
1926 /** The URL segments matched by this route */
1927 url,
1928 /** The matrix parameters scoped to this route */
1929 params,
1930 /** The query parameters shared by all the routes */
1931 queryParams,
1932 /** The URL fragment shared by all the routes */
1933 fragment,
1934 /** The static and resolved data of this route */
1935 data,
1936 /** The outlet name of the route */
1937 outlet,
1938 /** The component of the route */
1939 component, routeConfig, urlSegment, lastPathIndex, resolve) {
1940 this.url = url;
1941 this.params = params;
1942 this.queryParams = queryParams;
1943 this.fragment = fragment;
1944 this.data = data;
1945 this.outlet = outlet;
1946 this.component = component;
1947 this.routeConfig = routeConfig;
1948 this._urlSegment = urlSegment;
1949 this._lastPathIndex = lastPathIndex;
1950 this._resolve = resolve;
1951 }
1952 Object.defineProperty(ActivatedRouteSnapshot.prototype, "root", {
1953 /** The root of the router state */
1954 get: function () {
1955 return this._routerState.root;
1956 },
1957 enumerable: false,
1958 configurable: true
1959 });
1960 Object.defineProperty(ActivatedRouteSnapshot.prototype, "parent", {
1961 /** The parent of this route in the router state tree */
1962 get: function () {
1963 return this._routerState.parent(this);
1964 },
1965 enumerable: false,
1966 configurable: true
1967 });
1968 Object.defineProperty(ActivatedRouteSnapshot.prototype, "firstChild", {
1969 /** The first child of this route in the router state tree */
1970 get: function () {
1971 return this._routerState.firstChild(this);
1972 },
1973 enumerable: false,
1974 configurable: true
1975 });
1976 Object.defineProperty(ActivatedRouteSnapshot.prototype, "children", {
1977 /** The children of this route in the router state tree */
1978 get: function () {
1979 return this._routerState.children(this);
1980 },
1981 enumerable: false,
1982 configurable: true
1983 });
1984 Object.defineProperty(ActivatedRouteSnapshot.prototype, "pathFromRoot", {
1985 /** The path from the root of the router state tree to this route */
1986 get: function () {
1987 return this._routerState.pathFromRoot(this);
1988 },
1989 enumerable: false,
1990 configurable: true
1991 });
1992 Object.defineProperty(ActivatedRouteSnapshot.prototype, "paramMap", {
1993 get: function () {
1994 if (!this._paramMap) {
1995 this._paramMap = convertToParamMap(this.params);
1996 }
1997 return this._paramMap;
1998 },
1999 enumerable: false,
2000 configurable: true
2001 });
2002 Object.defineProperty(ActivatedRouteSnapshot.prototype, "queryParamMap", {
2003 get: function () {
2004 if (!this._queryParamMap) {
2005 this._queryParamMap = convertToParamMap(this.queryParams);
2006 }
2007 return this._queryParamMap;
2008 },
2009 enumerable: false,
2010 configurable: true
2011 });
2012 ActivatedRouteSnapshot.prototype.toString = function () {
2013 var url = this.url.map(function (segment) { return segment.toString(); }).join('/');
2014 var matched = this.routeConfig ? this.routeConfig.path : '';
2015 return "Route(url:'" + url + "', path:'" + matched + "')";
2016 };
2017 return ActivatedRouteSnapshot;
2018 }());
2019 /**
2020 * @description
2021 *
2022 * Represents the state of the router at a moment in time.
2023 *
2024 * This is a tree of activated route snapshots. Every node in this tree knows about
2025 * the "consumed" URL segments, the extracted parameters, and the resolved data.
2026 *
2027 * @usageNotes
2028 * ### Example
2029 *
2030 * ```
2031 * @Component({templateUrl:'template.html'})
2032 * class MyComponent {
2033 * constructor(router: Router) {
2034 * const state: RouterState = router.routerState;
2035 * const snapshot: RouterStateSnapshot = state.snapshot;
2036 * const root: ActivatedRouteSnapshot = snapshot.root;
2037 * const child = root.firstChild;
2038 * const id: Observable<string> = child.params.map(p => p.id);
2039 * //...
2040 * }
2041 * }
2042 * ```
2043 *
2044 * @publicApi
2045 */
2046 var RouterStateSnapshot = /** @class */ (function (_super) {
2047 __extends(RouterStateSnapshot, _super);
2048 /** @internal */
2049 function RouterStateSnapshot(
2050 /** The url from which this snapshot was created */
2051 url, root) {
2052 var _this = _super.call(this, root) || this;
2053 _this.url = url;
2054 setRouterState(_this, root);
2055 return _this;
2056 }
2057 RouterStateSnapshot.prototype.toString = function () {
2058 return serializeNode(this._root);
2059 };
2060 return RouterStateSnapshot;
2061 }(Tree));
2062 function setRouterState(state, node) {
2063 node.value._routerState = state;
2064 node.children.forEach(function (c) { return setRouterState(state, c); });
2065 }
2066 function serializeNode(node) {
2067 var c = node.children.length > 0 ? " { " + node.children.map(serializeNode).join(', ') + " } " : '';
2068 return "" + node.value + c;
2069 }
2070 /**
2071 * The expectation is that the activate route is created with the right set of parameters.
2072 * So we push new values into the observables only when they are not the initial values.
2073 * And we detect that by checking if the snapshot field is set.
2074 */
2075 function advanceActivatedRoute(route) {
2076 if (route.snapshot) {
2077 var currentSnapshot = route.snapshot;
2078 var nextSnapshot = route._futureSnapshot;
2079 route.snapshot = nextSnapshot;
2080 if (!shallowEqual(currentSnapshot.queryParams, nextSnapshot.queryParams)) {
2081 route.queryParams.next(nextSnapshot.queryParams);
2082 }
2083 if (currentSnapshot.fragment !== nextSnapshot.fragment) {
2084 route.fragment.next(nextSnapshot.fragment);
2085 }
2086 if (!shallowEqual(currentSnapshot.params, nextSnapshot.params)) {
2087 route.params.next(nextSnapshot.params);
2088 }
2089 if (!shallowEqualArrays(currentSnapshot.url, nextSnapshot.url)) {
2090 route.url.next(nextSnapshot.url);
2091 }
2092 if (!shallowEqual(currentSnapshot.data, nextSnapshot.data)) {
2093 route.data.next(nextSnapshot.data);
2094 }
2095 }
2096 else {
2097 route.snapshot = route._futureSnapshot;
2098 // this is for resolved data
2099 route.data.next(route._futureSnapshot.data);
2100 }
2101 }
2102 function equalParamsAndUrlSegments(a, b) {
2103 var equalUrlParams = shallowEqual(a.params, b.params) && equalSegments(a.url, b.url);
2104 var parentsMismatch = !a.parent !== !b.parent;
2105 return equalUrlParams && !parentsMismatch &&
2106 (!a.parent || equalParamsAndUrlSegments(a.parent, b.parent));
2107 }
2108
2109 /**
2110 * @license
2111 * Copyright Google LLC All Rights Reserved.
2112 *
2113 * Use of this source code is governed by an MIT-style license that can be
2114 * found in the LICENSE file at https://angular.io/license
2115 */
2116 function createRouterState(routeReuseStrategy, curr, prevState) {
2117 var root = createNode(routeReuseStrategy, curr._root, prevState ? prevState._root : undefined);
2118 return new RouterState(root, curr);
2119 }
2120 function createNode(routeReuseStrategy, curr, prevState) {
2121 // reuse an activated route that is currently displayed on the screen
2122 if (prevState && routeReuseStrategy.shouldReuseRoute(curr.value, prevState.value.snapshot)) {
2123 var value = prevState.value;
2124 value._futureSnapshot = curr.value;
2125 var children = createOrReuseChildren(routeReuseStrategy, curr, prevState);
2126 return new TreeNode(value, children);
2127 // retrieve an activated route that is used to be displayed, but is not currently displayed
2128 }
2129 else {
2130 var detachedRouteHandle = routeReuseStrategy.retrieve(curr.value);
2131 if (detachedRouteHandle) {
2132 var tree = detachedRouteHandle.route;
2133 setFutureSnapshotsOfActivatedRoutes(curr, tree);
2134 return tree;
2135 }
2136 else {
2137 var value = createActivatedRoute(curr.value);
2138 var children = curr.children.map(function (c) { return createNode(routeReuseStrategy, c); });
2139 return new TreeNode(value, children);
2140 }
2141 }
2142 }
2143 function setFutureSnapshotsOfActivatedRoutes(curr, result) {
2144 if (curr.value.routeConfig !== result.value.routeConfig) {
2145 throw new Error('Cannot reattach ActivatedRouteSnapshot created from a different route');
2146 }
2147 if (curr.children.length !== result.children.length) {
2148 throw new Error('Cannot reattach ActivatedRouteSnapshot with a different number of children');
2149 }
2150 result.value._futureSnapshot = curr.value;
2151 for (var i = 0; i < curr.children.length; ++i) {
2152 setFutureSnapshotsOfActivatedRoutes(curr.children[i], result.children[i]);
2153 }
2154 }
2155 function createOrReuseChildren(routeReuseStrategy, curr, prevState) {
2156 return curr.children.map(function (child) {
2157 var e_1, _a;
2158 try {
2159 for (var _b = __values(prevState.children), _c = _b.next(); !_c.done; _c = _b.next()) {
2160 var p = _c.value;
2161 if (routeReuseStrategy.shouldReuseRoute(p.value.snapshot, child.value)) {
2162 return createNode(routeReuseStrategy, child, p);
2163 }
2164 }
2165 }
2166 catch (e_1_1) { e_1 = { error: e_1_1 }; }
2167 finally {
2168 try {
2169 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2170 }
2171 finally { if (e_1) throw e_1.error; }
2172 }
2173 return createNode(routeReuseStrategy, child);
2174 });
2175 }
2176 function createActivatedRoute(c) {
2177 return new ActivatedRoute(new rxjs.BehaviorSubject(c.url), new rxjs.BehaviorSubject(c.params), new rxjs.BehaviorSubject(c.queryParams), new rxjs.BehaviorSubject(c.fragment), new rxjs.BehaviorSubject(c.data), c.outlet, c.component, c);
2178 }
2179
2180 /**
2181 * @license
2182 * Copyright Google LLC All Rights Reserved.
2183 *
2184 * Use of this source code is governed by an MIT-style license that can be
2185 * found in the LICENSE file at https://angular.io/license
2186 */
2187 function createUrlTree(route, urlTree, commands, queryParams, fragment) {
2188 if (commands.length === 0) {
2189 return tree(urlTree.root, urlTree.root, urlTree, queryParams, fragment);
2190 }
2191 var nav = computeNavigation(commands);
2192 if (nav.toRoot()) {
2193 return tree(urlTree.root, new UrlSegmentGroup([], {}), urlTree, queryParams, fragment);
2194 }
2195 var startingPosition = findStartingPosition(nav, urlTree, route);
2196 var segmentGroup = startingPosition.processChildren ?
2197 updateSegmentGroupChildren(startingPosition.segmentGroup, startingPosition.index, nav.commands) :
2198 updateSegmentGroup(startingPosition.segmentGroup, startingPosition.index, nav.commands);
2199 return tree(startingPosition.segmentGroup, segmentGroup, urlTree, queryParams, fragment);
2200 }
2201 function isMatrixParams(command) {
2202 return typeof command === 'object' && command != null && !command.outlets && !command.segmentPath;
2203 }
2204 function tree(oldSegmentGroup, newSegmentGroup, urlTree, queryParams, fragment) {
2205 var qp = {};
2206 if (queryParams) {
2207 forEach(queryParams, function (value, name) {
2208 qp[name] = Array.isArray(value) ? value.map(function (v) { return "" + v; }) : "" + value;
2209 });
2210 }
2211 if (urlTree.root === oldSegmentGroup) {
2212 return new UrlTree(newSegmentGroup, qp, fragment);
2213 }
2214 return new UrlTree(replaceSegment(urlTree.root, oldSegmentGroup, newSegmentGroup), qp, fragment);
2215 }
2216 function replaceSegment(current, oldSegment, newSegment) {
2217 var children = {};
2218 forEach(current.children, function (c, outletName) {
2219 if (c === oldSegment) {
2220 children[outletName] = newSegment;
2221 }
2222 else {
2223 children[outletName] = replaceSegment(c, oldSegment, newSegment);
2224 }
2225 });
2226 return new UrlSegmentGroup(current.segments, children);
2227 }
2228 var Navigation = /** @class */ (function () {
2229 function Navigation(isAbsolute, numberOfDoubleDots, commands) {
2230 this.isAbsolute = isAbsolute;
2231 this.numberOfDoubleDots = numberOfDoubleDots;
2232 this.commands = commands;
2233 if (isAbsolute && commands.length > 0 && isMatrixParams(commands[0])) {
2234 throw new Error('Root segment cannot have matrix parameters');
2235 }
2236 var cmdWithOutlet = commands.find(function (c) { return typeof c === 'object' && c != null && c.outlets; });
2237 if (cmdWithOutlet && cmdWithOutlet !== last(commands)) {
2238 throw new Error('{outlets:{}} has to be the last command');
2239 }
2240 }
2241 Navigation.prototype.toRoot = function () {
2242 return this.isAbsolute && this.commands.length === 1 && this.commands[0] == '/';
2243 };
2244 return Navigation;
2245 }());
2246 /** Transforms commands to a normalized `Navigation` */
2247 function computeNavigation(commands) {
2248 if ((typeof commands[0] === 'string') && commands.length === 1 && commands[0] === '/') {
2249 return new Navigation(true, 0, commands);
2250 }
2251 var numberOfDoubleDots = 0;
2252 var isAbsolute = false;
2253 var res = commands.reduce(function (res, cmd, cmdIdx) {
2254 if (typeof cmd === 'object' && cmd != null) {
2255 if (cmd.outlets) {
2256 var outlets_1 = {};
2257 forEach(cmd.outlets, function (commands, name) {
2258 outlets_1[name] = typeof commands === 'string' ? commands.split('/') : commands;
2259 });
2260 return __spread(res, [{ outlets: outlets_1 }]);
2261 }
2262 if (cmd.segmentPath) {
2263 return __spread(res, [cmd.segmentPath]);
2264 }
2265 }
2266 if (!(typeof cmd === 'string')) {
2267 return __spread(res, [cmd]);
2268 }
2269 if (cmdIdx === 0) {
2270 cmd.split('/').forEach(function (urlPart, partIndex) {
2271 if (partIndex == 0 && urlPart === '.') {
2272 // skip './a'
2273 }
2274 else if (partIndex == 0 && urlPart === '') { // '/a'
2275 isAbsolute = true;
2276 }
2277 else if (urlPart === '..') { // '../a'
2278 numberOfDoubleDots++;
2279 }
2280 else if (urlPart != '') {
2281 res.push(urlPart);
2282 }
2283 });
2284 return res;
2285 }
2286 return __spread(res, [cmd]);
2287 }, []);
2288 return new Navigation(isAbsolute, numberOfDoubleDots, res);
2289 }
2290 var Position = /** @class */ (function () {
2291 function Position(segmentGroup, processChildren, index) {
2292 this.segmentGroup = segmentGroup;
2293 this.processChildren = processChildren;
2294 this.index = index;
2295 }
2296 return Position;
2297 }());
2298 function findStartingPosition(nav, tree, route) {
2299 if (nav.isAbsolute) {
2300 return new Position(tree.root, true, 0);
2301 }
2302 if (route.snapshot._lastPathIndex === -1) {
2303 var segmentGroup = route.snapshot._urlSegment;
2304 // Pathless ActivatedRoute has _lastPathIndex === -1 but should not process children
2305 // see issue #26224, #13011, #35687
2306 // However, if the ActivatedRoute is the root we should process children like above.
2307 var processChildren = segmentGroup === tree.root;
2308 return new Position(segmentGroup, processChildren, 0);
2309 }
2310 var modifier = isMatrixParams(nav.commands[0]) ? 0 : 1;
2311 var index = route.snapshot._lastPathIndex + modifier;
2312 return createPositionApplyingDoubleDots(route.snapshot._urlSegment, index, nav.numberOfDoubleDots);
2313 }
2314 function createPositionApplyingDoubleDots(group, index, numberOfDoubleDots) {
2315 var g = group;
2316 var ci = index;
2317 var dd = numberOfDoubleDots;
2318 while (dd > ci) {
2319 dd -= ci;
2320 g = g.parent;
2321 if (!g) {
2322 throw new Error('Invalid number of \'../\'');
2323 }
2324 ci = g.segments.length;
2325 }
2326 return new Position(g, false, ci - dd);
2327 }
2328 function getPath(command) {
2329 if (typeof command === 'object' && command != null && command.outlets) {
2330 return command.outlets[PRIMARY_OUTLET];
2331 }
2332 return "" + command;
2333 }
2334 function getOutlets(commands) {
2335 var _a;
2336 if (typeof commands[0] === 'object' && commands[0] !== null && commands[0].outlets) {
2337 return commands[0].outlets;
2338 }
2339 return _a = {}, _a[PRIMARY_OUTLET] = commands, _a;
2340 }
2341 function updateSegmentGroup(segmentGroup, startIndex, commands) {
2342 if (!segmentGroup) {
2343 segmentGroup = new UrlSegmentGroup([], {});
2344 }
2345 if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
2346 return updateSegmentGroupChildren(segmentGroup, startIndex, commands);
2347 }
2348 var m = prefixedWith(segmentGroup, startIndex, commands);
2349 var slicedCommands = commands.slice(m.commandIndex);
2350 if (m.match && m.pathIndex < segmentGroup.segments.length) {
2351 var g = new UrlSegmentGroup(segmentGroup.segments.slice(0, m.pathIndex), {});
2352 g.children[PRIMARY_OUTLET] =
2353 new UrlSegmentGroup(segmentGroup.segments.slice(m.pathIndex), segmentGroup.children);
2354 return updateSegmentGroupChildren(g, 0, slicedCommands);
2355 }
2356 else if (m.match && slicedCommands.length === 0) {
2357 return new UrlSegmentGroup(segmentGroup.segments, {});
2358 }
2359 else if (m.match && !segmentGroup.hasChildren()) {
2360 return createNewSegmentGroup(segmentGroup, startIndex, commands);
2361 }
2362 else if (m.match) {
2363 return updateSegmentGroupChildren(segmentGroup, 0, slicedCommands);
2364 }
2365 else {
2366 return createNewSegmentGroup(segmentGroup, startIndex, commands);
2367 }
2368 }
2369 function updateSegmentGroupChildren(segmentGroup, startIndex, commands) {
2370 if (commands.length === 0) {
2371 return new UrlSegmentGroup(segmentGroup.segments, {});
2372 }
2373 else {
2374 var outlets_2 = getOutlets(commands);
2375 var children_1 = {};
2376 forEach(outlets_2, function (commands, outlet) {
2377 if (commands !== null) {
2378 children_1[outlet] = updateSegmentGroup(segmentGroup.children[outlet], startIndex, commands);
2379 }
2380 });
2381 forEach(segmentGroup.children, function (child, childOutlet) {
2382 if (outlets_2[childOutlet] === undefined) {
2383 children_1[childOutlet] = child;
2384 }
2385 });
2386 return new UrlSegmentGroup(segmentGroup.segments, children_1);
2387 }
2388 }
2389 function prefixedWith(segmentGroup, startIndex, commands) {
2390 var currentCommandIndex = 0;
2391 var currentPathIndex = startIndex;
2392 var noMatch = { match: false, pathIndex: 0, commandIndex: 0 };
2393 while (currentPathIndex < segmentGroup.segments.length) {
2394 if (currentCommandIndex >= commands.length)
2395 return noMatch;
2396 var path = segmentGroup.segments[currentPathIndex];
2397 var curr = getPath(commands[currentCommandIndex]);
2398 var next = currentCommandIndex < commands.length - 1 ? commands[currentCommandIndex + 1] : null;
2399 if (currentPathIndex > 0 && curr === undefined)
2400 break;
2401 if (curr && next && (typeof next === 'object') && next.outlets === undefined) {
2402 if (!compare(curr, next, path))
2403 return noMatch;
2404 currentCommandIndex += 2;
2405 }
2406 else {
2407 if (!compare(curr, {}, path))
2408 return noMatch;
2409 currentCommandIndex++;
2410 }
2411 currentPathIndex++;
2412 }
2413 return { match: true, pathIndex: currentPathIndex, commandIndex: currentCommandIndex };
2414 }
2415 function createNewSegmentGroup(segmentGroup, startIndex, commands) {
2416 var paths = segmentGroup.segments.slice(0, startIndex);
2417 var i = 0;
2418 while (i < commands.length) {
2419 if (typeof commands[i] === 'object' && commands[i] !== null &&
2420 commands[i].outlets !== undefined) {
2421 var children = createNewSegmentChildren(commands[i].outlets);
2422 return new UrlSegmentGroup(paths, children);
2423 }
2424 // if we start with an object literal, we need to reuse the path part from the segment
2425 if (i === 0 && isMatrixParams(commands[0])) {
2426 var p = segmentGroup.segments[startIndex];
2427 paths.push(new UrlSegment(p.path, commands[0]));
2428 i++;
2429 continue;
2430 }
2431 var curr = getPath(commands[i]);
2432 var next = (i < commands.length - 1) ? commands[i + 1] : null;
2433 if (curr && next && isMatrixParams(next)) {
2434 paths.push(new UrlSegment(curr, stringify(next)));
2435 i += 2;
2436 }
2437 else {
2438 paths.push(new UrlSegment(curr, {}));
2439 i++;
2440 }
2441 }
2442 return new UrlSegmentGroup(paths, {});
2443 }
2444 function createNewSegmentChildren(outlets) {
2445 var children = {};
2446 forEach(outlets, function (commands, outlet) {
2447 if (commands !== null) {
2448 children[outlet] = createNewSegmentGroup(new UrlSegmentGroup([], {}), 0, commands);
2449 }
2450 });
2451 return children;
2452 }
2453 function stringify(params) {
2454 var res = {};
2455 forEach(params, function (v, k) { return res[k] = "" + v; });
2456 return res;
2457 }
2458 function compare(path, params, segment) {
2459 return path == segment.path && shallowEqual(params, segment.parameters);
2460 }
2461
2462 /**
2463 * @license
2464 * Copyright Google LLC All Rights Reserved.
2465 *
2466 * Use of this source code is governed by an MIT-style license that can be
2467 * found in the LICENSE file at https://angular.io/license
2468 */
2469 var activateRoutes = function (rootContexts, routeReuseStrategy, forwardEvent) {
2470 return operators.map(function (t) {
2471 new ActivateRoutes(routeReuseStrategy, t.targetRouterState, t.currentRouterState, forwardEvent)
2472 .activate(rootContexts);
2473 return t;
2474 });
2475 };
2476 var ActivateRoutes = /** @class */ (function () {
2477 function ActivateRoutes(routeReuseStrategy, futureState, currState, forwardEvent) {
2478 this.routeReuseStrategy = routeReuseStrategy;
2479 this.futureState = futureState;
2480 this.currState = currState;
2481 this.forwardEvent = forwardEvent;
2482 }
2483 ActivateRoutes.prototype.activate = function (parentContexts) {
2484 var futureRoot = this.futureState._root;
2485 var currRoot = this.currState ? this.currState._root : null;
2486 this.deactivateChildRoutes(futureRoot, currRoot, parentContexts);
2487 advanceActivatedRoute(this.futureState.root);
2488 this.activateChildRoutes(futureRoot, currRoot, parentContexts);
2489 };
2490 // De-activate the child route that are not re-used for the future state
2491 ActivateRoutes.prototype.deactivateChildRoutes = function (futureNode, currNode, contexts) {
2492 var _this = this;
2493 var children = nodeChildrenAsMap(currNode);
2494 // Recurse on the routes active in the future state to de-activate deeper children
2495 futureNode.children.forEach(function (futureChild) {
2496 var childOutletName = futureChild.value.outlet;
2497 _this.deactivateRoutes(futureChild, children[childOutletName], contexts);
2498 delete children[childOutletName];
2499 });
2500 // De-activate the routes that will not be re-used
2501 forEach(children, function (v, childName) {
2502 _this.deactivateRouteAndItsChildren(v, contexts);
2503 });
2504 };
2505 ActivateRoutes.prototype.deactivateRoutes = function (futureNode, currNode, parentContext) {
2506 var future = futureNode.value;
2507 var curr = currNode ? currNode.value : null;
2508 if (future === curr) {
2509 // Reusing the node, check to see if the children need to be de-activated
2510 if (future.component) {
2511 // If we have a normal route, we need to go through an outlet.
2512 var context = parentContext.getContext(future.outlet);
2513 if (context) {
2514 this.deactivateChildRoutes(futureNode, currNode, context.children);
2515 }
2516 }
2517 else {
2518 // if we have a componentless route, we recurse but keep the same outlet map.
2519 this.deactivateChildRoutes(futureNode, currNode, parentContext);
2520 }
2521 }
2522 else {
2523 if (curr) {
2524 // Deactivate the current route which will not be re-used
2525 this.deactivateRouteAndItsChildren(currNode, parentContext);
2526 }
2527 }
2528 };
2529 ActivateRoutes.prototype.deactivateRouteAndItsChildren = function (route, parentContexts) {
2530 if (this.routeReuseStrategy.shouldDetach(route.value.snapshot)) {
2531 this.detachAndStoreRouteSubtree(route, parentContexts);
2532 }
2533 else {
2534 this.deactivateRouteAndOutlet(route, parentContexts);
2535 }
2536 };
2537 ActivateRoutes.prototype.detachAndStoreRouteSubtree = function (route, parentContexts) {
2538 var context = parentContexts.getContext(route.value.outlet);
2539 if (context && context.outlet) {
2540 var componentRef = context.outlet.detach();
2541 var contexts = context.children.onOutletDeactivated();
2542 this.routeReuseStrategy.store(route.value.snapshot, { componentRef: componentRef, route: route, contexts: contexts });
2543 }
2544 };
2545 ActivateRoutes.prototype.deactivateRouteAndOutlet = function (route, parentContexts) {
2546 var _this = this;
2547 var context = parentContexts.getContext(route.value.outlet);
2548 if (context) {
2549 var children = nodeChildrenAsMap(route);
2550 var contexts_1 = route.value.component ? context.children : parentContexts;
2551 forEach(children, function (v, k) { return _this.deactivateRouteAndItsChildren(v, contexts_1); });
2552 if (context.outlet) {
2553 // Destroy the component
2554 context.outlet.deactivate();
2555 // Destroy the contexts for all the outlets that were in the component
2556 context.children.onOutletDeactivated();
2557 }
2558 }
2559 };
2560 ActivateRoutes.prototype.activateChildRoutes = function (futureNode, currNode, contexts) {
2561 var _this = this;
2562 var children = nodeChildrenAsMap(currNode);
2563 futureNode.children.forEach(function (c) {
2564 _this.activateRoutes(c, children[c.value.outlet], contexts);
2565 _this.forwardEvent(new ActivationEnd(c.value.snapshot));
2566 });
2567 if (futureNode.children.length) {
2568 this.forwardEvent(new ChildActivationEnd(futureNode.value.snapshot));
2569 }
2570 };
2571 ActivateRoutes.prototype.activateRoutes = function (futureNode, currNode, parentContexts) {
2572 var future = futureNode.value;
2573 var curr = currNode ? currNode.value : null;
2574 advanceActivatedRoute(future);
2575 // reusing the node
2576 if (future === curr) {
2577 if (future.component) {
2578 // If we have a normal route, we need to go through an outlet.
2579 var context = parentContexts.getOrCreateContext(future.outlet);
2580 this.activateChildRoutes(futureNode, currNode, context.children);
2581 }
2582 else {
2583 // if we have a componentless route, we recurse but keep the same outlet map.
2584 this.activateChildRoutes(futureNode, currNode, parentContexts);
2585 }
2586 }
2587 else {
2588 if (future.component) {
2589 // if we have a normal route, we need to place the component into the outlet and recurse.
2590 var context = parentContexts.getOrCreateContext(future.outlet);
2591 if (this.routeReuseStrategy.shouldAttach(future.snapshot)) {
2592 var stored = this.routeReuseStrategy.retrieve(future.snapshot);
2593 this.routeReuseStrategy.store(future.snapshot, null);
2594 context.children.onOutletReAttached(stored.contexts);
2595 context.attachRef = stored.componentRef;
2596 context.route = stored.route.value;
2597 if (context.outlet) {
2598 // Attach right away when the outlet has already been instantiated
2599 // Otherwise attach from `RouterOutlet.ngOnInit` when it is instantiated
2600 context.outlet.attach(stored.componentRef, stored.route.value);
2601 }
2602 advanceActivatedRouteNodeAndItsChildren(stored.route);
2603 }
2604 else {
2605 var config = parentLoadedConfig(future.snapshot);
2606 var cmpFactoryResolver = config ? config.module.componentFactoryResolver : null;
2607 context.attachRef = null;
2608 context.route = future;
2609 context.resolver = cmpFactoryResolver;
2610 if (context.outlet) {
2611 // Activate the outlet when it has already been instantiated
2612 // Otherwise it will get activated from its `ngOnInit` when instantiated
2613 context.outlet.activateWith(future, cmpFactoryResolver);
2614 }
2615 this.activateChildRoutes(futureNode, null, context.children);
2616 }
2617 }
2618 else {
2619 // if we have a componentless route, we recurse but keep the same outlet map.
2620 this.activateChildRoutes(futureNode, null, parentContexts);
2621 }
2622 }
2623 };
2624 return ActivateRoutes;
2625 }());
2626 function advanceActivatedRouteNodeAndItsChildren(node) {
2627 advanceActivatedRoute(node.value);
2628 node.children.forEach(advanceActivatedRouteNodeAndItsChildren);
2629 }
2630 function parentLoadedConfig(snapshot) {
2631 for (var s = snapshot.parent; s; s = s.parent) {
2632 var route = s.routeConfig;
2633 if (route && route._loadedConfig)
2634 return route._loadedConfig;
2635 if (route && route.component)
2636 return null;
2637 }
2638 return null;
2639 }
2640
2641 /**
2642 * @license
2643 * Copyright Google LLC All Rights Reserved.
2644 *
2645 * Use of this source code is governed by an MIT-style license that can be
2646 * found in the LICENSE file at https://angular.io/license
2647 */
2648 /**
2649 * Simple function check, but generic so type inference will flow. Example:
2650 *
2651 * function product(a: number, b: number) {
2652 * return a * b;
2653 * }
2654 *
2655 * if (isFunction<product>(fn)) {
2656 * return fn(1, 2);
2657 * } else {
2658 * throw "Must provide the `product` function";
2659 * }
2660 */
2661 function isFunction(v) {
2662 return typeof v === 'function';
2663 }
2664 function isBoolean(v) {
2665 return typeof v === 'boolean';
2666 }
2667 function isUrlTree(v) {
2668 return v instanceof UrlTree;
2669 }
2670 function isCanLoad(guard) {
2671 return guard && isFunction(guard.canLoad);
2672 }
2673 function isCanActivate(guard) {
2674 return guard && isFunction(guard.canActivate);
2675 }
2676 function isCanActivateChild(guard) {
2677 return guard && isFunction(guard.canActivateChild);
2678 }
2679 function isCanDeactivate(guard) {
2680 return guard && isFunction(guard.canDeactivate);
2681 }
2682
2683 /**
2684 * @license
2685 * Copyright Google LLC All Rights Reserved.
2686 *
2687 * Use of this source code is governed by an MIT-style license that can be
2688 * found in the LICENSE file at https://angular.io/license
2689 */
2690 var NoMatch = /** @class */ (function () {
2691 function NoMatch(segmentGroup) {
2692 this.segmentGroup = segmentGroup || null;
2693 }
2694 return NoMatch;
2695 }());
2696 var AbsoluteRedirect = /** @class */ (function () {
2697 function AbsoluteRedirect(urlTree) {
2698 this.urlTree = urlTree;
2699 }
2700 return AbsoluteRedirect;
2701 }());
2702 function noMatch(segmentGroup) {
2703 return new rxjs.Observable(function (obs) { return obs.error(new NoMatch(segmentGroup)); });
2704 }
2705 function absoluteRedirect(newTree) {
2706 return new rxjs.Observable(function (obs) { return obs.error(new AbsoluteRedirect(newTree)); });
2707 }
2708 function namedOutletsRedirect(redirectTo) {
2709 return new rxjs.Observable(function (obs) { return obs.error(new Error("Only absolute redirects can have named outlets. redirectTo: '" + redirectTo + "'")); });
2710 }
2711 function canLoadFails(route) {
2712 return new rxjs.Observable(function (obs) { return obs.error(navigationCancelingError("Cannot load children because the guard of the route \"path: '" + route.path + "'\" returned false")); });
2713 }
2714 /**
2715 * Returns the `UrlTree` with the redirection applied.
2716 *
2717 * Lazy modules are loaded along the way.
2718 */
2719 function applyRedirects(moduleInjector, configLoader, urlSerializer, urlTree, config) {
2720 return new ApplyRedirects(moduleInjector, configLoader, urlSerializer, urlTree, config).apply();
2721 }
2722 var ApplyRedirects = /** @class */ (function () {
2723 function ApplyRedirects(moduleInjector, configLoader, urlSerializer, urlTree, config) {
2724 this.configLoader = configLoader;
2725 this.urlSerializer = urlSerializer;
2726 this.urlTree = urlTree;
2727 this.config = config;
2728 this.allowRedirects = true;
2729 this.ngModule = moduleInjector.get(core.NgModuleRef);
2730 }
2731 ApplyRedirects.prototype.apply = function () {
2732 var _this = this;
2733 var expanded$ = this.expandSegmentGroup(this.ngModule, this.config, this.urlTree.root, PRIMARY_OUTLET);
2734 var urlTrees$ = expanded$.pipe(operators.map(function (rootSegmentGroup) { return _this.createUrlTree(rootSegmentGroup, _this.urlTree.queryParams, _this.urlTree.fragment); }));
2735 return urlTrees$.pipe(operators.catchError(function (e) {
2736 if (e instanceof AbsoluteRedirect) {
2737 // after an absolute redirect we do not apply any more redirects!
2738 _this.allowRedirects = false;
2739 // we need to run matching, so we can fetch all lazy-loaded modules
2740 return _this.match(e.urlTree);
2741 }
2742 if (e instanceof NoMatch) {
2743 throw _this.noMatchError(e);
2744 }
2745 throw e;
2746 }));
2747 };
2748 ApplyRedirects.prototype.match = function (tree) {
2749 var _this = this;
2750 var expanded$ = this.expandSegmentGroup(this.ngModule, this.config, tree.root, PRIMARY_OUTLET);
2751 var mapped$ = expanded$.pipe(operators.map(function (rootSegmentGroup) {
2752 return _this.createUrlTree(rootSegmentGroup, tree.queryParams, tree.fragment);
2753 }));
2754 return mapped$.pipe(operators.catchError(function (e) {
2755 if (e instanceof NoMatch) {
2756 throw _this.noMatchError(e);
2757 }
2758 throw e;
2759 }));
2760 };
2761 ApplyRedirects.prototype.noMatchError = function (e) {
2762 return new Error("Cannot match any routes. URL Segment: '" + e.segmentGroup + "'");
2763 };
2764 ApplyRedirects.prototype.createUrlTree = function (rootCandidate, queryParams, fragment) {
2765 var _a;
2766 var root = rootCandidate.segments.length > 0 ?
2767 new UrlSegmentGroup([], (_a = {}, _a[PRIMARY_OUTLET] = rootCandidate, _a)) :
2768 rootCandidate;
2769 return new UrlTree(root, queryParams, fragment);
2770 };
2771 ApplyRedirects.prototype.expandSegmentGroup = function (ngModule, routes, segmentGroup, outlet) {
2772 if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
2773 return this.expandChildren(ngModule, routes, segmentGroup)
2774 .pipe(operators.map(function (children) { return new UrlSegmentGroup([], children); }));
2775 }
2776 return this.expandSegment(ngModule, segmentGroup, routes, segmentGroup.segments, outlet, true);
2777 };
2778 // Recursively expand segment groups for all the child outlets
2779 ApplyRedirects.prototype.expandChildren = function (ngModule, routes, segmentGroup) {
2780 var _this = this;
2781 return waitForMap(segmentGroup.children, function (childOutlet, child) { return _this.expandSegmentGroup(ngModule, routes, child, childOutlet); });
2782 };
2783 ApplyRedirects.prototype.expandSegment = function (ngModule, segmentGroup, routes, segments, outlet, allowRedirects) {
2784 var _this = this;
2785 return rxjs.of.apply(void 0, __spread(routes)).pipe(operators.map(function (r) {
2786 var expanded$ = _this.expandSegmentAgainstRoute(ngModule, segmentGroup, routes, r, segments, outlet, allowRedirects);
2787 return expanded$.pipe(operators.catchError(function (e) {
2788 if (e instanceof NoMatch) {
2789 // TODO(i): this return type doesn't match the declared Observable<UrlSegmentGroup> -
2790 // talk to Jason
2791 return rxjs.of(null);
2792 }
2793 throw e;
2794 }));
2795 }), operators.concatAll(), operators.first(function (s) { return !!s; }), operators.catchError(function (e, _) {
2796 if (e instanceof rxjs.EmptyError || e.name === 'EmptyError') {
2797 if (_this.noLeftoversInUrl(segmentGroup, segments, outlet)) {
2798 return rxjs.of(new UrlSegmentGroup([], {}));
2799 }
2800 throw new NoMatch(segmentGroup);
2801 }
2802 throw e;
2803 }));
2804 };
2805 ApplyRedirects.prototype.noLeftoversInUrl = function (segmentGroup, segments, outlet) {
2806 return segments.length === 0 && !segmentGroup.children[outlet];
2807 };
2808 ApplyRedirects.prototype.expandSegmentAgainstRoute = function (ngModule, segmentGroup, routes, route, paths, outlet, allowRedirects) {
2809 if (getOutlet(route) !== outlet) {
2810 return noMatch(segmentGroup);
2811 }
2812 if (route.redirectTo === undefined) {
2813 return this.matchSegmentAgainstRoute(ngModule, segmentGroup, route, paths);
2814 }
2815 if (allowRedirects && this.allowRedirects) {
2816 return this.expandSegmentAgainstRouteUsingRedirect(ngModule, segmentGroup, routes, route, paths, outlet);
2817 }
2818 return noMatch(segmentGroup);
2819 };
2820 ApplyRedirects.prototype.expandSegmentAgainstRouteUsingRedirect = function (ngModule, segmentGroup, routes, route, segments, outlet) {
2821 if (route.path === '**') {
2822 return this.expandWildCardWithParamsAgainstRouteUsingRedirect(ngModule, routes, route, outlet);
2823 }
2824 return this.expandRegularSegmentAgainstRouteUsingRedirect(ngModule, segmentGroup, routes, route, segments, outlet);
2825 };
2826 ApplyRedirects.prototype.expandWildCardWithParamsAgainstRouteUsingRedirect = function (ngModule, routes, route, outlet) {
2827 var _this = this;
2828 var newTree = this.applyRedirectCommands([], route.redirectTo, {});
2829 if (route.redirectTo.startsWith('/')) {
2830 return absoluteRedirect(newTree);
2831 }
2832 return this.lineralizeSegments(route, newTree).pipe(operators.mergeMap(function (newSegments) {
2833 var group = new UrlSegmentGroup(newSegments, {});
2834 return _this.expandSegment(ngModule, group, routes, newSegments, outlet, false);
2835 }));
2836 };
2837 ApplyRedirects.prototype.expandRegularSegmentAgainstRouteUsingRedirect = function (ngModule, segmentGroup, routes, route, segments, outlet) {
2838 var _this = this;
2839 var _a = match(segmentGroup, route, segments), matched = _a.matched, consumedSegments = _a.consumedSegments, lastChild = _a.lastChild, positionalParamSegments = _a.positionalParamSegments;
2840 if (!matched)
2841 return noMatch(segmentGroup);
2842 var newTree = this.applyRedirectCommands(consumedSegments, route.redirectTo, positionalParamSegments);
2843 if (route.redirectTo.startsWith('/')) {
2844 return absoluteRedirect(newTree);
2845 }
2846 return this.lineralizeSegments(route, newTree).pipe(operators.mergeMap(function (newSegments) {
2847 return _this.expandSegment(ngModule, segmentGroup, routes, newSegments.concat(segments.slice(lastChild)), outlet, false);
2848 }));
2849 };
2850 ApplyRedirects.prototype.matchSegmentAgainstRoute = function (ngModule, rawSegmentGroup, route, segments) {
2851 var _this = this;
2852 if (route.path === '**') {
2853 if (route.loadChildren) {
2854 return this.configLoader.load(ngModule.injector, route)
2855 .pipe(operators.map(function (cfg) {
2856 route._loadedConfig = cfg;
2857 return new UrlSegmentGroup(segments, {});
2858 }));
2859 }
2860 return rxjs.of(new UrlSegmentGroup(segments, {}));
2861 }
2862 var _a = match(rawSegmentGroup, route, segments), matched = _a.matched, consumedSegments = _a.consumedSegments, lastChild = _a.lastChild;
2863 if (!matched)
2864 return noMatch(rawSegmentGroup);
2865 var rawSlicedSegments = segments.slice(lastChild);
2866 var childConfig$ = this.getChildConfig(ngModule, route, segments);
2867 return childConfig$.pipe(operators.mergeMap(function (routerConfig) {
2868 var childModule = routerConfig.module;
2869 var childConfig = routerConfig.routes;
2870 var _a = split(rawSegmentGroup, consumedSegments, rawSlicedSegments, childConfig), segmentGroup = _a.segmentGroup, slicedSegments = _a.slicedSegments;
2871 if (slicedSegments.length === 0 && segmentGroup.hasChildren()) {
2872 var expanded$_1 = _this.expandChildren(childModule, childConfig, segmentGroup);
2873 return expanded$_1.pipe(operators.map(function (children) { return new UrlSegmentGroup(consumedSegments, children); }));
2874 }
2875 if (childConfig.length === 0 && slicedSegments.length === 0) {
2876 return rxjs.of(new UrlSegmentGroup(consumedSegments, {}));
2877 }
2878 var expanded$ = _this.expandSegment(childModule, segmentGroup, childConfig, slicedSegments, PRIMARY_OUTLET, true);
2879 return expanded$.pipe(operators.map(function (cs) {
2880 return new UrlSegmentGroup(consumedSegments.concat(cs.segments), cs.children);
2881 }));
2882 }));
2883 };
2884 ApplyRedirects.prototype.getChildConfig = function (ngModule, route, segments) {
2885 var _this = this;
2886 if (route.children) {
2887 // The children belong to the same module
2888 return rxjs.of(new LoadedRouterConfig(route.children, ngModule));
2889 }
2890 if (route.loadChildren) {
2891 // lazy children belong to the loaded module
2892 if (route._loadedConfig !== undefined) {
2893 return rxjs.of(route._loadedConfig);
2894 }
2895 return this.runCanLoadGuards(ngModule.injector, route, segments)
2896 .pipe(operators.mergeMap(function (shouldLoadResult) {
2897 if (shouldLoadResult) {
2898 return _this.configLoader.load(ngModule.injector, route)
2899 .pipe(operators.map(function (cfg) {
2900 route._loadedConfig = cfg;
2901 return cfg;
2902 }));
2903 }
2904 return canLoadFails(route);
2905 }));
2906 }
2907 return rxjs.of(new LoadedRouterConfig([], ngModule));
2908 };
2909 ApplyRedirects.prototype.runCanLoadGuards = function (moduleInjector, route, segments) {
2910 var _this = this;
2911 var canLoad = route.canLoad;
2912 if (!canLoad || canLoad.length === 0)
2913 return rxjs.of(true);
2914 var obs = rxjs.from(canLoad).pipe(operators.map(function (injectionToken) {
2915 var guard = moduleInjector.get(injectionToken);
2916 var guardVal;
2917 if (isCanLoad(guard)) {
2918 guardVal = guard.canLoad(route, segments);
2919 }
2920 else if (isFunction(guard)) {
2921 guardVal = guard(route, segments);
2922 }
2923 else {
2924 throw new Error('Invalid CanLoad guard');
2925 }
2926 return wrapIntoObservable(guardVal);
2927 }));
2928 return obs.pipe(operators.concatAll(), operators.tap(function (result) {
2929 if (!isUrlTree(result))
2930 return;
2931 var error = navigationCancelingError("Redirecting to \"" + _this.urlSerializer.serialize(result) + "\"");
2932 error.url = result;
2933 throw error;
2934 }), operators.every(function (result) { return result === true; }));
2935 };
2936 ApplyRedirects.prototype.lineralizeSegments = function (route, urlTree) {
2937 var res = [];
2938 var c = urlTree.root;
2939 while (true) {
2940 res = res.concat(c.segments);
2941 if (c.numberOfChildren === 0) {
2942 return rxjs.of(res);
2943 }
2944 if (c.numberOfChildren > 1 || !c.children[PRIMARY_OUTLET]) {
2945 return namedOutletsRedirect(route.redirectTo);
2946 }
2947 c = c.children[PRIMARY_OUTLET];
2948 }
2949 };
2950 ApplyRedirects.prototype.applyRedirectCommands = function (segments, redirectTo, posParams) {
2951 return this.applyRedirectCreatreUrlTree(redirectTo, this.urlSerializer.parse(redirectTo), segments, posParams);
2952 };
2953 ApplyRedirects.prototype.applyRedirectCreatreUrlTree = function (redirectTo, urlTree, segments, posParams) {
2954 var newRoot = this.createSegmentGroup(redirectTo, urlTree.root, segments, posParams);
2955 return new UrlTree(newRoot, this.createQueryParams(urlTree.queryParams, this.urlTree.queryParams), urlTree.fragment);
2956 };
2957 ApplyRedirects.prototype.createQueryParams = function (redirectToParams, actualParams) {
2958 var res = {};
2959 forEach(redirectToParams, function (v, k) {
2960 var copySourceValue = typeof v === 'string' && v.startsWith(':');
2961 if (copySourceValue) {
2962 var sourceName = v.substring(1);
2963 res[k] = actualParams[sourceName];
2964 }
2965 else {
2966 res[k] = v;
2967 }
2968 });
2969 return res;
2970 };
2971 ApplyRedirects.prototype.createSegmentGroup = function (redirectTo, group, segments, posParams) {
2972 var _this = this;
2973 var updatedSegments = this.createSegments(redirectTo, group.segments, segments, posParams);
2974 var children = {};
2975 forEach(group.children, function (child, name) {
2976 children[name] = _this.createSegmentGroup(redirectTo, child, segments, posParams);
2977 });
2978 return new UrlSegmentGroup(updatedSegments, children);
2979 };
2980 ApplyRedirects.prototype.createSegments = function (redirectTo, redirectToSegments, actualSegments, posParams) {
2981 var _this = this;
2982 return redirectToSegments.map(function (s) { return s.path.startsWith(':') ? _this.findPosParam(redirectTo, s, posParams) :
2983 _this.findOrReturn(s, actualSegments); });
2984 };
2985 ApplyRedirects.prototype.findPosParam = function (redirectTo, redirectToUrlSegment, posParams) {
2986 var pos = posParams[redirectToUrlSegment.path.substring(1)];
2987 if (!pos)
2988 throw new Error("Cannot redirect to '" + redirectTo + "'. Cannot find '" + redirectToUrlSegment.path + "'.");
2989 return pos;
2990 };
2991 ApplyRedirects.prototype.findOrReturn = function (redirectToUrlSegment, actualSegments) {
2992 var e_1, _a;
2993 var idx = 0;
2994 try {
2995 for (var actualSegments_1 = __values(actualSegments), actualSegments_1_1 = actualSegments_1.next(); !actualSegments_1_1.done; actualSegments_1_1 = actualSegments_1.next()) {
2996 var s = actualSegments_1_1.value;
2997 if (s.path === redirectToUrlSegment.path) {
2998 actualSegments.splice(idx);
2999 return s;
3000 }
3001 idx++;
3002 }
3003 }
3004 catch (e_1_1) { e_1 = { error: e_1_1 }; }
3005 finally {
3006 try {
3007 if (actualSegments_1_1 && !actualSegments_1_1.done && (_a = actualSegments_1.return)) _a.call(actualSegments_1);
3008 }
3009 finally { if (e_1) throw e_1.error; }
3010 }
3011 return redirectToUrlSegment;
3012 };
3013 return ApplyRedirects;
3014 }());
3015 function match(segmentGroup, route, segments) {
3016 if (route.path === '') {
3017 if ((route.pathMatch === 'full') && (segmentGroup.hasChildren() || segments.length > 0)) {
3018 return { matched: false, consumedSegments: [], lastChild: 0, positionalParamSegments: {} };
3019 }
3020 return { matched: true, consumedSegments: [], lastChild: 0, positionalParamSegments: {} };
3021 }
3022 var matcher = route.matcher || defaultUrlMatcher;
3023 var res = matcher(segments, segmentGroup, route);
3024 if (!res) {
3025 return {
3026 matched: false,
3027 consumedSegments: [],
3028 lastChild: 0,
3029 positionalParamSegments: {},
3030 };
3031 }
3032 return {
3033 matched: true,
3034 consumedSegments: res.consumed,
3035 lastChild: res.consumed.length,
3036 positionalParamSegments: res.posParams,
3037 };
3038 }
3039 function split(segmentGroup, consumedSegments, slicedSegments, config) {
3040 if (slicedSegments.length > 0 &&
3041 containsEmptyPathRedirectsWithNamedOutlets(segmentGroup, slicedSegments, config)) {
3042 var s = new UrlSegmentGroup(consumedSegments, createChildrenForEmptySegments(config, new UrlSegmentGroup(slicedSegments, segmentGroup.children)));
3043 return { segmentGroup: mergeTrivialChildren(s), slicedSegments: [] };
3044 }
3045 if (slicedSegments.length === 0 &&
3046 containsEmptyPathRedirects(segmentGroup, slicedSegments, config)) {
3047 var s = new UrlSegmentGroup(segmentGroup.segments, addEmptySegmentsToChildrenIfNeeded(segmentGroup, slicedSegments, config, segmentGroup.children));
3048 return { segmentGroup: mergeTrivialChildren(s), slicedSegments: slicedSegments };
3049 }
3050 return { segmentGroup: segmentGroup, slicedSegments: slicedSegments };
3051 }
3052 function mergeTrivialChildren(s) {
3053 if (s.numberOfChildren === 1 && s.children[PRIMARY_OUTLET]) {
3054 var c = s.children[PRIMARY_OUTLET];
3055 return new UrlSegmentGroup(s.segments.concat(c.segments), c.children);
3056 }
3057 return s;
3058 }
3059 function addEmptySegmentsToChildrenIfNeeded(segmentGroup, slicedSegments, routes, children) {
3060 var e_2, _a;
3061 var res = {};
3062 try {
3063 for (var routes_1 = __values(routes), routes_1_1 = routes_1.next(); !routes_1_1.done; routes_1_1 = routes_1.next()) {
3064 var r = routes_1_1.value;
3065 if (isEmptyPathRedirect(segmentGroup, slicedSegments, r) && !children[getOutlet(r)]) {
3066 res[getOutlet(r)] = new UrlSegmentGroup([], {});
3067 }
3068 }
3069 }
3070 catch (e_2_1) { e_2 = { error: e_2_1 }; }
3071 finally {
3072 try {
3073 if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
3074 }
3075 finally { if (e_2) throw e_2.error; }
3076 }
3077 return __assign(__assign({}, children), res);
3078 }
3079 function createChildrenForEmptySegments(routes, primarySegmentGroup) {
3080 var e_3, _a;
3081 var res = {};
3082 res[PRIMARY_OUTLET] = primarySegmentGroup;
3083 try {
3084 for (var routes_2 = __values(routes), routes_2_1 = routes_2.next(); !routes_2_1.done; routes_2_1 = routes_2.next()) {
3085 var r = routes_2_1.value;
3086 if (r.path === '' && getOutlet(r) !== PRIMARY_OUTLET) {
3087 res[getOutlet(r)] = new UrlSegmentGroup([], {});
3088 }
3089 }
3090 }
3091 catch (e_3_1) { e_3 = { error: e_3_1 }; }
3092 finally {
3093 try {
3094 if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
3095 }
3096 finally { if (e_3) throw e_3.error; }
3097 }
3098 return res;
3099 }
3100 function containsEmptyPathRedirectsWithNamedOutlets(segmentGroup, segments, routes) {
3101 return routes.some(function (r) { return isEmptyPathRedirect(segmentGroup, segments, r) && getOutlet(r) !== PRIMARY_OUTLET; });
3102 }
3103 function containsEmptyPathRedirects(segmentGroup, segments, routes) {
3104 return routes.some(function (r) { return isEmptyPathRedirect(segmentGroup, segments, r); });
3105 }
3106 function isEmptyPathRedirect(segmentGroup, segments, r) {
3107 if ((segmentGroup.hasChildren() || segments.length > 0) && r.pathMatch === 'full') {
3108 return false;
3109 }
3110 return r.path === '' && r.redirectTo !== undefined;
3111 }
3112 function getOutlet(route) {
3113 return route.outlet || PRIMARY_OUTLET;
3114 }
3115
3116 /**
3117 * @license
3118 * Copyright Google LLC All Rights Reserved.
3119 *
3120 * Use of this source code is governed by an MIT-style license that can be
3121 * found in the LICENSE file at https://angular.io/license
3122 */
3123 function applyRedirects$1(moduleInjector, configLoader, urlSerializer, config) {
3124 return function (source) {
3125 return source.pipe(operators.switchMap(function (t) { return applyRedirects(moduleInjector, configLoader, urlSerializer, t.extractedUrl, config)
3126 .pipe(operators.map(function (urlAfterRedirects) { return (__assign(__assign({}, t), { urlAfterRedirects: urlAfterRedirects })); })); }));
3127 };
3128 }
3129
3130 /**
3131 * @license
3132 * Copyright Google LLC All Rights Reserved.
3133 *
3134 * Use of this source code is governed by an MIT-style license that can be
3135 * found in the LICENSE file at https://angular.io/license
3136 */
3137 var CanActivate = /** @class */ (function () {
3138 function CanActivate(path) {
3139 this.path = path;
3140 this.route = this.path[this.path.length - 1];
3141 }
3142 return CanActivate;
3143 }());
3144 var CanDeactivate = /** @class */ (function () {
3145 function CanDeactivate(component, route) {
3146 this.component = component;
3147 this.route = route;
3148 }
3149 return CanDeactivate;
3150 }());
3151 function getAllRouteGuards(future, curr, parentContexts) {
3152 var futureRoot = future._root;
3153 var currRoot = curr ? curr._root : null;
3154 return getChildRouteGuards(futureRoot, currRoot, parentContexts, [futureRoot.value]);
3155 }
3156 function getCanActivateChild(p) {
3157 var canActivateChild = p.routeConfig ? p.routeConfig.canActivateChild : null;
3158 if (!canActivateChild || canActivateChild.length === 0)
3159 return null;
3160 return { node: p, guards: canActivateChild };
3161 }
3162 function getToken(token, snapshot, moduleInjector) {
3163 var config = getClosestLoadedConfig(snapshot);
3164 var injector = config ? config.module.injector : moduleInjector;
3165 return injector.get(token);
3166 }
3167 function getClosestLoadedConfig(snapshot) {
3168 if (!snapshot)
3169 return null;
3170 for (var s = snapshot.parent; s; s = s.parent) {
3171 var route = s.routeConfig;
3172 if (route && route._loadedConfig)
3173 return route._loadedConfig;
3174 }
3175 return null;
3176 }
3177 function getChildRouteGuards(futureNode, currNode, contexts, futurePath, checks) {
3178 if (checks === void 0) { checks = {
3179 canDeactivateChecks: [],
3180 canActivateChecks: []
3181 }; }
3182 var prevChildren = nodeChildrenAsMap(currNode);
3183 // Process the children of the future route
3184 futureNode.children.forEach(function (c) {
3185 getRouteGuards(c, prevChildren[c.value.outlet], contexts, futurePath.concat([c.value]), checks);
3186 delete prevChildren[c.value.outlet];
3187 });
3188 // Process any children left from the current route (not active for the future route)
3189 forEach(prevChildren, function (v, k) {
3190 return deactivateRouteAndItsChildren(v, contexts.getContext(k), checks);
3191 });
3192 return checks;
3193 }
3194 function getRouteGuards(futureNode, currNode, parentContexts, futurePath, checks) {
3195 if (checks === void 0) { checks = {
3196 canDeactivateChecks: [],
3197 canActivateChecks: []
3198 }; }
3199 var future = futureNode.value;
3200 var curr = currNode ? currNode.value : null;
3201 var context = parentContexts ? parentContexts.getContext(futureNode.value.outlet) : null;
3202 // reusing the node
3203 if (curr && future.routeConfig === curr.routeConfig) {
3204 var shouldRun = shouldRunGuardsAndResolvers(curr, future, future.routeConfig.runGuardsAndResolvers);
3205 if (shouldRun) {
3206 checks.canActivateChecks.push(new CanActivate(futurePath));
3207 }
3208 else {
3209 // we need to set the data
3210 future.data = curr.data;
3211 future._resolvedData = curr._resolvedData;
3212 }
3213 // If we have a component, we need to go through an outlet.
3214 if (future.component) {
3215 getChildRouteGuards(futureNode, currNode, context ? context.children : null, futurePath, checks);
3216 // if we have a componentless route, we recurse but keep the same outlet map.
3217 }
3218 else {
3219 getChildRouteGuards(futureNode, currNode, parentContexts, futurePath, checks);
3220 }
3221 if (shouldRun) {
3222 var component = context && context.outlet && context.outlet.component || null;
3223 checks.canDeactivateChecks.push(new CanDeactivate(component, curr));
3224 }
3225 }
3226 else {
3227 if (curr) {
3228 deactivateRouteAndItsChildren(currNode, context, checks);
3229 }
3230 checks.canActivateChecks.push(new CanActivate(futurePath));
3231 // If we have a component, we need to go through an outlet.
3232 if (future.component) {
3233 getChildRouteGuards(futureNode, null, context ? context.children : null, futurePath, checks);
3234 // if we have a componentless route, we recurse but keep the same outlet map.
3235 }
3236 else {
3237 getChildRouteGuards(futureNode, null, parentContexts, futurePath, checks);
3238 }
3239 }
3240 return checks;
3241 }
3242 function shouldRunGuardsAndResolvers(curr, future, mode) {
3243 if (typeof mode === 'function') {
3244 return mode(curr, future);
3245 }
3246 switch (mode) {
3247 case 'pathParamsChange':
3248 return !equalPath(curr.url, future.url);
3249 case 'pathParamsOrQueryParamsChange':
3250 return !equalPath(curr.url, future.url) ||
3251 !shallowEqual(curr.queryParams, future.queryParams);
3252 case 'always':
3253 return true;
3254 case 'paramsOrQueryParamsChange':
3255 return !equalParamsAndUrlSegments(curr, future) ||
3256 !shallowEqual(curr.queryParams, future.queryParams);
3257 case 'paramsChange':
3258 default:
3259 return !equalParamsAndUrlSegments(curr, future);
3260 }
3261 }
3262 function deactivateRouteAndItsChildren(route, context, checks) {
3263 var children = nodeChildrenAsMap(route);
3264 var r = route.value;
3265 forEach(children, function (node, childName) {
3266 if (!r.component) {
3267 deactivateRouteAndItsChildren(node, context, checks);
3268 }
3269 else if (context) {
3270 deactivateRouteAndItsChildren(node, context.children.getContext(childName), checks);
3271 }
3272 else {
3273 deactivateRouteAndItsChildren(node, null, checks);
3274 }
3275 });
3276 if (!r.component) {
3277 checks.canDeactivateChecks.push(new CanDeactivate(null, r));
3278 }
3279 else if (context && context.outlet && context.outlet.isActivated) {
3280 checks.canDeactivateChecks.push(new CanDeactivate(context.outlet.component, r));
3281 }
3282 else {
3283 checks.canDeactivateChecks.push(new CanDeactivate(null, r));
3284 }
3285 }
3286
3287 /**
3288 * @license
3289 * Copyright Google LLC All Rights Reserved.
3290 *
3291 * Use of this source code is governed by an MIT-style license that can be
3292 * found in the LICENSE file at https://angular.io/license
3293 */
3294 var INITIAL_VALUE = Symbol('INITIAL_VALUE');
3295 function prioritizedGuardValue() {
3296 return operators.switchMap(function (obs) {
3297 return rxjs.combineLatest.apply(void 0, __spread(obs.map(function (o) { return o.pipe(operators.take(1), operators.startWith(INITIAL_VALUE)); }))).pipe(operators.scan(function (acc, list) {
3298 var isPending = false;
3299 return list.reduce(function (innerAcc, val, i) {
3300 if (innerAcc !== INITIAL_VALUE)
3301 return innerAcc;
3302 // Toggle pending flag if any values haven't been set yet
3303 if (val === INITIAL_VALUE)
3304 isPending = true;
3305 // Any other return values are only valid if we haven't yet hit a pending
3306 // call. This guarantees that in the case of a guard at the bottom of the
3307 // tree that returns a redirect, we will wait for the higher priority
3308 // guard at the top to finish before performing the redirect.
3309 if (!isPending) {
3310 // Early return when we hit a `false` value as that should always
3311 // cancel navigation
3312 if (val === false)
3313 return val;
3314 if (i === list.length - 1 || isUrlTree(val)) {
3315 return val;
3316 }
3317 }
3318 return innerAcc;
3319 }, acc);
3320 }, INITIAL_VALUE), operators.filter(function (item) { return item !== INITIAL_VALUE; }), operators.map(function (item) { return isUrlTree(item) ? item : item === true; }), //
3321 operators.take(1));
3322 });
3323 }
3324
3325 /**
3326 * @license
3327 * Copyright Google LLC All Rights Reserved.
3328 *
3329 * Use of this source code is governed by an MIT-style license that can be
3330 * found in the LICENSE file at https://angular.io/license
3331 */
3332 function checkGuards(moduleInjector, forwardEvent) {
3333 return function (source) {
3334 return source.pipe(operators.mergeMap(function (t) {
3335 var targetSnapshot = t.targetSnapshot, currentSnapshot = t.currentSnapshot, _a = t.guards, canActivateChecks = _a.canActivateChecks, canDeactivateChecks = _a.canDeactivateChecks;
3336 if (canDeactivateChecks.length === 0 && canActivateChecks.length === 0) {
3337 return rxjs.of(__assign(__assign({}, t), { guardsResult: true }));
3338 }
3339 return runCanDeactivateChecks(canDeactivateChecks, targetSnapshot, currentSnapshot, moduleInjector)
3340 .pipe(operators.mergeMap(function (canDeactivate) {
3341 return canDeactivate && isBoolean(canDeactivate) ?
3342 runCanActivateChecks(targetSnapshot, canActivateChecks, moduleInjector, forwardEvent) :
3343 rxjs.of(canDeactivate);
3344 }), operators.map(function (guardsResult) { return (__assign(__assign({}, t), { guardsResult: guardsResult })); }));
3345 }));
3346 };
3347 }
3348 function runCanDeactivateChecks(checks, futureRSS, currRSS, moduleInjector) {
3349 return rxjs.from(checks).pipe(operators.mergeMap(function (check) {
3350 return runCanDeactivate(check.component, check.route, currRSS, futureRSS, moduleInjector);
3351 }), operators.first(function (result) {
3352 return result !== true;
3353 }, true));
3354 }
3355 function runCanActivateChecks(futureSnapshot, checks, moduleInjector, forwardEvent) {
3356 return rxjs.from(checks).pipe(operators.concatMap(function (check) {
3357 return rxjs.from([
3358 fireChildActivationStart(check.route.parent, forwardEvent),
3359 fireActivationStart(check.route, forwardEvent),
3360 runCanActivateChild(futureSnapshot, check.path, moduleInjector),
3361 runCanActivate(futureSnapshot, check.route, moduleInjector)
3362 ])
3363 .pipe(operators.concatAll(), operators.first(function (result) {
3364 return result !== true;
3365 }, true));
3366 }), operators.first(function (result) {
3367 return result !== true;
3368 }, true));
3369 }
3370 /**
3371 * This should fire off `ActivationStart` events for each route being activated at this
3372 * level.
3373 * In other words, if you're activating `a` and `b` below, `path` will contain the
3374 * `ActivatedRouteSnapshot`s for both and we will fire `ActivationStart` for both. Always
3375 * return
3376 * `true` so checks continue to run.
3377 */
3378 function fireActivationStart(snapshot, forwardEvent) {
3379 if (snapshot !== null && forwardEvent) {
3380 forwardEvent(new ActivationStart(snapshot));
3381 }
3382 return rxjs.of(true);
3383 }
3384 /**
3385 * This should fire off `ChildActivationStart` events for each route being activated at this
3386 * level.
3387 * In other words, if you're activating `a` and `b` below, `path` will contain the
3388 * `ActivatedRouteSnapshot`s for both and we will fire `ChildActivationStart` for both. Always
3389 * return
3390 * `true` so checks continue to run.
3391 */
3392 function fireChildActivationStart(snapshot, forwardEvent) {
3393 if (snapshot !== null && forwardEvent) {
3394 forwardEvent(new ChildActivationStart(snapshot));
3395 }
3396 return rxjs.of(true);
3397 }
3398 function runCanActivate(futureRSS, futureARS, moduleInjector) {
3399 var canActivate = futureARS.routeConfig ? futureARS.routeConfig.canActivate : null;
3400 if (!canActivate || canActivate.length === 0)
3401 return rxjs.of(true);
3402 var canActivateObservables = canActivate.map(function (c) {
3403 return rxjs.defer(function () {
3404 var guard = getToken(c, futureARS, moduleInjector);
3405 var observable;
3406 if (isCanActivate(guard)) {
3407 observable = wrapIntoObservable(guard.canActivate(futureARS, futureRSS));
3408 }
3409 else if (isFunction(guard)) {
3410 observable = wrapIntoObservable(guard(futureARS, futureRSS));
3411 }
3412 else {
3413 throw new Error('Invalid CanActivate guard');
3414 }
3415 return observable.pipe(operators.first());
3416 });
3417 });
3418 return rxjs.of(canActivateObservables).pipe(prioritizedGuardValue());
3419 }
3420 function runCanActivateChild(futureRSS, path, moduleInjector) {
3421 var futureARS = path[path.length - 1];
3422 var canActivateChildGuards = path.slice(0, path.length - 1)
3423 .reverse()
3424 .map(function (p) { return getCanActivateChild(p); })
3425 .filter(function (_) { return _ !== null; });
3426 var canActivateChildGuardsMapped = canActivateChildGuards.map(function (d) {
3427 return rxjs.defer(function () {
3428 var guardsMapped = d.guards.map(function (c) {
3429 var guard = getToken(c, d.node, moduleInjector);
3430 var observable;
3431 if (isCanActivateChild(guard)) {
3432 observable = wrapIntoObservable(guard.canActivateChild(futureARS, futureRSS));
3433 }
3434 else if (isFunction(guard)) {
3435 observable = wrapIntoObservable(guard(futureARS, futureRSS));
3436 }
3437 else {
3438 throw new Error('Invalid CanActivateChild guard');
3439 }
3440 return observable.pipe(operators.first());
3441 });
3442 return rxjs.of(guardsMapped).pipe(prioritizedGuardValue());
3443 });
3444 });
3445 return rxjs.of(canActivateChildGuardsMapped).pipe(prioritizedGuardValue());
3446 }
3447 function runCanDeactivate(component, currARS, currRSS, futureRSS, moduleInjector) {
3448 var canDeactivate = currARS && currARS.routeConfig ? currARS.routeConfig.canDeactivate : null;
3449 if (!canDeactivate || canDeactivate.length === 0)
3450 return rxjs.of(true);
3451 var canDeactivateObservables = canDeactivate.map(function (c) {
3452 var guard = getToken(c, currARS, moduleInjector);
3453 var observable;
3454 if (isCanDeactivate(guard)) {
3455 observable = wrapIntoObservable(guard.canDeactivate(component, currARS, currRSS, futureRSS));
3456 }
3457 else if (isFunction(guard)) {
3458 observable = wrapIntoObservable(guard(component, currARS, currRSS, futureRSS));
3459 }
3460 else {
3461 throw new Error('Invalid CanDeactivate guard');
3462 }
3463 return observable.pipe(operators.first());
3464 });
3465 return rxjs.of(canDeactivateObservables).pipe(prioritizedGuardValue());
3466 }
3467
3468 /**
3469 * @license
3470 * Copyright Google LLC All Rights Reserved.
3471 *
3472 * Use of this source code is governed by an MIT-style license that can be
3473 * found in the LICENSE file at https://angular.io/license
3474 */
3475 var NoMatch$1 = /** @class */ (function () {
3476 function NoMatch() {
3477 }
3478 return NoMatch;
3479 }());
3480 function recognize(rootComponentType, config, urlTree, url, paramsInheritanceStrategy, relativeLinkResolution) {
3481 if (paramsInheritanceStrategy === void 0) { paramsInheritanceStrategy = 'emptyOnly'; }
3482 if (relativeLinkResolution === void 0) { relativeLinkResolution = 'legacy'; }
3483 return new Recognizer(rootComponentType, config, urlTree, url, paramsInheritanceStrategy, relativeLinkResolution)
3484 .recognize();
3485 }
3486 var Recognizer = /** @class */ (function () {
3487 function Recognizer(rootComponentType, config, urlTree, url, paramsInheritanceStrategy, relativeLinkResolution) {
3488 this.rootComponentType = rootComponentType;
3489 this.config = config;
3490 this.urlTree = urlTree;
3491 this.url = url;
3492 this.paramsInheritanceStrategy = paramsInheritanceStrategy;
3493 this.relativeLinkResolution = relativeLinkResolution;
3494 }
3495 Recognizer.prototype.recognize = function () {
3496 try {
3497 var rootSegmentGroup = split$1(this.urlTree.root, [], [], this.config, this.relativeLinkResolution).segmentGroup;
3498 var children = this.processSegmentGroup(this.config, rootSegmentGroup, PRIMARY_OUTLET);
3499 var root = new ActivatedRouteSnapshot([], Object.freeze({}), Object.freeze(__assign({}, this.urlTree.queryParams)), this.urlTree.fragment, {}, PRIMARY_OUTLET, this.rootComponentType, null, this.urlTree.root, -1, {});
3500 var rootNode = new TreeNode(root, children);
3501 var routeState = new RouterStateSnapshot(this.url, rootNode);
3502 this.inheritParamsAndData(routeState._root);
3503 return rxjs.of(routeState);
3504 }
3505 catch (e) {
3506 return new rxjs.Observable(function (obs) { return obs.error(e); });
3507 }
3508 };
3509 Recognizer.prototype.inheritParamsAndData = function (routeNode) {
3510 var _this = this;
3511 var route = routeNode.value;
3512 var i = inheritedParamsDataResolve(route, this.paramsInheritanceStrategy);
3513 route.params = Object.freeze(i.params);
3514 route.data = Object.freeze(i.data);
3515 routeNode.children.forEach(function (n) { return _this.inheritParamsAndData(n); });
3516 };
3517 Recognizer.prototype.processSegmentGroup = function (config, segmentGroup, outlet) {
3518 if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
3519 return this.processChildren(config, segmentGroup);
3520 }
3521 return this.processSegment(config, segmentGroup, segmentGroup.segments, outlet);
3522 };
3523 Recognizer.prototype.processChildren = function (config, segmentGroup) {
3524 var _this = this;
3525 var children = mapChildrenIntoArray(segmentGroup, function (child, childOutlet) { return _this.processSegmentGroup(config, child, childOutlet); });
3526 checkOutletNameUniqueness(children);
3527 sortActivatedRouteSnapshots(children);
3528 return children;
3529 };
3530 Recognizer.prototype.processSegment = function (config, segmentGroup, segments, outlet) {
3531 var e_1, _a;
3532 try {
3533 for (var config_1 = __values(config), config_1_1 = config_1.next(); !config_1_1.done; config_1_1 = config_1.next()) {
3534 var r = config_1_1.value;
3535 try {
3536 return this.processSegmentAgainstRoute(r, segmentGroup, segments, outlet);
3537 }
3538 catch (e) {
3539 if (!(e instanceof NoMatch$1))
3540 throw e;
3541 }
3542 }
3543 }
3544 catch (e_1_1) { e_1 = { error: e_1_1 }; }
3545 finally {
3546 try {
3547 if (config_1_1 && !config_1_1.done && (_a = config_1.return)) _a.call(config_1);
3548 }
3549 finally { if (e_1) throw e_1.error; }
3550 }
3551 if (this.noLeftoversInUrl(segmentGroup, segments, outlet)) {
3552 return [];
3553 }
3554 throw new NoMatch$1();
3555 };
3556 Recognizer.prototype.noLeftoversInUrl = function (segmentGroup, segments, outlet) {
3557 return segments.length === 0 && !segmentGroup.children[outlet];
3558 };
3559 Recognizer.prototype.processSegmentAgainstRoute = function (route, rawSegment, segments, outlet) {
3560 if (route.redirectTo)
3561 throw new NoMatch$1();
3562 if ((route.outlet || PRIMARY_OUTLET) !== outlet)
3563 throw new NoMatch$1();
3564 var snapshot;
3565 var consumedSegments = [];
3566 var rawSlicedSegments = [];
3567 if (route.path === '**') {
3568 var params = segments.length > 0 ? last(segments).parameters : {};
3569 snapshot = new ActivatedRouteSnapshot(segments, params, Object.freeze(__assign({}, this.urlTree.queryParams)), this.urlTree.fragment, getData(route), outlet, route.component, route, getSourceSegmentGroup(rawSegment), getPathIndexShift(rawSegment) + segments.length, getResolve(route));
3570 }
3571 else {
3572 var result = match$1(rawSegment, route, segments);
3573 consumedSegments = result.consumedSegments;
3574 rawSlicedSegments = segments.slice(result.lastChild);
3575 snapshot = new ActivatedRouteSnapshot(consumedSegments, result.parameters, Object.freeze(__assign({}, this.urlTree.queryParams)), this.urlTree.fragment, getData(route), outlet, route.component, route, getSourceSegmentGroup(rawSegment), getPathIndexShift(rawSegment) + consumedSegments.length, getResolve(route));
3576 }
3577 var childConfig = getChildConfig(route);
3578 var _a = split$1(rawSegment, consumedSegments, rawSlicedSegments, childConfig, this.relativeLinkResolution), segmentGroup = _a.segmentGroup, slicedSegments = _a.slicedSegments;
3579 if (slicedSegments.length === 0 && segmentGroup.hasChildren()) {
3580 var children_1 = this.processChildren(childConfig, segmentGroup);
3581 return [new TreeNode(snapshot, children_1)];
3582 }
3583 if (childConfig.length === 0 && slicedSegments.length === 0) {
3584 return [new TreeNode(snapshot, [])];
3585 }
3586 var children = this.processSegment(childConfig, segmentGroup, slicedSegments, PRIMARY_OUTLET);
3587 return [new TreeNode(snapshot, children)];
3588 };
3589 return Recognizer;
3590 }());
3591 function sortActivatedRouteSnapshots(nodes) {
3592 nodes.sort(function (a, b) {
3593 if (a.value.outlet === PRIMARY_OUTLET)
3594 return -1;
3595 if (b.value.outlet === PRIMARY_OUTLET)
3596 return 1;
3597 return a.value.outlet.localeCompare(b.value.outlet);
3598 });
3599 }
3600 function getChildConfig(route) {
3601 if (route.children) {
3602 return route.children;
3603 }
3604 if (route.loadChildren) {
3605 return route._loadedConfig.routes;
3606 }
3607 return [];
3608 }
3609 function match$1(segmentGroup, route, segments) {
3610 if (route.path === '') {
3611 if (route.pathMatch === 'full' && (segmentGroup.hasChildren() || segments.length > 0)) {
3612 throw new NoMatch$1();
3613 }
3614 return { consumedSegments: [], lastChild: 0, parameters: {} };
3615 }
3616 var matcher = route.matcher || defaultUrlMatcher;
3617 var res = matcher(segments, segmentGroup, route);
3618 if (!res)
3619 throw new NoMatch$1();
3620 var posParams = {};
3621 forEach(res.posParams, function (v, k) {
3622 posParams[k] = v.path;
3623 });
3624 var parameters = res.consumed.length > 0 ? __assign(__assign({}, posParams), res.consumed[res.consumed.length - 1].parameters) :
3625 posParams;
3626 return { consumedSegments: res.consumed, lastChild: res.consumed.length, parameters: parameters };
3627 }
3628 function checkOutletNameUniqueness(nodes) {
3629 var names = {};
3630 nodes.forEach(function (n) {
3631 var routeWithSameOutletName = names[n.value.outlet];
3632 if (routeWithSameOutletName) {
3633 var p = routeWithSameOutletName.url.map(function (s) { return s.toString(); }).join('/');
3634 var c = n.value.url.map(function (s) { return s.toString(); }).join('/');
3635 throw new Error("Two segments cannot have the same outlet name: '" + p + "' and '" + c + "'.");
3636 }
3637 names[n.value.outlet] = n.value;
3638 });
3639 }
3640 function getSourceSegmentGroup(segmentGroup) {
3641 var s = segmentGroup;
3642 while (s._sourceSegment) {
3643 s = s._sourceSegment;
3644 }
3645 return s;
3646 }
3647 function getPathIndexShift(segmentGroup) {
3648 var s = segmentGroup;
3649 var res = (s._segmentIndexShift ? s._segmentIndexShift : 0);
3650 while (s._sourceSegment) {
3651 s = s._sourceSegment;
3652 res += (s._segmentIndexShift ? s._segmentIndexShift : 0);
3653 }
3654 return res - 1;
3655 }
3656 function split$1(segmentGroup, consumedSegments, slicedSegments, config, relativeLinkResolution) {
3657 if (slicedSegments.length > 0 &&
3658 containsEmptyPathMatchesWithNamedOutlets(segmentGroup, slicedSegments, config)) {
3659 var s_1 = new UrlSegmentGroup(consumedSegments, createChildrenForEmptyPaths(segmentGroup, consumedSegments, config, new UrlSegmentGroup(slicedSegments, segmentGroup.children)));
3660 s_1._sourceSegment = segmentGroup;
3661 s_1._segmentIndexShift = consumedSegments.length;
3662 return { segmentGroup: s_1, slicedSegments: [] };
3663 }
3664 if (slicedSegments.length === 0 &&
3665 containsEmptyPathMatches(segmentGroup, slicedSegments, config)) {
3666 var s_2 = new UrlSegmentGroup(segmentGroup.segments, addEmptyPathsToChildrenIfNeeded(segmentGroup, consumedSegments, slicedSegments, config, segmentGroup.children, relativeLinkResolution));
3667 s_2._sourceSegment = segmentGroup;
3668 s_2._segmentIndexShift = consumedSegments.length;
3669 return { segmentGroup: s_2, slicedSegments: slicedSegments };
3670 }
3671 var s = new UrlSegmentGroup(segmentGroup.segments, segmentGroup.children);
3672 s._sourceSegment = segmentGroup;
3673 s._segmentIndexShift = consumedSegments.length;
3674 return { segmentGroup: s, slicedSegments: slicedSegments };
3675 }
3676 function addEmptyPathsToChildrenIfNeeded(segmentGroup, consumedSegments, slicedSegments, routes, children, relativeLinkResolution) {
3677 var e_2, _a;
3678 var res = {};
3679 try {
3680 for (var routes_1 = __values(routes), routes_1_1 = routes_1.next(); !routes_1_1.done; routes_1_1 = routes_1.next()) {
3681 var r = routes_1_1.value;
3682 if (emptyPathMatch(segmentGroup, slicedSegments, r) && !children[getOutlet$1(r)]) {
3683 var s = new UrlSegmentGroup([], {});
3684 s._sourceSegment = segmentGroup;
3685 if (relativeLinkResolution === 'legacy') {
3686 s._segmentIndexShift = segmentGroup.segments.length;
3687 }
3688 else {
3689 s._segmentIndexShift = consumedSegments.length;
3690 }
3691 res[getOutlet$1(r)] = s;
3692 }
3693 }
3694 }
3695 catch (e_2_1) { e_2 = { error: e_2_1 }; }
3696 finally {
3697 try {
3698 if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
3699 }
3700 finally { if (e_2) throw e_2.error; }
3701 }
3702 return __assign(__assign({}, children), res);
3703 }
3704 function createChildrenForEmptyPaths(segmentGroup, consumedSegments, routes, primarySegment) {
3705 var e_3, _a;
3706 var res = {};
3707 res[PRIMARY_OUTLET] = primarySegment;
3708 primarySegment._sourceSegment = segmentGroup;
3709 primarySegment._segmentIndexShift = consumedSegments.length;
3710 try {
3711 for (var routes_2 = __values(routes), routes_2_1 = routes_2.next(); !routes_2_1.done; routes_2_1 = routes_2.next()) {
3712 var r = routes_2_1.value;
3713 if (r.path === '' && getOutlet$1(r) !== PRIMARY_OUTLET) {
3714 var s = new UrlSegmentGroup([], {});
3715 s._sourceSegment = segmentGroup;
3716 s._segmentIndexShift = consumedSegments.length;
3717 res[getOutlet$1(r)] = s;
3718 }
3719 }
3720 }
3721 catch (e_3_1) { e_3 = { error: e_3_1 }; }
3722 finally {
3723 try {
3724 if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
3725 }
3726 finally { if (e_3) throw e_3.error; }
3727 }
3728 return res;
3729 }
3730 function containsEmptyPathMatchesWithNamedOutlets(segmentGroup, slicedSegments, routes) {
3731 return routes.some(function (r) { return emptyPathMatch(segmentGroup, slicedSegments, r) && getOutlet$1(r) !== PRIMARY_OUTLET; });
3732 }
3733 function containsEmptyPathMatches(segmentGroup, slicedSegments, routes) {
3734 return routes.some(function (r) { return emptyPathMatch(segmentGroup, slicedSegments, r); });
3735 }
3736 function emptyPathMatch(segmentGroup, slicedSegments, r) {
3737 if ((segmentGroup.hasChildren() || slicedSegments.length > 0) && r.pathMatch === 'full') {
3738 return false;
3739 }
3740 return r.path === '' && r.redirectTo === undefined;
3741 }
3742 function getOutlet$1(route) {
3743 return route.outlet || PRIMARY_OUTLET;
3744 }
3745 function getData(route) {
3746 return route.data || {};
3747 }
3748 function getResolve(route) {
3749 return route.resolve || {};
3750 }
3751
3752 /**
3753 * @license
3754 * Copyright Google LLC All Rights Reserved.
3755 *
3756 * Use of this source code is governed by an MIT-style license that can be
3757 * found in the LICENSE file at https://angular.io/license
3758 */
3759 function recognize$1(rootComponentType, config, serializer, paramsInheritanceStrategy, relativeLinkResolution) {
3760 return function (source) {
3761 return source.pipe(operators.mergeMap(function (t) { return recognize(rootComponentType, config, t.urlAfterRedirects, serializer(t.urlAfterRedirects), paramsInheritanceStrategy, relativeLinkResolution)
3762 .pipe(operators.map(function (targetSnapshot) { return (__assign(__assign({}, t), { targetSnapshot: targetSnapshot })); })); }));
3763 };
3764 }
3765
3766 /**
3767 * @license
3768 * Copyright Google LLC All Rights Reserved.
3769 *
3770 * Use of this source code is governed by an MIT-style license that can be
3771 * found in the LICENSE file at https://angular.io/license
3772 */
3773 function resolveData(paramsInheritanceStrategy, moduleInjector) {
3774 return function (source) {
3775 return source.pipe(operators.mergeMap(function (t) {
3776 var targetSnapshot = t.targetSnapshot, canActivateChecks = t.guards.canActivateChecks;
3777 if (!canActivateChecks.length) {
3778 return rxjs.of(t);
3779 }
3780 var canActivateChecksResolved = 0;
3781 return rxjs.from(canActivateChecks)
3782 .pipe(operators.concatMap(function (check) { return runResolve(check.route, targetSnapshot, paramsInheritanceStrategy, moduleInjector); }), operators.tap(function () { return canActivateChecksResolved++; }), operators.takeLast(1), operators.mergeMap(function (_) { return canActivateChecksResolved === canActivateChecks.length ? rxjs.of(t) : rxjs.EMPTY; }));
3783 }));
3784 };
3785 }
3786 function runResolve(futureARS, futureRSS, paramsInheritanceStrategy, moduleInjector) {
3787 var resolve = futureARS._resolve;
3788 return resolveNode(resolve, futureARS, futureRSS, moduleInjector)
3789 .pipe(operators.map(function (resolvedData) {
3790 futureARS._resolvedData = resolvedData;
3791 futureARS.data = __assign(__assign({}, futureARS.data), inheritedParamsDataResolve(futureARS, paramsInheritanceStrategy).resolve);
3792 return null;
3793 }));
3794 }
3795 function resolveNode(resolve, futureARS, futureRSS, moduleInjector) {
3796 var keys = Object.keys(resolve);
3797 if (keys.length === 0) {
3798 return rxjs.of({});
3799 }
3800 var data = {};
3801 return rxjs.from(keys).pipe(operators.mergeMap(function (key) { return getResolver(resolve[key], futureARS, futureRSS, moduleInjector)
3802 .pipe(operators.tap(function (value) {
3803 data[key] = value;
3804 })); }), operators.takeLast(1), operators.mergeMap(function () {
3805 // Ensure all resolvers returned values, otherwise don't emit any "next" and just complete
3806 // the chain which will cancel navigation
3807 if (Object.keys(data).length === keys.length) {
3808 return rxjs.of(data);
3809 }
3810 return rxjs.EMPTY;
3811 }));
3812 }
3813 function getResolver(injectionToken, futureARS, futureRSS, moduleInjector) {
3814 var resolver = getToken(injectionToken, futureARS, moduleInjector);
3815 return resolver.resolve ? wrapIntoObservable(resolver.resolve(futureARS, futureRSS)) :
3816 wrapIntoObservable(resolver(futureARS, futureRSS));
3817 }
3818
3819 /**
3820 * @license
3821 * Copyright Google LLC All Rights Reserved.
3822 *
3823 * Use of this source code is governed by an MIT-style license that can be
3824 * found in the LICENSE file at https://angular.io/license
3825 */
3826 /**
3827 * Perform a side effect through a switchMap for every emission on the source Observable,
3828 * but return an Observable that is identical to the source. It's essentially the same as
3829 * the `tap` operator, but if the side effectful `next` function returns an ObservableInput,
3830 * it will wait before continuing with the original value.
3831 */
3832 function switchTap(next) {
3833 return function (source) {
3834 return source.pipe(operators.switchMap(function (v) {
3835 var nextResult = next(v);
3836 if (nextResult) {
3837 return rxjs.from(nextResult).pipe(operators.map(function () { return v; }));
3838 }
3839 return rxjs.from([v]);
3840 }));
3841 };
3842 }
3843
3844 /**
3845 * @license
3846 * Copyright Google LLC All Rights Reserved.
3847 *
3848 * Use of this source code is governed by an MIT-style license that can be
3849 * found in the LICENSE file at https://angular.io/license
3850 */
3851 /**
3852 * @description
3853 *
3854 * Provides a way to customize when activated routes get reused.
3855 *
3856 * @publicApi
3857 */
3858 var RouteReuseStrategy = /** @class */ (function () {
3859 function RouteReuseStrategy() {
3860 }
3861 return RouteReuseStrategy;
3862 }());
3863 /**
3864 * Does not detach any subtrees. Reuses routes as long as their route config is the same.
3865 */
3866 var DefaultRouteReuseStrategy = /** @class */ (function () {
3867 function DefaultRouteReuseStrategy() {
3868 }
3869 DefaultRouteReuseStrategy.prototype.shouldDetach = function (route) {
3870 return false;
3871 };
3872 DefaultRouteReuseStrategy.prototype.store = function (route, detachedTree) { };
3873 DefaultRouteReuseStrategy.prototype.shouldAttach = function (route) {
3874 return false;
3875 };
3876 DefaultRouteReuseStrategy.prototype.retrieve = function (route) {
3877 return null;
3878 };
3879 DefaultRouteReuseStrategy.prototype.shouldReuseRoute = function (future, curr) {
3880 return future.routeConfig === curr.routeConfig;
3881 };
3882 return DefaultRouteReuseStrategy;
3883 }());
3884
3885 /**
3886 * @license
3887 * Copyright Google LLC All Rights Reserved.
3888 *
3889 * Use of this source code is governed by an MIT-style license that can be
3890 * found in the LICENSE file at https://angular.io/license
3891 */
3892 /**
3893 * The [DI token](guide/glossary/#di-token) for a router configuration.
3894 * @see `ROUTES`
3895 * @publicApi
3896 */
3897 var ROUTES = new core.InjectionToken('ROUTES');
3898 var RouterConfigLoader = /** @class */ (function () {
3899 function RouterConfigLoader(loader, compiler, onLoadStartListener, onLoadEndListener) {
3900 this.loader = loader;
3901 this.compiler = compiler;
3902 this.onLoadStartListener = onLoadStartListener;
3903 this.onLoadEndListener = onLoadEndListener;
3904 }
3905 RouterConfigLoader.prototype.load = function (parentInjector, route) {
3906 var _this = this;
3907 if (this.onLoadStartListener) {
3908 this.onLoadStartListener(route);
3909 }
3910 var moduleFactory$ = this.loadModuleFactory(route.loadChildren);
3911 return moduleFactory$.pipe(operators.map(function (factory) {
3912 if (_this.onLoadEndListener) {
3913 _this.onLoadEndListener(route);
3914 }
3915 var module = factory.create(parentInjector);
3916 return new LoadedRouterConfig(flatten(module.injector.get(ROUTES)).map(standardizeConfig), module);
3917 }));
3918 };
3919 RouterConfigLoader.prototype.loadModuleFactory = function (loadChildren) {
3920 var _this = this;
3921 if (typeof loadChildren === 'string') {
3922 return rxjs.from(this.loader.load(loadChildren));
3923 }
3924 else {
3925 return wrapIntoObservable(loadChildren()).pipe(operators.mergeMap(function (t) {
3926 if (t instanceof core.NgModuleFactory) {
3927 return rxjs.of(t);
3928 }
3929 else {
3930 return rxjs.from(_this.compiler.compileModuleAsync(t));
3931 }
3932 }));
3933 }
3934 };
3935 return RouterConfigLoader;
3936 }());
3937
3938 /**
3939 * @license
3940 * Copyright Google LLC All Rights Reserved.
3941 *
3942 * Use of this source code is governed by an MIT-style license that can be
3943 * found in the LICENSE file at https://angular.io/license
3944 */
3945 /**
3946 * Store contextual information about a `RouterOutlet`
3947 *
3948 * @publicApi
3949 */
3950 var OutletContext = /** @class */ (function () {
3951 function OutletContext() {
3952 this.outlet = null;
3953 this.route = null;
3954 this.resolver = null;
3955 this.children = new ChildrenOutletContexts();
3956 this.attachRef = null;
3957 }
3958 return OutletContext;
3959 }());
3960 /**
3961 * Store contextual information about the children (= nested) `RouterOutlet`
3962 *
3963 * @publicApi
3964 */
3965 var ChildrenOutletContexts = /** @class */ (function () {
3966 function ChildrenOutletContexts() {
3967 // contexts for child outlets, by name.
3968 this.contexts = new Map();
3969 }
3970 /** Called when a `RouterOutlet` directive is instantiated */
3971 ChildrenOutletContexts.prototype.onChildOutletCreated = function (childName, outlet) {
3972 var context = this.getOrCreateContext(childName);
3973 context.outlet = outlet;
3974 this.contexts.set(childName, context);
3975 };
3976 /**
3977 * Called when a `RouterOutlet` directive is destroyed.
3978 * We need to keep the context as the outlet could be destroyed inside a NgIf and might be
3979 * re-created later.
3980 */
3981 ChildrenOutletContexts.prototype.onChildOutletDestroyed = function (childName) {
3982 var context = this.getContext(childName);
3983 if (context) {
3984 context.outlet = null;
3985 }
3986 };
3987 /**
3988 * Called when the corresponding route is deactivated during navigation.
3989 * Because the component get destroyed, all children outlet are destroyed.
3990 */
3991 ChildrenOutletContexts.prototype.onOutletDeactivated = function () {
3992 var contexts = this.contexts;
3993 this.contexts = new Map();
3994 return contexts;
3995 };
3996 ChildrenOutletContexts.prototype.onOutletReAttached = function (contexts) {
3997 this.contexts = contexts;
3998 };
3999 ChildrenOutletContexts.prototype.getOrCreateContext = function (childName) {
4000 var context = this.getContext(childName);
4001 if (!context) {
4002 context = new OutletContext();
4003 this.contexts.set(childName, context);
4004 }
4005 return context;
4006 };
4007 ChildrenOutletContexts.prototype.getContext = function (childName) {
4008 return this.contexts.get(childName) || null;
4009 };
4010 return ChildrenOutletContexts;
4011 }());
4012
4013 /**
4014 * @license
4015 * Copyright Google LLC All Rights Reserved.
4016 *
4017 * Use of this source code is governed by an MIT-style license that can be
4018 * found in the LICENSE file at https://angular.io/license
4019 */
4020 /**
4021 * @description
4022 *
4023 * Provides a way to migrate AngularJS applications to Angular.
4024 *
4025 * @publicApi
4026 */
4027 var UrlHandlingStrategy = /** @class */ (function () {
4028 function UrlHandlingStrategy() {
4029 }
4030 return UrlHandlingStrategy;
4031 }());
4032 /**
4033 * @publicApi
4034 */
4035 var DefaultUrlHandlingStrategy = /** @class */ (function () {
4036 function DefaultUrlHandlingStrategy() {
4037 }
4038 DefaultUrlHandlingStrategy.prototype.shouldProcessUrl = function (url) {
4039 return true;
4040 };
4041 DefaultUrlHandlingStrategy.prototype.extract = function (url) {
4042 return url;
4043 };
4044 DefaultUrlHandlingStrategy.prototype.merge = function (newUrlPart, wholeUrl) {
4045 return newUrlPart;
4046 };
4047 return DefaultUrlHandlingStrategy;
4048 }());
4049
4050 /**
4051 * @license
4052 * Copyright Google LLC All Rights Reserved.
4053 *
4054 * Use of this source code is governed by an MIT-style license that can be
4055 * found in the LICENSE file at https://angular.io/license
4056 */
4057 function defaultErrorHandler(error) {
4058 throw error;
4059 }
4060 function defaultMalformedUriErrorHandler(error, urlSerializer, url) {
4061 return urlSerializer.parse('/');
4062 }
4063 /**
4064 * @internal
4065 */
4066 function defaultRouterHook(snapshot, runExtras) {
4067 return rxjs.of(null);
4068 }
4069 /**
4070 * @description
4071 *
4072 * A service that provides navigation and URL manipulation capabilities.
4073 *
4074 * @see `Route`.
4075 * @see [Routing and Navigation Guide](guide/router).
4076 *
4077 * @ngModule RouterModule
4078 *
4079 * @publicApi
4080 */
4081 var Router = /** @class */ (function () {
4082 /**
4083 * Creates the router service.
4084 */
4085 // TODO: vsavkin make internal after the final is out.
4086 function Router(rootComponentType, urlSerializer, rootContexts, location, injector, loader, compiler, config) {
4087 var _this = this;
4088 this.rootComponentType = rootComponentType;
4089 this.urlSerializer = urlSerializer;
4090 this.rootContexts = rootContexts;
4091 this.location = location;
4092 this.config = config;
4093 this.lastSuccessfulNavigation = null;
4094 this.currentNavigation = null;
4095 this.navigationId = 0;
4096 this.isNgZoneEnabled = false;
4097 /**
4098 * An event stream for routing events in this NgModule.
4099 */
4100 this.events = new rxjs.Subject();
4101 /**
4102 * A handler for navigation errors in this NgModule.
4103 */
4104 this.errorHandler = defaultErrorHandler;
4105 /**
4106 * A handler for errors thrown by `Router.parseUrl(url)`
4107 * when `url` contains an invalid character.
4108 * The most common case is a `%` sign
4109 * that's not encoded and is not part of a percent encoded sequence.
4110 */
4111 this.malformedUriErrorHandler = defaultMalformedUriErrorHandler;
4112 /**
4113 * True if at least one navigation event has occurred,
4114 * false otherwise.
4115 */
4116 this.navigated = false;
4117 this.lastSuccessfulId = -1;
4118 /**
4119 * Hooks that enable you to pause navigation,
4120 * either before or after the preactivation phase.
4121 * Used by `RouterModule`.
4122 *
4123 * @internal
4124 */
4125 this.hooks = { beforePreactivation: defaultRouterHook, afterPreactivation: defaultRouterHook };
4126 /**
4127 * A strategy for extracting and merging URLs.
4128 * Used for AngularJS to Angular migrations.
4129 */
4130 this.urlHandlingStrategy = new DefaultUrlHandlingStrategy();
4131 /**
4132 * A strategy for re-using routes.
4133 */
4134 this.routeReuseStrategy = new DefaultRouteReuseStrategy();
4135 /**
4136 * How to handle a navigation request to the current URL. One of:
4137 * - `'ignore'` : The router ignores the request.
4138 * - `'reload'` : The router reloads the URL. Use to implement a "refresh" feature.
4139 */
4140 this.onSameUrlNavigation = 'ignore';
4141 /**
4142 * How to merge parameters, data, and resolved data from parent to child
4143 * routes. One of:
4144 *
4145 * - `'emptyOnly'` : Inherit parent parameters, data, and resolved data
4146 * for path-less or component-less routes.
4147 * - `'always'` : Inherit parent parameters, data, and resolved data
4148 * for all child routes.
4149 */
4150 this.paramsInheritanceStrategy = 'emptyOnly';
4151 /**
4152 * Determines when the router updates the browser URL.
4153 * By default (`"deferred"`), updates the browser URL after navigation has finished.
4154 * Set to `'eager'` to update the browser URL at the beginning of navigation.
4155 * You can choose to update early so that, if navigation fails,
4156 * you can show an error message with the URL that failed.
4157 */
4158 this.urlUpdateStrategy = 'deferred';
4159 /**
4160 * Enables a bug fix that corrects relative link resolution in components with empty paths.
4161 * @see `RouterModule`
4162 */
4163 this.relativeLinkResolution = 'legacy';
4164 var onLoadStart = function (r) { return _this.triggerEvent(new RouteConfigLoadStart(r)); };
4165 var onLoadEnd = function (r) { return _this.triggerEvent(new RouteConfigLoadEnd(r)); };
4166 this.ngModule = injector.get(core.NgModuleRef);
4167 this.console = injector.get(core.ɵConsole);
4168 var ngZone = injector.get(core.NgZone);
4169 this.isNgZoneEnabled = ngZone instanceof core.NgZone;
4170 this.resetConfig(config);
4171 this.currentUrlTree = createEmptyUrlTree();
4172 this.rawUrlTree = this.currentUrlTree;
4173 this.browserUrlTree = this.currentUrlTree;
4174 this.configLoader = new RouterConfigLoader(loader, compiler, onLoadStart, onLoadEnd);
4175 this.routerState = createEmptyState(this.currentUrlTree, this.rootComponentType);
4176 this.transitions = new rxjs.BehaviorSubject({
4177 id: 0,
4178 currentUrlTree: this.currentUrlTree,
4179 currentRawUrl: this.currentUrlTree,
4180 extractedUrl: this.urlHandlingStrategy.extract(this.currentUrlTree),
4181 urlAfterRedirects: this.urlHandlingStrategy.extract(this.currentUrlTree),
4182 rawUrl: this.currentUrlTree,
4183 extras: {},
4184 resolve: null,
4185 reject: null,
4186 promise: Promise.resolve(true),
4187 source: 'imperative',
4188 restoredState: null,
4189 currentSnapshot: this.routerState.snapshot,
4190 targetSnapshot: null,
4191 currentRouterState: this.routerState,
4192 targetRouterState: null,
4193 guards: { canActivateChecks: [], canDeactivateChecks: [] },
4194 guardsResult: null,
4195 });
4196 this.navigations = this.setupNavigations(this.transitions);
4197 this.processNavigations();
4198 }
4199 Router.prototype.setupNavigations = function (transitions) {
4200 var _this = this;
4201 var eventsSubject = this.events;
4202 return transitions.pipe(operators.filter(function (t) { return t.id !== 0; }),
4203 // Extract URL
4204 operators.map(function (t) {
4205 return (__assign(__assign({}, t), { extractedUrl: _this.urlHandlingStrategy.extract(t.rawUrl) }));
4206 }),
4207 // Using switchMap so we cancel executing navigations when a new one comes in
4208 operators.switchMap(function (t) {
4209 var completed = false;
4210 var errored = false;
4211 return rxjs.of(t).pipe(
4212 // Store the Navigation object
4213 operators.tap(function (t) {
4214 _this.currentNavigation = {
4215 id: t.id,
4216 initialUrl: t.currentRawUrl,
4217 extractedUrl: t.extractedUrl,
4218 trigger: t.source,
4219 extras: t.extras,
4220 previousNavigation: _this.lastSuccessfulNavigation ? __assign(__assign({}, _this.lastSuccessfulNavigation), { previousNavigation: null }) :
4221 null
4222 };
4223 }), operators.switchMap(function (t) {
4224 var urlTransition = !_this.navigated ||
4225 t.extractedUrl.toString() !== _this.browserUrlTree.toString();
4226 var processCurrentUrl = (_this.onSameUrlNavigation === 'reload' ? true : urlTransition) &&
4227 _this.urlHandlingStrategy.shouldProcessUrl(t.rawUrl);
4228 if (processCurrentUrl) {
4229 return rxjs.of(t).pipe(
4230 // Fire NavigationStart event
4231 operators.switchMap(function (t) {
4232 var transition = _this.transitions.getValue();
4233 eventsSubject.next(new NavigationStart(t.id, _this.serializeUrl(t.extractedUrl), t.source, t.restoredState));
4234 if (transition !== _this.transitions.getValue()) {
4235 return rxjs.EMPTY;
4236 }
4237 return [t];
4238 }),
4239 // This delay is required to match old behavior that forced navigation
4240 // to always be async
4241 operators.switchMap(function (t) { return Promise.resolve(t); }),
4242 // ApplyRedirects
4243 applyRedirects$1(_this.ngModule.injector, _this.configLoader, _this.urlSerializer, _this.config),
4244 // Update the currentNavigation
4245 operators.tap(function (t) {
4246 _this.currentNavigation = __assign(__assign({}, _this.currentNavigation), { finalUrl: t.urlAfterRedirects });
4247 }),
4248 // Recognize
4249 recognize$1(_this.rootComponentType, _this.config, function (url) { return _this.serializeUrl(url); }, _this.paramsInheritanceStrategy, _this.relativeLinkResolution),
4250 // Update URL if in `eager` update mode
4251 operators.tap(function (t) {
4252 if (_this.urlUpdateStrategy === 'eager') {
4253 if (!t.extras.skipLocationChange) {
4254 _this.setBrowserUrl(t.urlAfterRedirects, !!t.extras.replaceUrl, t.id, t.extras.state);
4255 }
4256 _this.browserUrlTree = t.urlAfterRedirects;
4257 }
4258 }),
4259 // Fire RoutesRecognized
4260 operators.tap(function (t) {
4261 var routesRecognized = new RoutesRecognized(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot);
4262 eventsSubject.next(routesRecognized);
4263 }));
4264 }
4265 else {
4266 var processPreviousUrl = urlTransition && _this.rawUrlTree &&
4267 _this.urlHandlingStrategy.shouldProcessUrl(_this.rawUrlTree);
4268 /* When the current URL shouldn't be processed, but the previous one was,
4269 * we handle this "error condition" by navigating to the previously
4270 * successful URL, but leaving the URL intact.*/
4271 if (processPreviousUrl) {
4272 var id = t.id, extractedUrl = t.extractedUrl, source = t.source, restoredState = t.restoredState, extras = t.extras;
4273 var navStart = new NavigationStart(id, _this.serializeUrl(extractedUrl), source, restoredState);
4274 eventsSubject.next(navStart);
4275 var targetSnapshot = createEmptyState(extractedUrl, _this.rootComponentType).snapshot;
4276 return rxjs.of(__assign(__assign({}, t), { targetSnapshot: targetSnapshot, urlAfterRedirects: extractedUrl, extras: __assign(__assign({}, extras), { skipLocationChange: false, replaceUrl: false }) }));
4277 }
4278 else {
4279 /* When neither the current or previous URL can be processed, do nothing
4280 * other than update router's internal reference to the current "settled"
4281 * URL. This way the next navigation will be coming from the current URL
4282 * in the browser.
4283 */
4284 _this.rawUrlTree = t.rawUrl;
4285 _this.browserUrlTree = t.urlAfterRedirects;
4286 t.resolve(null);
4287 return rxjs.EMPTY;
4288 }
4289 }
4290 }),
4291 // Before Preactivation
4292 switchTap(function (t) {
4293 var targetSnapshot = t.targetSnapshot, navigationId = t.id, appliedUrlTree = t.extractedUrl, rawUrlTree = t.rawUrl, _a = t.extras, skipLocationChange = _a.skipLocationChange, replaceUrl = _a.replaceUrl;
4294 return _this.hooks.beforePreactivation(targetSnapshot, {
4295 navigationId: navigationId,
4296 appliedUrlTree: appliedUrlTree,
4297 rawUrlTree: rawUrlTree,
4298 skipLocationChange: !!skipLocationChange,
4299 replaceUrl: !!replaceUrl,
4300 });
4301 }),
4302 // --- GUARDS ---
4303 operators.tap(function (t) {
4304 var guardsStart = new GuardsCheckStart(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot);
4305 _this.triggerEvent(guardsStart);
4306 }), operators.map(function (t) { return (__assign(__assign({}, t), { guards: getAllRouteGuards(t.targetSnapshot, t.currentSnapshot, _this.rootContexts) })); }), checkGuards(_this.ngModule.injector, function (evt) { return _this.triggerEvent(evt); }), operators.tap(function (t) {
4307 if (isUrlTree(t.guardsResult)) {
4308 var error = navigationCancelingError("Redirecting to \"" + _this.serializeUrl(t.guardsResult) + "\"");
4309 error.url = t.guardsResult;
4310 throw error;
4311 }
4312 }), operators.tap(function (t) {
4313 var guardsEnd = new GuardsCheckEnd(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot, !!t.guardsResult);
4314 _this.triggerEvent(guardsEnd);
4315 }), operators.filter(function (t) {
4316 if (!t.guardsResult) {
4317 _this.resetUrlToCurrentUrlTree();
4318 var navCancel = new NavigationCancel(t.id, _this.serializeUrl(t.extractedUrl), '');
4319 eventsSubject.next(navCancel);
4320 t.resolve(false);
4321 return false;
4322 }
4323 return true;
4324 }),
4325 // --- RESOLVE ---
4326 switchTap(function (t) {
4327 if (t.guards.canActivateChecks.length) {
4328 return rxjs.of(t).pipe(operators.tap(function (t) {
4329 var resolveStart = new ResolveStart(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot);
4330 _this.triggerEvent(resolveStart);
4331 }), operators.switchMap(function (t) {
4332 var dataResolved = false;
4333 return rxjs.of(t).pipe(resolveData(_this.paramsInheritanceStrategy, _this.ngModule.injector), operators.tap({
4334 next: function () { return dataResolved = true; },
4335 complete: function () {
4336 if (!dataResolved) {
4337 var navCancel = new NavigationCancel(t.id, _this.serializeUrl(t.extractedUrl), "At least one route resolver didn't emit any value.");
4338 eventsSubject.next(navCancel);
4339 t.resolve(false);
4340 }
4341 }
4342 }));
4343 }), operators.tap(function (t) {
4344 var resolveEnd = new ResolveEnd(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot);
4345 _this.triggerEvent(resolveEnd);
4346 }));
4347 }
4348 return undefined;
4349 }),
4350 // --- AFTER PREACTIVATION ---
4351 switchTap(function (t) {
4352 var targetSnapshot = t.targetSnapshot, navigationId = t.id, appliedUrlTree = t.extractedUrl, rawUrlTree = t.rawUrl, _a = t.extras, skipLocationChange = _a.skipLocationChange, replaceUrl = _a.replaceUrl;
4353 return _this.hooks.afterPreactivation(targetSnapshot, {
4354 navigationId: navigationId,
4355 appliedUrlTree: appliedUrlTree,
4356 rawUrlTree: rawUrlTree,
4357 skipLocationChange: !!skipLocationChange,
4358 replaceUrl: !!replaceUrl,
4359 });
4360 }), operators.map(function (t) {
4361 var targetRouterState = createRouterState(_this.routeReuseStrategy, t.targetSnapshot, t.currentRouterState);
4362 return (__assign(__assign({}, t), { targetRouterState: targetRouterState }));
4363 }),
4364 /* Once here, we are about to activate syncronously. The assumption is this
4365 will succeed, and user code may read from the Router service. Therefore
4366 before activation, we need to update router properties storing the current
4367 URL and the RouterState, as well as updated the browser URL. All this should
4368 happen *before* activating. */
4369 operators.tap(function (t) {
4370 _this.currentUrlTree = t.urlAfterRedirects;
4371 _this.rawUrlTree =
4372 _this.urlHandlingStrategy.merge(_this.currentUrlTree, t.rawUrl);
4373 _this.routerState = t.targetRouterState;
4374 if (_this.urlUpdateStrategy === 'deferred') {
4375 if (!t.extras.skipLocationChange) {
4376 _this.setBrowserUrl(_this.rawUrlTree, !!t.extras.replaceUrl, t.id, t.extras.state);
4377 }
4378 _this.browserUrlTree = t.urlAfterRedirects;
4379 }
4380 }), activateRoutes(_this.rootContexts, _this.routeReuseStrategy, function (evt) { return _this.triggerEvent(evt); }), operators.tap({
4381 next: function () {
4382 completed = true;
4383 },
4384 complete: function () {
4385 completed = true;
4386 }
4387 }), operators.finalize(function () {
4388 /* When the navigation stream finishes either through error or success, we
4389 * set the `completed` or `errored` flag. However, there are some situations
4390 * where we could get here without either of those being set. For instance, a
4391 * redirect during NavigationStart. Therefore, this is a catch-all to make
4392 * sure the NavigationCancel
4393 * event is fired when a navigation gets cancelled but not caught by other
4394 * means. */
4395 if (!completed && !errored) {
4396 // Must reset to current URL tree here to ensure history.state is set. On a
4397 // fresh page load, if a new navigation comes in before a successful
4398 // navigation completes, there will be nothing in
4399 // history.state.navigationId. This can cause sync problems with AngularJS
4400 // sync code which looks for a value here in order to determine whether or
4401 // not to handle a given popstate event or to leave it to the Angualr
4402 // router.
4403 _this.resetUrlToCurrentUrlTree();
4404 var navCancel = new NavigationCancel(t.id, _this.serializeUrl(t.extractedUrl), "Navigation ID " + t.id + " is not equal to the current navigation id " + _this.navigationId);
4405 eventsSubject.next(navCancel);
4406 t.resolve(false);
4407 }
4408 // currentNavigation should always be reset to null here. If navigation was
4409 // successful, lastSuccessfulTransition will have already been set. Therefore
4410 // we can safely set currentNavigation to null here.
4411 _this.currentNavigation = null;
4412 }), operators.catchError(function (e) {
4413 errored = true;
4414 /* This error type is issued during Redirect, and is handled as a
4415 * cancellation rather than an error. */
4416 if (isNavigationCancelingError(e)) {
4417 var redirecting = isUrlTree(e.url);
4418 if (!redirecting) {
4419 // Set property only if we're not redirecting. If we landed on a page and
4420 // redirect to `/` route, the new navigation is going to see the `/`
4421 // isn't a change from the default currentUrlTree and won't navigate.
4422 // This is only applicable with initial navigation, so setting
4423 // `navigated` only when not redirecting resolves this scenario.
4424 _this.navigated = true;
4425 _this.resetStateAndUrl(t.currentRouterState, t.currentUrlTree, t.rawUrl);
4426 }
4427 var navCancel = new NavigationCancel(t.id, _this.serializeUrl(t.extractedUrl), e.message);
4428 eventsSubject.next(navCancel);
4429 // When redirecting, we need to delay resolving the navigation
4430 // promise and push it to the redirect navigation
4431 if (!redirecting) {
4432 t.resolve(false);
4433 }
4434 else {
4435 // setTimeout is required so this navigation finishes with
4436 // the return EMPTY below. If it isn't allowed to finish
4437 // processing, there can be multiple navigations to the same
4438 // URL.
4439 setTimeout(function () {
4440 var mergedTree = _this.urlHandlingStrategy.merge(e.url, _this.rawUrlTree);
4441 var extras = {
4442 skipLocationChange: t.extras.skipLocationChange,
4443 replaceUrl: _this.urlUpdateStrategy === 'eager'
4444 };
4445 return _this.scheduleNavigation(mergedTree, 'imperative', null, extras, { resolve: t.resolve, reject: t.reject, promise: t.promise });
4446 }, 0);
4447 }
4448 /* All other errors should reset to the router's internal URL reference to
4449 * the pre-error state. */
4450 }
4451 else {
4452 _this.resetStateAndUrl(t.currentRouterState, t.currentUrlTree, t.rawUrl);
4453 var navError = new NavigationError(t.id, _this.serializeUrl(t.extractedUrl), e);
4454 eventsSubject.next(navError);
4455 try {
4456 t.resolve(_this.errorHandler(e));
4457 }
4458 catch (ee) {
4459 t.reject(ee);
4460 }
4461 }
4462 return rxjs.EMPTY;
4463 }));
4464 // TODO(jasonaden): remove cast once g3 is on updated TypeScript
4465 }));
4466 };
4467 /**
4468 * @internal
4469 * TODO: this should be removed once the constructor of the router made internal
4470 */
4471 Router.prototype.resetRootComponentType = function (rootComponentType) {
4472 this.rootComponentType = rootComponentType;
4473 // TODO: vsavkin router 4.0 should make the root component set to null
4474 // this will simplify the lifecycle of the router.
4475 this.routerState.root.component = this.rootComponentType;
4476 };
4477 Router.prototype.getTransition = function () {
4478 var transition = this.transitions.value;
4479 // This value needs to be set. Other values such as extractedUrl are set on initial navigation
4480 // but the urlAfterRedirects may not get set if we aren't processing the new URL *and* not
4481 // processing the previous URL.
4482 transition.urlAfterRedirects = this.browserUrlTree;
4483 return transition;
4484 };
4485 Router.prototype.setTransition = function (t) {
4486 this.transitions.next(__assign(__assign({}, this.getTransition()), t));
4487 };
4488 /**
4489 * Sets up the location change listener and performs the initial navigation.
4490 */
4491 Router.prototype.initialNavigation = function () {
4492 this.setUpLocationChangeListener();
4493 if (this.navigationId === 0) {
4494 this.navigateByUrl(this.location.path(true), { replaceUrl: true });
4495 }
4496 };
4497 /**
4498 * Sets up the location change listener.
4499 */
4500 Router.prototype.setUpLocationChangeListener = function () {
4501 var _this = this;
4502 // Don't need to use Zone.wrap any more, because zone.js
4503 // already patch onPopState, so location change callback will
4504 // run into ngZone
4505 if (!this.locationSubscription) {
4506 this.locationSubscription = this.location.subscribe(function (change) {
4507 var rawUrlTree = _this.parseUrl(change['url']);
4508 var source = change['type'] === 'popstate' ? 'popstate' : 'hashchange';
4509 // Navigations coming from Angular router have a navigationId state property. When this
4510 // exists, restore the state.
4511 var state = change.state && change.state.navigationId ? change.state : null;
4512 setTimeout(function () {
4513 _this.scheduleNavigation(rawUrlTree, source, state, { replaceUrl: true });
4514 }, 0);
4515 });
4516 }
4517 };
4518 Object.defineProperty(Router.prototype, "url", {
4519 /** The current URL. */
4520 get: function () {
4521 return this.serializeUrl(this.currentUrlTree);
4522 },
4523 enumerable: false,
4524 configurable: true
4525 });
4526 /** The current Navigation object if one exists */
4527 Router.prototype.getCurrentNavigation = function () {
4528 return this.currentNavigation;
4529 };
4530 /** @internal */
4531 Router.prototype.triggerEvent = function (event) {
4532 this.events.next(event);
4533 };
4534 /**
4535 * Resets the configuration used for navigation and generating links.
4536 *
4537 * @param config The route array for the new configuration.
4538 *
4539 * @usageNotes
4540 *
4541 * ```
4542 * router.resetConfig([
4543 * { path: 'team/:id', component: TeamCmp, children: [
4544 * { path: 'simple', component: SimpleCmp },
4545 * { path: 'user/:name', component: UserCmp }
4546 * ]}
4547 * ]);
4548 * ```
4549 */
4550 Router.prototype.resetConfig = function (config) {
4551 validateConfig(config);
4552 this.config = config.map(standardizeConfig);
4553 this.navigated = false;
4554 this.lastSuccessfulId = -1;
4555 };
4556 /** @docsNotRequired */
4557 Router.prototype.ngOnDestroy = function () {
4558 this.dispose();
4559 };
4560 /** Disposes of the router. */
4561 Router.prototype.dispose = function () {
4562 if (this.locationSubscription) {
4563 this.locationSubscription.unsubscribe();
4564 this.locationSubscription = null;
4565 }
4566 };
4567 /**
4568 * Applies an array of commands to the current URL tree and creates a new URL tree.
4569 *
4570 * When given an activated route, applies the given commands starting from the route.
4571 * Otherwise, applies the given command starting from the root.
4572 *
4573 * @param commands An array of commands to apply.
4574 * @param navigationExtras Options that control the navigation strategy. This function
4575 * only utilizes properties in `NavigationExtras` that would change the provided URL.
4576 * @returns The new URL tree.
4577 *
4578 * @usageNotes
4579 *
4580 * ```
4581 * // create /team/33/user/11
4582 * router.createUrlTree(['/team', 33, 'user', 11]);
4583 *
4584 * // create /team/33;expand=true/user/11
4585 * router.createUrlTree(['/team', 33, {expand: true}, 'user', 11]);
4586 *
4587 * // you can collapse static segments like this (this works only with the first passed-in value):
4588 * router.createUrlTree(['/team/33/user', userId]);
4589 *
4590 * // If the first segment can contain slashes, and you do not want the router to split it,
4591 * // you can do the following:
4592 * router.createUrlTree([{segmentPath: '/one/two'}]);
4593 *
4594 * // create /team/33/(user/11//right:chat)
4595 * router.createUrlTree(['/team', 33, {outlets: {primary: 'user/11', right: 'chat'}}]);
4596 *
4597 * // remove the right secondary node
4598 * router.createUrlTree(['/team', 33, {outlets: {primary: 'user/11', right: null}}]);
4599 *
4600 * // assuming the current url is `/team/33/user/11` and the route points to `user/11`
4601 *
4602 * // navigate to /team/33/user/11/details
4603 * router.createUrlTree(['details'], {relativeTo: route});
4604 *
4605 * // navigate to /team/33/user/22
4606 * router.createUrlTree(['../22'], {relativeTo: route});
4607 *
4608 * // navigate to /team/44/user/22
4609 * router.createUrlTree(['../../team/44/user/22'], {relativeTo: route});
4610 * ```
4611 */
4612 Router.prototype.createUrlTree = function (commands, navigationExtras) {
4613 if (navigationExtras === void 0) { navigationExtras = {}; }
4614 var relativeTo = navigationExtras.relativeTo, queryParams = navigationExtras.queryParams, fragment = navigationExtras.fragment, preserveQueryParams = navigationExtras.preserveQueryParams, queryParamsHandling = navigationExtras.queryParamsHandling, preserveFragment = navigationExtras.preserveFragment;
4615 if (core.isDevMode() && preserveQueryParams && console && console.warn) {
4616 console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.');
4617 }
4618 var a = relativeTo || this.routerState.root;
4619 var f = preserveFragment ? this.currentUrlTree.fragment : fragment;
4620 var q = null;
4621 if (queryParamsHandling) {
4622 switch (queryParamsHandling) {
4623 case 'merge':
4624 q = __assign(__assign({}, this.currentUrlTree.queryParams), queryParams);
4625 break;
4626 case 'preserve':
4627 q = this.currentUrlTree.queryParams;
4628 break;
4629 default:
4630 q = queryParams || null;
4631 }
4632 }
4633 else {
4634 q = preserveQueryParams ? this.currentUrlTree.queryParams : queryParams || null;
4635 }
4636 if (q !== null) {
4637 q = this.removeEmptyProps(q);
4638 }
4639 return createUrlTree(a, this.currentUrlTree, commands, q, f);
4640 };
4641 /**
4642 * Navigate based on the provided URL, which must be absolute.
4643 *
4644 * @param url An absolute URL. The function does not apply any delta to the current URL.
4645 * @param extras An object containing properties that modify the navigation strategy.
4646 * The function ignores any properties in the `NavigationExtras` that would change the
4647 * provided URL.
4648 *
4649 * @returns A Promise that resolves to 'true' when navigation succeeds,
4650 * to 'false' when navigation fails, or is rejected on error.
4651 *
4652 * @usageNotes
4653 *
4654 * ```
4655 * router.navigateByUrl("/team/33/user/11");
4656 *
4657 * // Navigate without updating the URL
4658 * router.navigateByUrl("/team/33/user/11", { skipLocationChange: true });
4659 * ```
4660 *
4661 */
4662 Router.prototype.navigateByUrl = function (url, extras) {
4663 if (extras === void 0) { extras = { skipLocationChange: false }; }
4664 if (core.isDevMode() && this.isNgZoneEnabled && !core.NgZone.isInAngularZone()) {
4665 this.console.warn("Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?");
4666 }
4667 var urlTree = isUrlTree(url) ? url : this.parseUrl(url);
4668 var mergedTree = this.urlHandlingStrategy.merge(urlTree, this.rawUrlTree);
4669 return this.scheduleNavigation(mergedTree, 'imperative', null, extras);
4670 };
4671 /**
4672 * Navigate based on the provided array of commands and a starting point.
4673 * If no starting route is provided, the navigation is absolute.
4674 *
4675 * Returns a promise that:
4676 * - resolves to 'true' when navigation succeeds,
4677 * - resolves to 'false' when navigation fails,
4678 * - is rejected when an error happens.
4679 *
4680 * @usageNotes
4681 *
4682 * ```
4683 * router.navigate(['team', 33, 'user', 11], {relativeTo: route});
4684 *
4685 * // Navigate without updating the URL
4686 * router.navigate(['team', 33, 'user', 11], {relativeTo: route, skipLocationChange: true});
4687 * ```
4688 *
4689 * The first parameter of `navigate()` is a delta to be applied to the current URL
4690 * or the one provided in the `relativeTo` property of the second parameter (the
4691 * `NavigationExtras`).
4692 *
4693 * In order to affect this browser's `history.state` entry, the `state`
4694 * parameter can be passed. This must be an object because the router
4695 * will add the `navigationId` property to this object before creating
4696 * the new history item.
4697 */
4698 Router.prototype.navigate = function (commands, extras) {
4699 if (extras === void 0) { extras = { skipLocationChange: false }; }
4700 validateCommands(commands);
4701 return this.navigateByUrl(this.createUrlTree(commands, extras), extras);
4702 };
4703 /** Serializes a `UrlTree` into a string */
4704 Router.prototype.serializeUrl = function (url) {
4705 return this.urlSerializer.serialize(url);
4706 };
4707 /** Parses a string into a `UrlTree` */
4708 Router.prototype.parseUrl = function (url) {
4709 var urlTree;
4710 try {
4711 urlTree = this.urlSerializer.parse(url);
4712 }
4713 catch (e) {
4714 urlTree = this.malformedUriErrorHandler(e, this.urlSerializer, url);
4715 }
4716 return urlTree;
4717 };
4718 /** Returns whether the url is activated */
4719 Router.prototype.isActive = function (url, exact) {
4720 if (isUrlTree(url)) {
4721 return containsTree(this.currentUrlTree, url, exact);
4722 }
4723 var urlTree = this.parseUrl(url);
4724 return containsTree(this.currentUrlTree, urlTree, exact);
4725 };
4726 Router.prototype.removeEmptyProps = function (params) {
4727 return Object.keys(params).reduce(function (result, key) {
4728 var value = params[key];
4729 if (value !== null && value !== undefined) {
4730 result[key] = value;
4731 }
4732 return result;
4733 }, {});
4734 };
4735 Router.prototype.processNavigations = function () {
4736 var _this = this;
4737 this.navigations.subscribe(function (t) {
4738 _this.navigated = true;
4739 _this.lastSuccessfulId = t.id;
4740 _this.events
4741 .next(new NavigationEnd(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(_this.currentUrlTree)));
4742 _this.lastSuccessfulNavigation = _this.currentNavigation;
4743 _this.currentNavigation = null;
4744 t.resolve(true);
4745 }, function (e) {
4746 _this.console.warn("Unhandled Navigation Error: ");
4747 });
4748 };
4749 Router.prototype.scheduleNavigation = function (rawUrl, source, restoredState, extras, priorPromise) {
4750 var lastNavigation = this.getTransition();
4751 // If the user triggers a navigation imperatively (e.g., by using navigateByUrl),
4752 // and that navigation results in 'replaceState' that leads to the same URL,
4753 // we should skip those.
4754 if (lastNavigation && source !== 'imperative' && lastNavigation.source === 'imperative' &&
4755 lastNavigation.rawUrl.toString() === rawUrl.toString()) {
4756 return Promise.resolve(true); // return value is not used
4757 }
4758 // Because of a bug in IE and Edge, the location class fires two events (popstate and
4759 // hashchange) every single time. The second one should be ignored. Otherwise, the URL will
4760 // flicker. Handles the case when a popstate was emitted first.
4761 if (lastNavigation && source == 'hashchange' && lastNavigation.source === 'popstate' &&
4762 lastNavigation.rawUrl.toString() === rawUrl.toString()) {
4763 return Promise.resolve(true); // return value is not used
4764 }
4765 // Because of a bug in IE and Edge, the location class fires two events (popstate and
4766 // hashchange) every single time. The second one should be ignored. Otherwise, the URL will
4767 // flicker. Handles the case when a hashchange was emitted first.
4768 if (lastNavigation && source == 'popstate' && lastNavigation.source === 'hashchange' &&
4769 lastNavigation.rawUrl.toString() === rawUrl.toString()) {
4770 return Promise.resolve(true); // return value is not used
4771 }
4772 var resolve;
4773 var reject;
4774 var promise;
4775 if (priorPromise) {
4776 resolve = priorPromise.resolve;
4777 reject = priorPromise.reject;
4778 promise = priorPromise.promise;
4779 }
4780 else {
4781 promise = new Promise(function (res, rej) {
4782 resolve = res;
4783 reject = rej;
4784 });
4785 }
4786 var id = ++this.navigationId;
4787 this.setTransition({
4788 id: id,
4789 source: source,
4790 restoredState: restoredState,
4791 currentUrlTree: this.currentUrlTree,
4792 currentRawUrl: this.rawUrlTree,
4793 rawUrl: rawUrl,
4794 extras: extras,
4795 resolve: resolve,
4796 reject: reject,
4797 promise: promise,
4798 currentSnapshot: this.routerState.snapshot,
4799 currentRouterState: this.routerState
4800 });
4801 // Make sure that the error is propagated even though `processNavigations` catch
4802 // handler does not rethrow
4803 return promise.catch(function (e) {
4804 return Promise.reject(e);
4805 });
4806 };
4807 Router.prototype.setBrowserUrl = function (url, replaceUrl, id, state) {
4808 var path = this.urlSerializer.serialize(url);
4809 state = state || {};
4810 if (this.location.isCurrentPathEqualTo(path) || replaceUrl) {
4811 // TODO(jasonaden): Remove first `navigationId` and rely on `ng` namespace.
4812 this.location.replaceState(path, '', __assign(__assign({}, state), { navigationId: id }));
4813 }
4814 else {
4815 this.location.go(path, '', __assign(__assign({}, state), { navigationId: id }));
4816 }
4817 };
4818 Router.prototype.resetStateAndUrl = function (storedState, storedUrl, rawUrl) {
4819 this.routerState = storedState;
4820 this.currentUrlTree = storedUrl;
4821 this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, rawUrl);
4822 this.resetUrlToCurrentUrlTree();
4823 };
4824 Router.prototype.resetUrlToCurrentUrlTree = function () {
4825 this.location.replaceState(this.urlSerializer.serialize(this.rawUrlTree), '', { navigationId: this.lastSuccessfulId });
4826 };
4827 Router.decorators = [
4828 { type: core.Injectable }
4829 ];
4830 Router.ctorParameters = function () { return [
4831 { type: core.Type },
4832 { type: UrlSerializer },
4833 { type: ChildrenOutletContexts },
4834 { type: common.Location },
4835 { type: core.Injector },
4836 { type: core.NgModuleFactoryLoader },
4837 { type: core.Compiler },
4838 { type: undefined }
4839 ]; };
4840 return Router;
4841 }());
4842 function validateCommands(commands) {
4843 for (var i = 0; i < commands.length; i++) {
4844 var cmd = commands[i];
4845 if (cmd == null) {
4846 throw new Error("The requested path contains " + cmd + " segment at index " + i);
4847 }
4848 }
4849 }
4850
4851 /**
4852 * @license
4853 * Copyright Google LLC All Rights Reserved.
4854 *
4855 * Use of this source code is governed by an MIT-style license that can be
4856 * found in the LICENSE file at https://angular.io/license
4857 */
4858 /**
4859 * @description
4860 *
4861 * Lets you link to specific routes in your app.
4862 *
4863 * Consider the following route configuration:
4864 * `[{ path: 'user/:name', component: UserCmp }]`.
4865 * When linking to this `user/:name` route, you use the `RouterLink` directive.
4866 *
4867 * If the link is static, you can use the directive as follows:
4868 * `<a routerLink="/user/bob">link to user component</a>`
4869 *
4870 * If you use dynamic values to generate the link, you can pass an array of path
4871 * segments, followed by the params for each segment.
4872 *
4873 * For instance `['/team', teamId, 'user', userName, {details: true}]`
4874 * means that we want to generate a link to `/team/11/user/bob;details=true`.
4875 *
4876 * Multiple static segments can be merged into one
4877 * (e.g., `['/team/11/user', userName, {details: true}]`).
4878 *
4879 * The first segment name can be prepended with `/`, `./`, or `../`:
4880 * * If the first segment begins with `/`, the router will look up the route from the root of the
4881 * app.
4882 * * If the first segment begins with `./`, or doesn't begin with a slash, the router will
4883 * instead look in the children of the current activated route.
4884 * * And if the first segment begins with `../`, the router will go up one level.
4885 *
4886 * You can set query params and fragment as follows:
4887 *
4888 * ```
4889 * <a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" fragment="education">
4890 * link to user component
4891 * </a>
4892 * ```
4893 * RouterLink will use these to generate this link: `/user/bob?debug=true#education`.
4894 *
4895 * (Deprecated in v4.0.0 use `queryParamsHandling` instead) You can also tell the
4896 * directive to preserve the current query params and fragment:
4897 *
4898 * ```
4899 * <a [routerLink]="['/user/bob']" preserveQueryParams preserveFragment>
4900 * link to user component
4901 * </a>
4902 * ```
4903 *
4904 * You can tell the directive how to handle queryParams. Available options are:
4905 * - `'merge'`: merge the queryParams into the current queryParams
4906 * - `'preserve'`: preserve the current queryParams
4907 * - default/`''`: use the queryParams only
4908 *
4909 * Same options for {@link NavigationExtras#queryParamsHandling
4910 * NavigationExtras#queryParamsHandling}.
4911 *
4912 * ```
4913 * <a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" queryParamsHandling="merge">
4914 * link to user component
4915 * </a>
4916 * ```
4917 *
4918 * You can provide a `state` value to be persisted to the browser's History.state
4919 * property (See https://developer.mozilla.org/en-US/docs/Web/API/History#Properties). It's
4920 * used as follows:
4921 *
4922 * ```
4923 * <a [routerLink]="['/user/bob']" [state]="{tracingId: 123}">
4924 * link to user component
4925 * </a>
4926 * ```
4927 *
4928 * And later the value can be read from the router through `router.getCurrentNavigation`.
4929 * For example, to capture the `tracingId` above during the `NavigationStart` event:
4930 *
4931 * ```
4932 * // Get NavigationStart events
4933 * router.events.pipe(filter(e => e instanceof NavigationStart)).subscribe(e => {
4934 * const navigation = router.getCurrentNavigation();
4935 * tracingService.trace({id: navigation.extras.state.tracingId});
4936 * });
4937 * ```
4938 *
4939 * The router link directive always treats the provided input as a delta to the current url.
4940 *
4941 * For instance, if the current url is `/user/(box//aux:team)`.
4942 *
4943 * Then the following link `<a [routerLink]="['/user/jim']">Jim</a>` will generate the link
4944 * `/user/(jim//aux:team)`.
4945 *
4946 * See {@link Router#createUrlTree createUrlTree} for more information.
4947 *
4948 * @ngModule RouterModule
4949 *
4950 * @publicApi
4951 */
4952 var RouterLink = /** @class */ (function () {
4953 function RouterLink(router, route, tabIndex, renderer, el) {
4954 this.router = router;
4955 this.route = route;
4956 this.commands = [];
4957 if (tabIndex == null) {
4958 renderer.setAttribute(el.nativeElement, 'tabindex', '0');
4959 }
4960 }
4961 Object.defineProperty(RouterLink.prototype, "routerLink", {
4962 /**
4963 * @param commands An array of commands to pass to {@link Router#createUrlTree
4964 * Router#createUrlTree}.
4965 * - **array**: commands to pass to {@link Router#createUrlTree Router#createUrlTree}.
4966 * - **string**: shorthand for array of commands with just the string, i.e. `['/route']`
4967 * - **null|undefined**: shorthand for an empty array of commands, i.e. `[]`
4968 * @see {@link Router#createUrlTree Router#createUrlTree}
4969 */
4970 set: function (commands) {
4971 if (commands != null) {
4972 this.commands = Array.isArray(commands) ? commands : [commands];
4973 }
4974 else {
4975 this.commands = [];
4976 }
4977 },
4978 enumerable: false,
4979 configurable: true
4980 });
4981 Object.defineProperty(RouterLink.prototype, "preserveQueryParams", {
4982 /**
4983 * @deprecated As of Angular v4.0 use `queryParamsHandling` instead.
4984 */
4985 set: function (value) {
4986 if (core.isDevMode() && console && console.warn) {
4987 console.warn('preserveQueryParams is deprecated!, use queryParamsHandling instead.');
4988 }
4989 this.preserve = value;
4990 },
4991 enumerable: false,
4992 configurable: true
4993 });
4994 RouterLink.prototype.onClick = function () {
4995 var extras = {
4996 skipLocationChange: attrBoolValue(this.skipLocationChange),
4997 replaceUrl: attrBoolValue(this.replaceUrl),
4998 state: this.state,
4999 };
5000 this.router.navigateByUrl(this.urlTree, extras);
5001 return true;
5002 };
5003 Object.defineProperty(RouterLink.prototype, "urlTree", {
5004 get: function () {
5005 return this.router.createUrlTree(this.commands, {
5006 relativeTo: this.route,
5007 queryParams: this.queryParams,
5008 fragment: this.fragment,
5009 preserveQueryParams: attrBoolValue(this.preserve),
5010 queryParamsHandling: this.queryParamsHandling,
5011 preserveFragment: attrBoolValue(this.preserveFragment),
5012 });
5013 },
5014 enumerable: false,
5015 configurable: true
5016 });
5017 RouterLink.decorators = [
5018 { type: core.Directive, args: [{ selector: ':not(a):not(area)[routerLink]' },] }
5019 ];
5020 RouterLink.ctorParameters = function () { return [
5021 { type: Router },
5022 { type: ActivatedRoute },
5023 { type: String, decorators: [{ type: core.Attribute, args: ['tabindex',] }] },
5024 { type: core.Renderer2 },
5025 { type: core.ElementRef }
5026 ]; };
5027 RouterLink.propDecorators = {
5028 queryParams: [{ type: core.Input }],
5029 fragment: [{ type: core.Input }],
5030 queryParamsHandling: [{ type: core.Input }],
5031 preserveFragment: [{ type: core.Input }],
5032 skipLocationChange: [{ type: core.Input }],
5033 replaceUrl: [{ type: core.Input }],
5034 state: [{ type: core.Input }],
5035 routerLink: [{ type: core.Input }],
5036 preserveQueryParams: [{ type: core.Input }],
5037 onClick: [{ type: core.HostListener, args: ['click',] }]
5038 };
5039 return RouterLink;
5040 }());
5041 /**
5042 * @description
5043 *
5044 * Lets you link to specific routes in your app.
5045 *
5046 * See `RouterLink` for more information.
5047 *
5048 * @ngModule RouterModule
5049 *
5050 * @publicApi
5051 */
5052 var RouterLinkWithHref = /** @class */ (function () {
5053 function RouterLinkWithHref(router, route, locationStrategy) {
5054 var _this = this;
5055 this.router = router;
5056 this.route = route;
5057 this.locationStrategy = locationStrategy;
5058 this.commands = [];
5059 this.subscription = router.events.subscribe(function (s) {
5060 if (s instanceof NavigationEnd) {
5061 _this.updateTargetUrlAndHref();
5062 }
5063 });
5064 }
5065 Object.defineProperty(RouterLinkWithHref.prototype, "routerLink", {
5066 /**
5067 * @param commands An array of commands to pass to {@link Router#createUrlTree
5068 * Router#createUrlTree}.
5069 * - **array**: commands to pass to {@link Router#createUrlTree Router#createUrlTree}.
5070 * - **string**: shorthand for array of commands with just the string, i.e. `['/route']`
5071 * - **null|undefined**: shorthand for an empty array of commands, i.e. `[]`
5072 * @see {@link Router#createUrlTree Router#createUrlTree}
5073 */
5074 set: function (commands) {
5075 if (commands != null) {
5076 this.commands = Array.isArray(commands) ? commands : [commands];
5077 }
5078 else {
5079 this.commands = [];
5080 }
5081 },
5082 enumerable: false,
5083 configurable: true
5084 });
5085 Object.defineProperty(RouterLinkWithHref.prototype, "preserveQueryParams", {
5086 /**
5087 * @deprecated As of Angular v4.0 use `queryParamsHandling` instead.
5088 */
5089 set: function (value) {
5090 if (core.isDevMode() && console && console.warn) {
5091 console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.');
5092 }
5093 this.preserve = value;
5094 },
5095 enumerable: false,
5096 configurable: true
5097 });
5098 RouterLinkWithHref.prototype.ngOnChanges = function (changes) {
5099 this.updateTargetUrlAndHref();
5100 };
5101 RouterLinkWithHref.prototype.ngOnDestroy = function () {
5102 this.subscription.unsubscribe();
5103 };
5104 RouterLinkWithHref.prototype.onClick = function (button, ctrlKey, metaKey, shiftKey) {
5105 if (button !== 0 || ctrlKey || metaKey || shiftKey) {
5106 return true;
5107 }
5108 if (typeof this.target === 'string' && this.target != '_self') {
5109 return true;
5110 }
5111 var extras = {
5112 skipLocationChange: attrBoolValue(this.skipLocationChange),
5113 replaceUrl: attrBoolValue(this.replaceUrl),
5114 state: this.state
5115 };
5116 this.router.navigateByUrl(this.urlTree, extras);
5117 return false;
5118 };
5119 RouterLinkWithHref.prototype.updateTargetUrlAndHref = function () {
5120 this.href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.urlTree));
5121 };
5122 Object.defineProperty(RouterLinkWithHref.prototype, "urlTree", {
5123 get: function () {
5124 return this.router.createUrlTree(this.commands, {
5125 relativeTo: this.route,
5126 queryParams: this.queryParams,
5127 fragment: this.fragment,
5128 preserveQueryParams: attrBoolValue(this.preserve),
5129 queryParamsHandling: this.queryParamsHandling,
5130 preserveFragment: attrBoolValue(this.preserveFragment),
5131 });
5132 },
5133 enumerable: false,
5134 configurable: true
5135 });
5136 RouterLinkWithHref.decorators = [
5137 { type: core.Directive, args: [{ selector: 'a[routerLink],area[routerLink]' },] }
5138 ];
5139 RouterLinkWithHref.ctorParameters = function () { return [
5140 { type: Router },
5141 { type: ActivatedRoute },
5142 { type: common.LocationStrategy }
5143 ]; };
5144 RouterLinkWithHref.propDecorators = {
5145 target: [{ type: core.HostBinding, args: ['attr.target',] }, { type: core.Input }],
5146 queryParams: [{ type: core.Input }],
5147 fragment: [{ type: core.Input }],
5148 queryParamsHandling: [{ type: core.Input }],
5149 preserveFragment: [{ type: core.Input }],
5150 skipLocationChange: [{ type: core.Input }],
5151 replaceUrl: [{ type: core.Input }],
5152 state: [{ type: core.Input }],
5153 href: [{ type: core.HostBinding }],
5154 routerLink: [{ type: core.Input }],
5155 preserveQueryParams: [{ type: core.Input }],
5156 onClick: [{ type: core.HostListener, args: ['click', ['$event.button', '$event.ctrlKey', '$event.metaKey', '$event.shiftKey'],] }]
5157 };
5158 return RouterLinkWithHref;
5159 }());
5160 function attrBoolValue(s) {
5161 return s === '' || !!s;
5162 }
5163
5164 /**
5165 * @license
5166 * Copyright Google LLC All Rights Reserved.
5167 *
5168 * Use of this source code is governed by an MIT-style license that can be
5169 * found in the LICENSE file at https://angular.io/license
5170 */
5171 /**
5172 *
5173 * @description
5174 *
5175 * Lets you add a CSS class to an element when the link's route becomes active.
5176 *
5177 * This directive lets you add a CSS class to an element when the link's route
5178 * becomes active.
5179 *
5180 * Consider the following example:
5181 *
5182 * ```
5183 * <a routerLink="/user/bob" routerLinkActive="active-link">Bob</a>
5184 * ```
5185 *
5186 * When the url is either '/user' or '/user/bob', the active-link class will
5187 * be added to the `a` tag. If the url changes, the class will be removed.
5188 *
5189 * You can set more than one class, as follows:
5190 *
5191 * ```
5192 * <a routerLink="/user/bob" routerLinkActive="class1 class2">Bob</a>
5193 * <a routerLink="/user/bob" [routerLinkActive]="['class1', 'class2']">Bob</a>
5194 * ```
5195 *
5196 * You can configure RouterLinkActive by passing `exact: true`. This will add the classes
5197 * only when the url matches the link exactly.
5198 *
5199 * ```
5200 * <a routerLink="/user/bob" routerLinkActive="active-link" [routerLinkActiveOptions]="{exact:
5201 * true}">Bob</a>
5202 * ```
5203 *
5204 * You can assign the RouterLinkActive instance to a template variable and directly check
5205 * the `isActive` status.
5206 * ```
5207 * <a routerLink="/user/bob" routerLinkActive #rla="routerLinkActive">
5208 * Bob {{ rla.isActive ? '(already open)' : ''}}
5209 * </a>
5210 * ```
5211 *
5212 * Finally, you can apply the RouterLinkActive directive to an ancestor of a RouterLink.
5213 *
5214 * ```
5215 * <div routerLinkActive="active-link" [routerLinkActiveOptions]="{exact: true}">
5216 * <a routerLink="/user/jim">Jim</a>
5217 * <a routerLink="/user/bob">Bob</a>
5218 * </div>
5219 * ```
5220 *
5221 * This will set the active-link class on the div tag if the url is either '/user/jim' or
5222 * '/user/bob'.
5223 *
5224 * @ngModule RouterModule
5225 *
5226 * @publicApi
5227 */
5228 var RouterLinkActive = /** @class */ (function () {
5229 function RouterLinkActive(router, element, renderer, cdr, link, linkWithHref) {
5230 var _this = this;
5231 this.router = router;
5232 this.element = element;
5233 this.renderer = renderer;
5234 this.cdr = cdr;
5235 this.link = link;
5236 this.linkWithHref = linkWithHref;
5237 this.classes = [];
5238 this.isActive = false;
5239 this.routerLinkActiveOptions = { exact: false };
5240 this.subscription = router.events.subscribe(function (s) {
5241 if (s instanceof NavigationEnd) {
5242 _this.update();
5243 }
5244 });
5245 }
5246 RouterLinkActive.prototype.ngAfterContentInit = function () {
5247 var _this = this;
5248 this.links.changes.subscribe(function (_) { return _this.update(); });
5249 this.linksWithHrefs.changes.subscribe(function (_) { return _this.update(); });
5250 this.update();
5251 };
5252 Object.defineProperty(RouterLinkActive.prototype, "routerLinkActive", {
5253 set: function (data) {
5254 var classes = Array.isArray(data) ? data : data.split(' ');
5255 this.classes = classes.filter(function (c) { return !!c; });
5256 },
5257 enumerable: false,
5258 configurable: true
5259 });
5260 RouterLinkActive.prototype.ngOnChanges = function (changes) {
5261 this.update();
5262 };
5263 RouterLinkActive.prototype.ngOnDestroy = function () {
5264 this.subscription.unsubscribe();
5265 };
5266 RouterLinkActive.prototype.update = function () {
5267 var _this = this;
5268 if (!this.links || !this.linksWithHrefs || !this.router.navigated)
5269 return;
5270 Promise.resolve().then(function () {
5271 var hasActiveLinks = _this.hasActiveLinks();
5272 if (_this.isActive !== hasActiveLinks) {
5273 _this.isActive = hasActiveLinks;
5274 _this.cdr.markForCheck();
5275 _this.classes.forEach(function (c) {
5276 if (hasActiveLinks) {
5277 _this.renderer.addClass(_this.element.nativeElement, c);
5278 }
5279 else {
5280 _this.renderer.removeClass(_this.element.nativeElement, c);
5281 }
5282 });
5283 }
5284 });
5285 };
5286 RouterLinkActive.prototype.isLinkActive = function (router) {
5287 var _this = this;
5288 return function (link) {
5289 return router.isActive(link.urlTree, _this.routerLinkActiveOptions.exact);
5290 };
5291 };
5292 RouterLinkActive.prototype.hasActiveLinks = function () {
5293 var isActiveCheckFn = this.isLinkActive(this.router);
5294 return this.link && isActiveCheckFn(this.link) ||
5295 this.linkWithHref && isActiveCheckFn(this.linkWithHref) ||
5296 this.links.some(isActiveCheckFn) || this.linksWithHrefs.some(isActiveCheckFn);
5297 };
5298 RouterLinkActive.decorators = [
5299 { type: core.Directive, args: [{
5300 selector: '[routerLinkActive]',
5301 exportAs: 'routerLinkActive',
5302 },] }
5303 ];
5304 RouterLinkActive.ctorParameters = function () { return [
5305 { type: Router },
5306 { type: core.ElementRef },
5307 { type: core.Renderer2 },
5308 { type: core.ChangeDetectorRef },
5309 { type: RouterLink, decorators: [{ type: core.Optional }] },
5310 { type: RouterLinkWithHref, decorators: [{ type: core.Optional }] }
5311 ]; };
5312 RouterLinkActive.propDecorators = {
5313 links: [{ type: core.ContentChildren, args: [RouterLink, { descendants: true },] }],
5314 linksWithHrefs: [{ type: core.ContentChildren, args: [RouterLinkWithHref, { descendants: true },] }],
5315 routerLinkActiveOptions: [{ type: core.Input }],
5316 routerLinkActive: [{ type: core.Input }]
5317 };
5318 return RouterLinkActive;
5319 }());
5320
5321 /**
5322 * @license
5323 * Copyright Google LLC All Rights Reserved.
5324 *
5325 * Use of this source code is governed by an MIT-style license that can be
5326 * found in the LICENSE file at https://angular.io/license
5327 */
5328 /**
5329 * @description
5330 *
5331 * Acts as a placeholder that Angular dynamically fills based on the current router state.
5332 *
5333 * Each outlet can have a unique name, determined by the optional `name` attribute.
5334 * The name cannot be set or changed dynamically. If not set, default value is "primary".
5335 *
5336 * ```
5337 * <router-outlet></router-outlet>
5338 * <router-outlet name='left'></router-outlet>
5339 * <router-outlet name='right'></router-outlet>
5340 * ```
5341 *
5342 * A router outlet emits an activate event when a new component is instantiated,
5343 * and a deactivate event when a component is destroyed.
5344 *
5345 * ```
5346 * <router-outlet
5347 * (activate)='onActivate($event)'
5348 * (deactivate)='onDeactivate($event)'></router-outlet>
5349 * ```
5350 * @ngModule RouterModule
5351 *
5352 * @publicApi
5353 */
5354 var RouterOutlet = /** @class */ (function () {
5355 function RouterOutlet(parentContexts, location, resolver, name, changeDetector) {
5356 this.parentContexts = parentContexts;
5357 this.location = location;
5358 this.resolver = resolver;
5359 this.changeDetector = changeDetector;
5360 this.activated = null;
5361 this._activatedRoute = null;
5362 this.activateEvents = new core.EventEmitter();
5363 this.deactivateEvents = new core.EventEmitter();
5364 this.name = name || PRIMARY_OUTLET;
5365 parentContexts.onChildOutletCreated(this.name, this);
5366 }
5367 RouterOutlet.prototype.ngOnDestroy = function () {
5368 this.parentContexts.onChildOutletDestroyed(this.name);
5369 };
5370 RouterOutlet.prototype.ngOnInit = function () {
5371 if (!this.activated) {
5372 // If the outlet was not instantiated at the time the route got activated we need to populate
5373 // the outlet when it is initialized (ie inside a NgIf)
5374 var context = this.parentContexts.getContext(this.name);
5375 if (context && context.route) {
5376 if (context.attachRef) {
5377 // `attachRef` is populated when there is an existing component to mount
5378 this.attach(context.attachRef, context.route);
5379 }
5380 else {
5381 // otherwise the component defined in the configuration is created
5382 this.activateWith(context.route, context.resolver || null);
5383 }
5384 }
5385 }
5386 };
5387 Object.defineProperty(RouterOutlet.prototype, "isActivated", {
5388 get: function () {
5389 return !!this.activated;
5390 },
5391 enumerable: false,
5392 configurable: true
5393 });
5394 Object.defineProperty(RouterOutlet.prototype, "component", {
5395 get: function () {
5396 if (!this.activated)
5397 throw new Error('Outlet is not activated');
5398 return this.activated.instance;
5399 },
5400 enumerable: false,
5401 configurable: true
5402 });
5403 Object.defineProperty(RouterOutlet.prototype, "activatedRoute", {
5404 get: function () {
5405 if (!this.activated)
5406 throw new Error('Outlet is not activated');
5407 return this._activatedRoute;
5408 },
5409 enumerable: false,
5410 configurable: true
5411 });
5412 Object.defineProperty(RouterOutlet.prototype, "activatedRouteData", {
5413 get: function () {
5414 if (this._activatedRoute) {
5415 return this._activatedRoute.snapshot.data;
5416 }
5417 return {};
5418 },
5419 enumerable: false,
5420 configurable: true
5421 });
5422 /**
5423 * Called when the `RouteReuseStrategy` instructs to detach the subtree
5424 */
5425 RouterOutlet.prototype.detach = function () {
5426 if (!this.activated)
5427 throw new Error('Outlet is not activated');
5428 this.location.detach();
5429 var cmp = this.activated;
5430 this.activated = null;
5431 this._activatedRoute = null;
5432 return cmp;
5433 };
5434 /**
5435 * Called when the `RouteReuseStrategy` instructs to re-attach a previously detached subtree
5436 */
5437 RouterOutlet.prototype.attach = function (ref, activatedRoute) {
5438 this.activated = ref;
5439 this._activatedRoute = activatedRoute;
5440 this.location.insert(ref.hostView);
5441 };
5442 RouterOutlet.prototype.deactivate = function () {
5443 if (this.activated) {
5444 var c = this.component;
5445 this.activated.destroy();
5446 this.activated = null;
5447 this._activatedRoute = null;
5448 this.deactivateEvents.emit(c);
5449 }
5450 };
5451 RouterOutlet.prototype.activateWith = function (activatedRoute, resolver) {
5452 if (this.isActivated) {
5453 throw new Error('Cannot activate an already activated outlet');
5454 }
5455 this._activatedRoute = activatedRoute;
5456 var snapshot = activatedRoute._futureSnapshot;
5457 var component = snapshot.routeConfig.component;
5458 resolver = resolver || this.resolver;
5459 var factory = resolver.resolveComponentFactory(component);
5460 var childContexts = this.parentContexts.getOrCreateContext(this.name).children;
5461 var injector = new OutletInjector(activatedRoute, childContexts, this.location.injector);
5462 this.activated = this.location.createComponent(factory, this.location.length, injector);
5463 // Calling `markForCheck` to make sure we will run the change detection when the
5464 // `RouterOutlet` is inside a `ChangeDetectionStrategy.OnPush` component.
5465 this.changeDetector.markForCheck();
5466 this.activateEvents.emit(this.activated.instance);
5467 };
5468 RouterOutlet.decorators = [
5469 { type: core.Directive, args: [{ selector: 'router-outlet', exportAs: 'outlet' },] }
5470 ];
5471 RouterOutlet.ctorParameters = function () { return [
5472 { type: ChildrenOutletContexts },
5473 { type: core.ViewContainerRef },
5474 { type: core.ComponentFactoryResolver },
5475 { type: String, decorators: [{ type: core.Attribute, args: ['name',] }] },
5476 { type: core.ChangeDetectorRef }
5477 ]; };
5478 RouterOutlet.propDecorators = {
5479 activateEvents: [{ type: core.Output, args: ['activate',] }],
5480 deactivateEvents: [{ type: core.Output, args: ['deactivate',] }]
5481 };
5482 return RouterOutlet;
5483 }());
5484 var OutletInjector = /** @class */ (function () {
5485 function OutletInjector(route, childContexts, parent) {
5486 this.route = route;
5487 this.childContexts = childContexts;
5488 this.parent = parent;
5489 }
5490 OutletInjector.prototype.get = function (token, notFoundValue) {
5491 if (token === ActivatedRoute) {
5492 return this.route;
5493 }
5494 if (token === ChildrenOutletContexts) {
5495 return this.childContexts;
5496 }
5497 return this.parent.get(token, notFoundValue);
5498 };
5499 return OutletInjector;
5500 }());
5501
5502 /**
5503 * @license
5504 * Copyright Google LLC All Rights Reserved.
5505 *
5506 * Use of this source code is governed by an MIT-style license that can be
5507 * found in the LICENSE file at https://angular.io/license
5508 */
5509 /**
5510 * @description
5511 *
5512 * Provides a preloading strategy.
5513 *
5514 * @publicApi
5515 */
5516 var PreloadingStrategy = /** @class */ (function () {
5517 function PreloadingStrategy() {
5518 }
5519 return PreloadingStrategy;
5520 }());
5521 /**
5522 * @description
5523 *
5524 * Provides a preloading strategy that preloads all modules as quickly as possible.
5525 *
5526 * ```
5527 * RouteModule.forRoot(ROUTES, {preloadingStrategy: PreloadAllModules})
5528 * ```
5529 *
5530 * @publicApi
5531 */
5532 var PreloadAllModules = /** @class */ (function () {
5533 function PreloadAllModules() {
5534 }
5535 PreloadAllModules.prototype.preload = function (route, fn) {
5536 return fn().pipe(operators.catchError(function () { return rxjs.of(null); }));
5537 };
5538 return PreloadAllModules;
5539 }());
5540 /**
5541 * @description
5542 *
5543 * Provides a preloading strategy that does not preload any modules.
5544 *
5545 * This strategy is enabled by default.
5546 *
5547 * @publicApi
5548 */
5549 var NoPreloading = /** @class */ (function () {
5550 function NoPreloading() {
5551 }
5552 NoPreloading.prototype.preload = function (route, fn) {
5553 return rxjs.of(null);
5554 };
5555 return NoPreloading;
5556 }());
5557 /**
5558 * The preloader optimistically loads all router configurations to
5559 * make navigations into lazily-loaded sections of the application faster.
5560 *
5561 * The preloader runs in the background. When the router bootstraps, the preloader
5562 * starts listening to all navigation events. After every such event, the preloader
5563 * will check if any configurations can be loaded lazily.
5564 *
5565 * If a route is protected by `canLoad` guards, the preloaded will not load it.
5566 *
5567 * @publicApi
5568 */
5569 var RouterPreloader = /** @class */ (function () {
5570 function RouterPreloader(router, moduleLoader, compiler, injector, preloadingStrategy) {
5571 this.router = router;
5572 this.injector = injector;
5573 this.preloadingStrategy = preloadingStrategy;
5574 var onStartLoad = function (r) { return router.triggerEvent(new RouteConfigLoadStart(r)); };
5575 var onEndLoad = function (r) { return router.triggerEvent(new RouteConfigLoadEnd(r)); };
5576 this.loader = new RouterConfigLoader(moduleLoader, compiler, onStartLoad, onEndLoad);
5577 }
5578 RouterPreloader.prototype.setUpPreloading = function () {
5579 var _this = this;
5580 this.subscription =
5581 this.router.events
5582 .pipe(operators.filter(function (e) { return e instanceof NavigationEnd; }), operators.concatMap(function () { return _this.preload(); }))
5583 .subscribe(function () { });
5584 };
5585 RouterPreloader.prototype.preload = function () {
5586 var ngModule = this.injector.get(core.NgModuleRef);
5587 return this.processRoutes(ngModule, this.router.config);
5588 };
5589 // TODO(jasonaden): This class relies on code external to the class to call setUpPreloading. If
5590 // this hasn't been done, ngOnDestroy will fail as this.subscription will be undefined. This
5591 // should be refactored.
5592 RouterPreloader.prototype.ngOnDestroy = function () {
5593 this.subscription.unsubscribe();
5594 };
5595 RouterPreloader.prototype.processRoutes = function (ngModule, routes) {
5596 var e_1, _a;
5597 var res = [];
5598 try {
5599 for (var routes_1 = __values(routes), routes_1_1 = routes_1.next(); !routes_1_1.done; routes_1_1 = routes_1.next()) {
5600 var route = routes_1_1.value;
5601 // we already have the config loaded, just recurse
5602 if (route.loadChildren && !route.canLoad && route._loadedConfig) {
5603 var childConfig = route._loadedConfig;
5604 res.push(this.processRoutes(childConfig.module, childConfig.routes));
5605 // no config loaded, fetch the config
5606 }
5607 else if (route.loadChildren && !route.canLoad) {
5608 res.push(this.preloadConfig(ngModule, route));
5609 // recurse into children
5610 }
5611 else if (route.children) {
5612 res.push(this.processRoutes(ngModule, route.children));
5613 }
5614 }
5615 }
5616 catch (e_1_1) { e_1 = { error: e_1_1 }; }
5617 finally {
5618 try {
5619 if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
5620 }
5621 finally { if (e_1) throw e_1.error; }
5622 }
5623 return rxjs.from(res).pipe(operators.mergeAll(), operators.map(function (_) { return void 0; }));
5624 };
5625 RouterPreloader.prototype.preloadConfig = function (ngModule, route) {
5626 var _this = this;
5627 return this.preloadingStrategy.preload(route, function () {
5628 var loaded$ = _this.loader.load(ngModule.injector, route);
5629 return loaded$.pipe(operators.mergeMap(function (config) {
5630 route._loadedConfig = config;
5631 return _this.processRoutes(config.module, config.routes);
5632 }));
5633 });
5634 };
5635 RouterPreloader.decorators = [
5636 { type: core.Injectable }
5637 ];
5638 RouterPreloader.ctorParameters = function () { return [
5639 { type: Router },
5640 { type: core.NgModuleFactoryLoader },
5641 { type: core.Compiler },
5642 { type: core.Injector },
5643 { type: PreloadingStrategy }
5644 ]; };
5645 return RouterPreloader;
5646 }());
5647
5648 /**
5649 * @license
5650 * Copyright Google LLC All Rights Reserved.
5651 *
5652 * Use of this source code is governed by an MIT-style license that can be
5653 * found in the LICENSE file at https://angular.io/license
5654 */
5655 var RouterScroller = /** @class */ (function () {
5656 function RouterScroller(router,
5657 /** @docsNotRequired */ viewportScroller, options) {
5658 if (options === void 0) { options = {}; }
5659 this.router = router;
5660 this.viewportScroller = viewportScroller;
5661 this.options = options;
5662 this.lastId = 0;
5663 this.lastSource = 'imperative';
5664 this.restoredId = 0;
5665 this.store = {};
5666 // Default both options to 'disabled'
5667 options.scrollPositionRestoration = options.scrollPositionRestoration || 'disabled';
5668 options.anchorScrolling = options.anchorScrolling || 'disabled';
5669 }
5670 RouterScroller.prototype.init = function () {
5671 // we want to disable the automatic scrolling because having two places
5672 // responsible for scrolling results race conditions, especially given
5673 // that browser don't implement this behavior consistently
5674 if (this.options.scrollPositionRestoration !== 'disabled') {
5675 this.viewportScroller.setHistoryScrollRestoration('manual');
5676 }
5677 this.routerEventsSubscription = this.createScrollEvents();
5678 this.scrollEventsSubscription = this.consumeScrollEvents();
5679 };
5680 RouterScroller.prototype.createScrollEvents = function () {
5681 var _this = this;
5682 return this.router.events.subscribe(function (e) {
5683 if (e instanceof NavigationStart) {
5684 // store the scroll position of the current stable navigations.
5685 _this.store[_this.lastId] = _this.viewportScroller.getScrollPosition();
5686 _this.lastSource = e.navigationTrigger;
5687 _this.restoredId = e.restoredState ? e.restoredState.navigationId : 0;
5688 }
5689 else if (e instanceof NavigationEnd) {
5690 _this.lastId = e.id;
5691 _this.scheduleScrollEvent(e, _this.router.parseUrl(e.urlAfterRedirects).fragment);
5692 }
5693 });
5694 };
5695 RouterScroller.prototype.consumeScrollEvents = function () {
5696 var _this = this;
5697 return this.router.events.subscribe(function (e) {
5698 if (!(e instanceof Scroll))
5699 return;
5700 // a popstate event. The pop state event will always ignore anchor scrolling.
5701 if (e.position) {
5702 if (_this.options.scrollPositionRestoration === 'top') {
5703 _this.viewportScroller.scrollToPosition([0, 0]);
5704 }
5705 else if (_this.options.scrollPositionRestoration === 'enabled') {
5706 _this.viewportScroller.scrollToPosition(e.position);
5707 }
5708 // imperative navigation "forward"
5709 }
5710 else {
5711 if (e.anchor && _this.options.anchorScrolling === 'enabled') {
5712 _this.viewportScroller.scrollToAnchor(e.anchor);
5713 }
5714 else if (_this.options.scrollPositionRestoration !== 'disabled') {
5715 _this.viewportScroller.scrollToPosition([0, 0]);
5716 }
5717 }
5718 });
5719 };
5720 RouterScroller.prototype.scheduleScrollEvent = function (routerEvent, anchor) {
5721 this.router.triggerEvent(new Scroll(routerEvent, this.lastSource === 'popstate' ? this.store[this.restoredId] : null, anchor));
5722 };
5723 RouterScroller.prototype.ngOnDestroy = function () {
5724 if (this.routerEventsSubscription) {
5725 this.routerEventsSubscription.unsubscribe();
5726 }
5727 if (this.scrollEventsSubscription) {
5728 this.scrollEventsSubscription.unsubscribe();
5729 }
5730 };
5731 RouterScroller.decorators = [
5732 { type: core.Injectable }
5733 ];
5734 RouterScroller.ctorParameters = function () { return [
5735 { type: Router },
5736 { type: common.ViewportScroller },
5737 { type: undefined }
5738 ]; };
5739 return RouterScroller;
5740 }());
5741
5742 /**
5743 * @license
5744 * Copyright Google LLC All Rights Reserved.
5745 *
5746 * Use of this source code is governed by an MIT-style license that can be
5747 * found in the LICENSE file at https://angular.io/license
5748 */
5749 /**
5750 * The directives defined in the `RouterModule`.
5751 */
5752 var ROUTER_DIRECTIVES = [RouterOutlet, RouterLink, RouterLinkWithHref, RouterLinkActive, ɵEmptyOutletComponent];
5753 /**
5754 * A [DI token](guide/glossary/#di-token) for the router service.
5755 *
5756 * @publicApi
5757 */
5758 var ROUTER_CONFIGURATION = new core.InjectionToken('ROUTER_CONFIGURATION');
5759 /**
5760 * @docsNotRequired
5761 */
5762 var ROUTER_FORROOT_GUARD = new core.InjectionToken('ROUTER_FORROOT_GUARD');
5763 var ɵ0 = { enableTracing: false };
5764 var ROUTER_PROVIDERS = [
5765 common.Location,
5766 { provide: UrlSerializer, useClass: DefaultUrlSerializer },
5767 {
5768 provide: Router,
5769 useFactory: setupRouter,
5770 deps: [
5771 UrlSerializer, ChildrenOutletContexts, common.Location, core.Injector, core.NgModuleFactoryLoader, core.Compiler,
5772 ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new core.Optional()],
5773 [RouteReuseStrategy, new core.Optional()]
5774 ]
5775 },
5776 ChildrenOutletContexts,
5777 { provide: ActivatedRoute, useFactory: rootRoute, deps: [Router] },
5778 { provide: core.NgModuleFactoryLoader, useClass: core.SystemJsNgModuleLoader },
5779 RouterPreloader,
5780 NoPreloading,
5781 PreloadAllModules,
5782 { provide: ROUTER_CONFIGURATION, useValue: ɵ0 },
5783 ];
5784 function routerNgProbeToken() {
5785 return new core.NgProbeToken('Router', Router);
5786 }
5787 /**
5788 * @usageNotes
5789 *
5790 * RouterModule can be imported multiple times: once per lazily-loaded bundle.
5791 * Since the router deals with a global shared resource--location, we cannot have
5792 * more than one router service active.
5793 *
5794 * That is why there are two ways to create the module: `RouterModule.forRoot` and
5795 * `RouterModule.forChild`.
5796 *
5797 * * `forRoot` creates a module that contains all the directives, the given routes, and the router
5798 * service itself.
5799 * * `forChild` creates a module that contains all the directives and the given routes, but does not
5800 * include the router service.
5801 *
5802 * When registered at the root, the module should be used as follows
5803 *
5804 * ```
5805 * @NgModule({
5806 * imports: [RouterModule.forRoot(ROUTES)]
5807 * })
5808 * class MyNgModule {}
5809 * ```
5810 *
5811 * For submodules and lazy loaded submodules the module should be used as follows:
5812 *
5813 * ```
5814 * @NgModule({
5815 * imports: [RouterModule.forChild(ROUTES)]
5816 * })
5817 * class MyNgModule {}
5818 * ```
5819 *
5820 * @description
5821 *
5822 * Adds router directives and providers.
5823 *
5824 * Managing state transitions is one of the hardest parts of building applications. This is
5825 * especially true on the web, where you also need to ensure that the state is reflected in the URL.
5826 * In addition, we often want to split applications into multiple bundles and load them on demand.
5827 * Doing this transparently is not trivial.
5828 *
5829 * The Angular router service solves these problems. Using the router, you can declaratively specify
5830 * application states, manage state transitions while taking care of the URL, and load bundles on
5831 * demand.
5832 *
5833 * @see [Routing and Navigation](guide/router.html) for an
5834 * overview of how the router service should be used.
5835 *
5836 * @publicApi
5837 */
5838 var RouterModule = /** @class */ (function () {
5839 // Note: We are injecting the Router so it gets created eagerly...
5840 function RouterModule(guard, router) {
5841 }
5842 /**
5843 * Creates and configures a module with all the router providers and directives.
5844 * Optionally sets up an application listener to perform an initial navigation.
5845 *
5846 * @param routes An array of `Route` objects that define the navigation paths for the application.
5847 * @param config An `ExtraOptions` configuration object that controls how navigation is performed.
5848 * @return The new router module.
5849 */
5850 RouterModule.forRoot = function (routes, config) {
5851 return {
5852 ngModule: RouterModule,
5853 providers: [
5854 ROUTER_PROVIDERS,
5855 provideRoutes(routes),
5856 {
5857 provide: ROUTER_FORROOT_GUARD,
5858 useFactory: provideForRootGuard,
5859 deps: [[Router, new core.Optional(), new core.SkipSelf()]]
5860 },
5861 { provide: ROUTER_CONFIGURATION, useValue: config ? config : {} },
5862 {
5863 provide: common.LocationStrategy,
5864 useFactory: provideLocationStrategy,
5865 deps: [common.PlatformLocation, [new core.Inject(common.APP_BASE_HREF), new core.Optional()], ROUTER_CONFIGURATION]
5866 },
5867 {
5868 provide: RouterScroller,
5869 useFactory: createRouterScroller,
5870 deps: [Router, common.ViewportScroller, ROUTER_CONFIGURATION]
5871 },
5872 {
5873 provide: PreloadingStrategy,
5874 useExisting: config && config.preloadingStrategy ? config.preloadingStrategy :
5875 NoPreloading
5876 },
5877 { provide: core.NgProbeToken, multi: true, useFactory: routerNgProbeToken },
5878 provideRouterInitializer(),
5879 ],
5880 };
5881 };
5882 /**
5883 * Creates a module with all the router directives and a provider registering routes.
5884 */
5885 RouterModule.forChild = function (routes) {
5886 return { ngModule: RouterModule, providers: [provideRoutes(routes)] };
5887 };
5888 RouterModule.decorators = [
5889 { type: core.NgModule, args: [{
5890 declarations: ROUTER_DIRECTIVES,
5891 exports: ROUTER_DIRECTIVES,
5892 entryComponents: [ɵEmptyOutletComponent]
5893 },] }
5894 ];
5895 RouterModule.ctorParameters = function () { return [
5896 { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [ROUTER_FORROOT_GUARD,] }] },
5897 { type: Router, decorators: [{ type: core.Optional }] }
5898 ]; };
5899 return RouterModule;
5900 }());
5901 function createRouterScroller(router, viewportScroller, config) {
5902 if (config.scrollOffset) {
5903 viewportScroller.setOffset(config.scrollOffset);
5904 }
5905 return new RouterScroller(router, viewportScroller, config);
5906 }
5907 function provideLocationStrategy(platformLocationStrategy, baseHref, options) {
5908 if (options === void 0) { options = {}; }
5909 return options.useHash ? new common.HashLocationStrategy(platformLocationStrategy, baseHref) :
5910 new common.PathLocationStrategy(platformLocationStrategy, baseHref);
5911 }
5912 function provideForRootGuard(router) {
5913 if (router) {
5914 throw new Error("RouterModule.forRoot() called twice. Lazy loaded modules should use RouterModule.forChild() instead.");
5915 }
5916 return 'guarded';
5917 }
5918 /**
5919 * Registers a [DI provider](guide/glossary#provider) for a set of routes.
5920 * @param routes The route configuration to provide.
5921 *
5922 * @usageNotes
5923 *
5924 * ```
5925 * @NgModule({
5926 * imports: [RouterModule.forChild(ROUTES)],
5927 * providers: [provideRoutes(EXTRA_ROUTES)]
5928 * })
5929 * class MyNgModule {}
5930 * ```
5931 *
5932 * @publicApi
5933 */
5934 function provideRoutes(routes) {
5935 return [
5936 { provide: core.ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes },
5937 { provide: ROUTES, multi: true, useValue: routes },
5938 ];
5939 }
5940 function setupRouter(urlSerializer, contexts, location, injector, loader, compiler, config, opts, urlHandlingStrategy, routeReuseStrategy) {
5941 if (opts === void 0) { opts = {}; }
5942 var router = new Router(null, urlSerializer, contexts, location, injector, loader, compiler, flatten(config));
5943 if (urlHandlingStrategy) {
5944 router.urlHandlingStrategy = urlHandlingStrategy;
5945 }
5946 if (routeReuseStrategy) {
5947 router.routeReuseStrategy = routeReuseStrategy;
5948 }
5949 if (opts.errorHandler) {
5950 router.errorHandler = opts.errorHandler;
5951 }
5952 if (opts.malformedUriErrorHandler) {
5953 router.malformedUriErrorHandler = opts.malformedUriErrorHandler;
5954 }
5955 if (opts.enableTracing) {
5956 var dom_1 = common.ɵgetDOM();
5957 router.events.subscribe(function (e) {
5958 dom_1.logGroup("Router Event: " + e.constructor.name);
5959 dom_1.log(e.toString());
5960 dom_1.log(e);
5961 dom_1.logGroupEnd();
5962 });
5963 }
5964 if (opts.onSameUrlNavigation) {
5965 router.onSameUrlNavigation = opts.onSameUrlNavigation;
5966 }
5967 if (opts.paramsInheritanceStrategy) {
5968 router.paramsInheritanceStrategy = opts.paramsInheritanceStrategy;
5969 }
5970 if (opts.urlUpdateStrategy) {
5971 router.urlUpdateStrategy = opts.urlUpdateStrategy;
5972 }
5973 if (opts.relativeLinkResolution) {
5974 router.relativeLinkResolution = opts.relativeLinkResolution;
5975 }
5976 return router;
5977 }
5978 function rootRoute(router) {
5979 return router.routerState.root;
5980 }
5981 /**
5982 * Router initialization requires two steps:
5983 *
5984 * First, we start the navigation in a `APP_INITIALIZER` to block the bootstrap if
5985 * a resolver or a guard executes asynchronously.
5986 *
5987 * Next, we actually run activation in a `BOOTSTRAP_LISTENER`, using the
5988 * `afterPreactivation` hook provided by the router.
5989 * The router navigation starts, reaches the point when preactivation is done, and then
5990 * pauses. It waits for the hook to be resolved. We then resolve it only in a bootstrap listener.
5991 */
5992 var RouterInitializer = /** @class */ (function () {
5993 function RouterInitializer(injector) {
5994 this.injector = injector;
5995 this.initNavigation = false;
5996 this.resultOfPreactivationDone = new rxjs.Subject();
5997 }
5998 RouterInitializer.prototype.appInitializer = function () {
5999 var _this = this;
6000 var p = this.injector.get(common.LOCATION_INITIALIZED, Promise.resolve(null));
6001 return p.then(function () {
6002 var resolve = null;
6003 var res = new Promise(function (r) { return resolve = r; });
6004 var router = _this.injector.get(Router);
6005 var opts = _this.injector.get(ROUTER_CONFIGURATION);
6006 if (_this.isLegacyDisabled(opts) || _this.isLegacyEnabled(opts)) {
6007 resolve(true);
6008 }
6009 else if (opts.initialNavigation === 'disabled') {
6010 router.setUpLocationChangeListener();
6011 resolve(true);
6012 }
6013 else if (opts.initialNavigation === 'enabled') {
6014 router.hooks.afterPreactivation = function () {
6015 // only the initial navigation should be delayed
6016 if (!_this.initNavigation) {
6017 _this.initNavigation = true;
6018 resolve(true);
6019 return _this.resultOfPreactivationDone;
6020 // subsequent navigations should not be delayed
6021 }
6022 else {
6023 return rxjs.of(null);
6024 }
6025 };
6026 router.initialNavigation();
6027 }
6028 else {
6029 throw new Error("Invalid initialNavigation options: '" + opts.initialNavigation + "'");
6030 }
6031 return res;
6032 });
6033 };
6034 RouterInitializer.prototype.bootstrapListener = function (bootstrappedComponentRef) {
6035 var opts = this.injector.get(ROUTER_CONFIGURATION);
6036 var preloader = this.injector.get(RouterPreloader);
6037 var routerScroller = this.injector.get(RouterScroller);
6038 var router = this.injector.get(Router);
6039 var ref = this.injector.get(core.ApplicationRef);
6040 if (bootstrappedComponentRef !== ref.components[0]) {
6041 return;
6042 }
6043 if (this.isLegacyEnabled(opts)) {
6044 router.initialNavigation();
6045 }
6046 else if (this.isLegacyDisabled(opts)) {
6047 router.setUpLocationChangeListener();
6048 }
6049 preloader.setUpPreloading();
6050 routerScroller.init();
6051 router.resetRootComponentType(ref.componentTypes[0]);
6052 this.resultOfPreactivationDone.next(null);
6053 this.resultOfPreactivationDone.complete();
6054 };
6055 RouterInitializer.prototype.isLegacyEnabled = function (opts) {
6056 return opts.initialNavigation === 'legacy_enabled' || opts.initialNavigation === true ||
6057 opts.initialNavigation === undefined;
6058 };
6059 RouterInitializer.prototype.isLegacyDisabled = function (opts) {
6060 return opts.initialNavigation === 'legacy_disabled' || opts.initialNavigation === false;
6061 };
6062 RouterInitializer.decorators = [
6063 { type: core.Injectable }
6064 ];
6065 RouterInitializer.ctorParameters = function () { return [
6066 { type: core.Injector }
6067 ]; };
6068 return RouterInitializer;
6069 }());
6070 function getAppInitializer(r) {
6071 return r.appInitializer.bind(r);
6072 }
6073 function getBootstrapListener(r) {
6074 return r.bootstrapListener.bind(r);
6075 }
6076 /**
6077 * A [DI token](guide/glossary/#di-token) for the router initializer that
6078 * is called after the app is bootstrapped.
6079 *
6080 * @publicApi
6081 */
6082 var ROUTER_INITIALIZER = new core.InjectionToken('Router Initializer');
6083 function provideRouterInitializer() {
6084 return [
6085 RouterInitializer,
6086 {
6087 provide: core.APP_INITIALIZER,
6088 multi: true,
6089 useFactory: getAppInitializer,
6090 deps: [RouterInitializer]
6091 },
6092 { provide: ROUTER_INITIALIZER, useFactory: getBootstrapListener, deps: [RouterInitializer] },
6093 { provide: core.APP_BOOTSTRAP_LISTENER, multi: true, useExisting: ROUTER_INITIALIZER },
6094 ];
6095 }
6096
6097 /**
6098 * @license
6099 * Copyright Google LLC All Rights Reserved.
6100 *
6101 * Use of this source code is governed by an MIT-style license that can be
6102 * found in the LICENSE file at https://angular.io/license
6103 */
6104 /**
6105 * @publicApi
6106 */
6107 var VERSION = new core.Version('10.0.3');
6108
6109 /**
6110 * @license
6111 * Copyright Google LLC All Rights Reserved.
6112 *
6113 * Use of this source code is governed by an MIT-style license that can be
6114 * found in the LICENSE file at https://angular.io/license
6115 */
6116
6117 /**
6118 * @license
6119 * Copyright Google LLC All Rights Reserved.
6120 *
6121 * Use of this source code is governed by an MIT-style license that can be
6122 * found in the LICENSE file at https://angular.io/license
6123 */
6124
6125 /**
6126 * @license
6127 * Copyright Google LLC All Rights Reserved.
6128 *
6129 * Use of this source code is governed by an MIT-style license that can be
6130 * found in the LICENSE file at https://angular.io/license
6131 */
6132 // This file only reexports content of the `src` folder. Keep it that way.
6133
6134 /**
6135 * @license
6136 * Copyright Google LLC All Rights Reserved.
6137 *
6138 * Use of this source code is governed by an MIT-style license that can be
6139 * found in the LICENSE file at https://angular.io/license
6140 */
6141
6142 /**
6143 * Generated bundle index. Do not edit.
6144 */
6145
6146 exports.ActivatedRoute = ActivatedRoute;
6147 exports.ActivatedRouteSnapshot = ActivatedRouteSnapshot;
6148 exports.ActivationEnd = ActivationEnd;
6149 exports.ActivationStart = ActivationStart;
6150 exports.ChildActivationEnd = ChildActivationEnd;
6151 exports.ChildActivationStart = ChildActivationStart;
6152 exports.ChildrenOutletContexts = ChildrenOutletContexts;
6153 exports.DefaultUrlSerializer = DefaultUrlSerializer;
6154 exports.GuardsCheckEnd = GuardsCheckEnd;
6155 exports.GuardsCheckStart = GuardsCheckStart;
6156 exports.NavigationCancel = NavigationCancel;
6157 exports.NavigationEnd = NavigationEnd;
6158 exports.NavigationError = NavigationError;
6159 exports.NavigationStart = NavigationStart;
6160 exports.NoPreloading = NoPreloading;
6161 exports.OutletContext = OutletContext;
6162 exports.PRIMARY_OUTLET = PRIMARY_OUTLET;
6163 exports.PreloadAllModules = PreloadAllModules;
6164 exports.PreloadingStrategy = PreloadingStrategy;
6165 exports.ROUTER_CONFIGURATION = ROUTER_CONFIGURATION;
6166 exports.ROUTER_INITIALIZER = ROUTER_INITIALIZER;
6167 exports.ROUTES = ROUTES;
6168 exports.ResolveEnd = ResolveEnd;
6169 exports.ResolveStart = ResolveStart;
6170 exports.RouteConfigLoadEnd = RouteConfigLoadEnd;
6171 exports.RouteConfigLoadStart = RouteConfigLoadStart;
6172 exports.RouteReuseStrategy = RouteReuseStrategy;
6173 exports.Router = Router;
6174 exports.RouterEvent = RouterEvent;
6175 exports.RouterLink = RouterLink;
6176 exports.RouterLinkActive = RouterLinkActive;
6177 exports.RouterLinkWithHref = RouterLinkWithHref;
6178 exports.RouterModule = RouterModule;
6179 exports.RouterOutlet = RouterOutlet;
6180 exports.RouterPreloader = RouterPreloader;
6181 exports.RouterState = RouterState;
6182 exports.RouterStateSnapshot = RouterStateSnapshot;
6183 exports.RoutesRecognized = RoutesRecognized;
6184 exports.Scroll = Scroll;
6185 exports.UrlHandlingStrategy = UrlHandlingStrategy;
6186 exports.UrlSegment = UrlSegment;
6187 exports.UrlSegmentGroup = UrlSegmentGroup;
6188 exports.UrlSerializer = UrlSerializer;
6189 exports.UrlTree = UrlTree;
6190 exports.VERSION = VERSION;
6191 exports.convertToParamMap = convertToParamMap;
6192 exports.provideRoutes = provideRoutes;
6193 exports.ɵEmptyOutletComponent = ɵEmptyOutletComponent;
6194 exports.ɵROUTER_PROVIDERS = ROUTER_PROVIDERS;
6195 exports.ɵangular_packages_router_router_a = ROUTER_FORROOT_GUARD;
6196 exports.ɵangular_packages_router_router_b = routerNgProbeToken;
6197 exports.ɵangular_packages_router_router_c = createRouterScroller;
6198 exports.ɵangular_packages_router_router_d = provideLocationStrategy;
6199 exports.ɵangular_packages_router_router_e = provideForRootGuard;
6200 exports.ɵangular_packages_router_router_f = setupRouter;
6201 exports.ɵangular_packages_router_router_g = rootRoute;
6202 exports.ɵangular_packages_router_router_h = RouterInitializer;
6203 exports.ɵangular_packages_router_router_i = getAppInitializer;
6204 exports.ɵangular_packages_router_router_j = getBootstrapListener;
6205 exports.ɵangular_packages_router_router_k = provideRouterInitializer;
6206 exports.ɵangular_packages_router_router_l = ɵEmptyOutletComponent;
6207 exports.ɵangular_packages_router_router_m = Tree;
6208 exports.ɵangular_packages_router_router_n = TreeNode;
6209 exports.ɵangular_packages_router_router_o = RouterScroller;
6210 exports.ɵflatten = flatten;
6211
6212 Object.defineProperty(exports, '__esModule', { value: true });
6213
6214})));
6215//# sourceMappingURL=router.umd.js.map