UNPKG

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