/** * @license Angular v6.0.9 * (c) 2010-2018 Google, Inc. https://angular.io/ * License: MIT */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/common'), require('@angular/platform-browser')) : typeof define === 'function' && define.amd ? define('@angular/router', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/common', '@angular/platform-browser'], factory) : (factory((global.ng = global.ng || {}, global.ng.router = {}),global.ng.core,global.rxjs,global.rxjs.operators,global.ng.common,global.ng.platformBrowser)); }(this, (function (exports,core,rxjs,operators,common,platformBrowser) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @description * * Base for events the Router goes through, as opposed to events tied to a specific * Route. `RouterEvent`s will only be fired one time for any given navigation. * * Example: * * ``` * class MyService { * constructor(public router: Router, logger: Logger) { * router.events.filter(e => e instanceof RouterEvent).subscribe(e => { * logger.log(e.id, e.url); * }); * } * } * ``` * * @experimental */ var RouterEvent = /** @class */ (function () { function RouterEvent( /** @docsNotRequired */ id, /** @docsNotRequired */ url) { this.id = id; this.url = url; } return RouterEvent; }()); /** * @description * * Represents an event triggered when a navigation starts. * * */ var NavigationStart = /** @class */ (function (_super) { __extends(NavigationStart, _super); function NavigationStart( /** @docsNotRequired */ id, /** @docsNotRequired */ url, /** @docsNotRequired */ navigationTrigger, /** @docsNotRequired */ restoredState) { /** @docsNotRequired */ if (navigationTrigger === void 0) { navigationTrigger = 'imperative'; } /** @docsNotRequired */ if (restoredState === void 0) { restoredState = null; } var _this = _super.call(this, id, url) || this; _this.navigationTrigger = navigationTrigger; _this.restoredState = restoredState; return _this; } /** @docsNotRequired */ NavigationStart.prototype.toString = function () { return "NavigationStart(id: " + this.id + ", url: '" + this.url + "')"; }; return NavigationStart; }(RouterEvent)); /** * @description * * Represents an event triggered when a navigation ends successfully. * * */ var NavigationEnd = /** @class */ (function (_super) { __extends(NavigationEnd, _super); function NavigationEnd( /** @docsNotRequired */ id, /** @docsNotRequired */ url, /** @docsNotRequired */ urlAfterRedirects) { var _this = _super.call(this, id, url) || this; _this.urlAfterRedirects = urlAfterRedirects; return _this; } /** @docsNotRequired */ NavigationEnd.prototype.toString = function () { return "NavigationEnd(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "')"; }; return NavigationEnd; }(RouterEvent)); /** * @description * * Represents an event triggered when a navigation is canceled. * * */ var NavigationCancel = /** @class */ (function (_super) { __extends(NavigationCancel, _super); function NavigationCancel( /** @docsNotRequired */ id, /** @docsNotRequired */ url, /** @docsNotRequired */ reason) { var _this = _super.call(this, id, url) || this; _this.reason = reason; return _this; } /** @docsNotRequired */ NavigationCancel.prototype.toString = function () { return "NavigationCancel(id: " + this.id + ", url: '" + this.url + "')"; }; return NavigationCancel; }(RouterEvent)); /** * @description * * Represents an event triggered when a navigation fails due to an unexpected error. * * */ var NavigationError = /** @class */ (function (_super) { __extends(NavigationError, _super); function NavigationError( /** @docsNotRequired */ id, /** @docsNotRequired */ url, /** @docsNotRequired */ error) { var _this = _super.call(this, id, url) || this; _this.error = error; return _this; } /** @docsNotRequired */ NavigationError.prototype.toString = function () { return "NavigationError(id: " + this.id + ", url: '" + this.url + "', error: " + this.error + ")"; }; return NavigationError; }(RouterEvent)); /** * @description * * Represents an event triggered when routes are recognized. * * */ var RoutesRecognized = /** @class */ (function (_super) { __extends(RoutesRecognized, _super); function RoutesRecognized( /** @docsNotRequired */ id, /** @docsNotRequired */ url, /** @docsNotRequired */ urlAfterRedirects, /** @docsNotRequired */ state) { var _this = _super.call(this, id, url) || this; _this.urlAfterRedirects = urlAfterRedirects; _this.state = state; return _this; } /** @docsNotRequired */ RoutesRecognized.prototype.toString = function () { return "RoutesRecognized(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")"; }; return RoutesRecognized; }(RouterEvent)); /** * @description * * Represents the start of the Guard phase of routing. * * @experimental */ var GuardsCheckStart = /** @class */ (function (_super) { __extends(GuardsCheckStart, _super); function GuardsCheckStart( /** @docsNotRequired */ id, /** @docsNotRequired */ url, /** @docsNotRequired */ urlAfterRedirects, /** @docsNotRequired */ state) { var _this = _super.call(this, id, url) || this; _this.urlAfterRedirects = urlAfterRedirects; _this.state = state; return _this; } GuardsCheckStart.prototype.toString = function () { return "GuardsCheckStart(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")"; }; return GuardsCheckStart; }(RouterEvent)); /** * @description * * Represents the end of the Guard phase of routing. * * @experimental */ var GuardsCheckEnd = /** @class */ (function (_super) { __extends(GuardsCheckEnd, _super); function GuardsCheckEnd( /** @docsNotRequired */ id, /** @docsNotRequired */ url, /** @docsNotRequired */ urlAfterRedirects, /** @docsNotRequired */ state, /** @docsNotRequired */ shouldActivate) { var _this = _super.call(this, id, url) || this; _this.urlAfterRedirects = urlAfterRedirects; _this.state = state; _this.shouldActivate = shouldActivate; return _this; } GuardsCheckEnd.prototype.toString = function () { return "GuardsCheckEnd(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ", shouldActivate: " + this.shouldActivate + ")"; }; return GuardsCheckEnd; }(RouterEvent)); /** * @description * * Represents the start of the Resolve phase of routing. The timing of this * event may change, thus it's experimental. In the current iteration it will run * in the "resolve" phase whether there's things to resolve or not. In the future this * behavior may change to only run when there are things to be resolved. * * @experimental */ var ResolveStart = /** @class */ (function (_super) { __extends(ResolveStart, _super); function ResolveStart( /** @docsNotRequired */ id, /** @docsNotRequired */ url, /** @docsNotRequired */ urlAfterRedirects, /** @docsNotRequired */ state) { var _this = _super.call(this, id, url) || this; _this.urlAfterRedirects = urlAfterRedirects; _this.state = state; return _this; } ResolveStart.prototype.toString = function () { return "ResolveStart(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")"; }; return ResolveStart; }(RouterEvent)); /** * @description * * Represents the end of the Resolve phase of routing. See note on * `ResolveStart` for use of this experimental API. * * @experimental */ var ResolveEnd = /** @class */ (function (_super) { __extends(ResolveEnd, _super); function ResolveEnd( /** @docsNotRequired */ id, /** @docsNotRequired */ url, /** @docsNotRequired */ urlAfterRedirects, /** @docsNotRequired */ state) { var _this = _super.call(this, id, url) || this; _this.urlAfterRedirects = urlAfterRedirects; _this.state = state; return _this; } ResolveEnd.prototype.toString = function () { return "ResolveEnd(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")"; }; return ResolveEnd; }(RouterEvent)); /** * @description * * Represents an event triggered before lazy loading a route config. * * @experimental */ var RouteConfigLoadStart = /** @class */ (function () { function RouteConfigLoadStart( /** @docsNotRequired */ route) { this.route = route; } RouteConfigLoadStart.prototype.toString = function () { return "RouteConfigLoadStart(path: " + this.route.path + ")"; }; return RouteConfigLoadStart; }()); /** * @description * * Represents an event triggered when a route has been lazy loaded. * * @experimental */ var RouteConfigLoadEnd = /** @class */ (function () { function RouteConfigLoadEnd( /** @docsNotRequired */ route) { this.route = route; } RouteConfigLoadEnd.prototype.toString = function () { return "RouteConfigLoadEnd(path: " + this.route.path + ")"; }; return RouteConfigLoadEnd; }()); /** * @description * * Represents the start of end of the Resolve phase of routing. See note on * `ChildActivationEnd` for use of this experimental API. * * @experimental */ var ChildActivationStart = /** @class */ (function () { function ChildActivationStart( /** @docsNotRequired */ snapshot) { this.snapshot = snapshot; } ChildActivationStart.prototype.toString = function () { var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || ''; return "ChildActivationStart(path: '" + path + "')"; }; return ChildActivationStart; }()); /** * @description * * Represents the start of end of the Resolve phase of routing. See note on * `ChildActivationStart` for use of this experimental API. * * @experimental */ var ChildActivationEnd = /** @class */ (function () { function ChildActivationEnd( /** @docsNotRequired */ snapshot) { this.snapshot = snapshot; } ChildActivationEnd.prototype.toString = function () { var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || ''; return "ChildActivationEnd(path: '" + path + "')"; }; return ChildActivationEnd; }()); /** * @description * * Represents the start of end of the Resolve phase of routing. See note on * `ActivationEnd` for use of this experimental API. * * @experimental */ var ActivationStart = /** @class */ (function () { function ActivationStart( /** @docsNotRequired */ snapshot) { this.snapshot = snapshot; } ActivationStart.prototype.toString = function () { var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || ''; return "ActivationStart(path: '" + path + "')"; }; return ActivationStart; }()); /** * @description * * Represents the start of end of the Resolve phase of routing. See note on * `ActivationStart` for use of this experimental API. * * @experimental */ var ActivationEnd = /** @class */ (function () { function ActivationEnd( /** @docsNotRequired */ snapshot) { this.snapshot = snapshot; } ActivationEnd.prototype.toString = function () { var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || ''; return "ActivationEnd(path: '" + path + "')"; }; return ActivationEnd; }()); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * This component is used internally within the router to be a placeholder when an empty * router-outlet is needed. For example, with a config such as: * * `{path: 'parent', outlet: 'nav', children: [...]}` * * In order to render, there needs to be a component on this config, which will default * to this `EmptyOutletComponent`. */ var EmptyOutletComponent = /** @class */ (function () { function EmptyOutletComponent() { } EmptyOutletComponent.decorators = [ { type: core.Component, args: [{ template: "" }] } ]; return EmptyOutletComponent; }()); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @description * * Name of the primary outlet. * * */ var PRIMARY_OUTLET = 'primary'; var ParamsAsMap = /** @class */ (function () { function ParamsAsMap(params) { this.params = params || {}; } ParamsAsMap.prototype.has = function (name) { return this.params.hasOwnProperty(name); }; ParamsAsMap.prototype.get = function (name) { if (this.has(name)) { var v = this.params[name]; return Array.isArray(v) ? v[0] : v; } return null; }; ParamsAsMap.prototype.getAll = function (name) { if (this.has(name)) { var v = this.params[name]; return Array.isArray(v) ? v : [v]; } return []; }; Object.defineProperty(ParamsAsMap.prototype, "keys", { get: function () { return Object.keys(this.params); }, enumerable: true, configurable: true }); return ParamsAsMap; }()); /** * Convert a `Params` instance to a `ParamMap`. * * */ function convertToParamMap(params) { return new ParamsAsMap(params); } var NAVIGATION_CANCELING_ERROR = 'ngNavigationCancelingError'; function navigationCancelingError(message) { var error = Error('NavigationCancelingError: ' + message); error[NAVIGATION_CANCELING_ERROR] = true; return error; } function isNavigationCancelingError(error) { return error && error[NAVIGATION_CANCELING_ERROR]; } // Matches the route configuration (`route`) against the actual URL (`segments`). function defaultUrlMatcher(segments, segmentGroup, route) { var parts = route.path.split('/'); if (parts.length > segments.length) { // The actual URL is shorter than the config, no match return null; } if (route.pathMatch === 'full' && (segmentGroup.hasChildren() || parts.length < segments.length)) { // The config is longer than the actual URL but we are looking for a full match, return null return null; } var posParams = {}; // Check each config part against the actual URL for (var index = 0; index < parts.length; index++) { var part = parts[index]; var segment = segments[index]; var isParameter = part.startsWith(':'); if (isParameter) { posParams[part.substring(1)] = segment; } else if (part !== segment.path) { // The actual URL part does not match the config, no match return null; } } return { consumed: segments.slice(0, parts.length), posParams: posParams }; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var LoadedRouterConfig = /** @class */ (function () { function LoadedRouterConfig(routes, module) { this.routes = routes; this.module = module; } return LoadedRouterConfig; }()); function validateConfig(config, parentPath) { if (parentPath === void 0) { parentPath = ''; } // forEach doesn't iterate undefined values for (var i = 0; i < config.length; i++) { var route = config[i]; var fullPath = getFullPath(parentPath, route); validateNode(route, fullPath); } } function validateNode(route, fullPath) { if (!route) { 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 "); } if (Array.isArray(route)) { throw new Error("Invalid configuration of route '" + fullPath + "': Array cannot be specified"); } if (!route.component && !route.children && !route.loadChildren && (route.outlet && route.outlet !== PRIMARY_OUTLET)) { throw new Error("Invalid configuration of route '" + fullPath + "': a componentless route without children or loadChildren cannot have a named outlet set"); } if (route.redirectTo && route.children) { throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and children cannot be used together"); } if (route.redirectTo && route.loadChildren) { throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and loadChildren cannot be used together"); } if (route.children && route.loadChildren) { throw new Error("Invalid configuration of route '" + fullPath + "': children and loadChildren cannot be used together"); } if (route.redirectTo && route.component) { throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and component cannot be used together"); } if (route.path && route.matcher) { throw new Error("Invalid configuration of route '" + fullPath + "': path and matcher cannot be used together"); } if (route.redirectTo === void 0 && !route.component && !route.children && !route.loadChildren) { throw new Error("Invalid configuration of route '" + fullPath + "'. One of the following must be provided: component, redirectTo, children or loadChildren"); } if (route.path === void 0 && route.matcher === void 0) { throw new Error("Invalid configuration of route '" + fullPath + "': routes must have either a path or a matcher specified"); } if (typeof route.path === 'string' && route.path.charAt(0) === '/') { throw new Error("Invalid configuration of route '" + fullPath + "': path cannot start with a slash"); } if (route.path === '' && route.redirectTo !== void 0 && route.pathMatch === void 0) { var exp = "The default value of 'pathMatch' is 'prefix', but often the intent is to use 'full'."; throw new Error("Invalid configuration of route '{path: \"" + fullPath + "\", redirectTo: \"" + route.redirectTo + "\"}': please provide 'pathMatch'. " + exp); } if (route.pathMatch !== void 0 && route.pathMatch !== 'full' && route.pathMatch !== 'prefix') { throw new Error("Invalid configuration of route '" + fullPath + "': pathMatch can only be set to 'prefix' or 'full'"); } if (route.children) { validateConfig(route.children, fullPath); } } function getFullPath(parentPath, currentRoute) { if (!currentRoute) { return parentPath; } if (!parentPath && !currentRoute.path) { return ''; } else if (parentPath && !currentRoute.path) { return parentPath + "/"; } else if (!parentPath && currentRoute.path) { return currentRoute.path; } else { return parentPath + "/" + currentRoute.path; } } /** * Makes a copy of the config and adds any default required properties. */ function standardizeConfig(r) { var children = r.children && r.children.map(standardizeConfig); var c = children ? __assign({}, r, { children: children }) : __assign({}, r); if (!c.component && (children || c.loadChildren) && (c.outlet && c.outlet !== PRIMARY_OUTLET)) { c.component = EmptyOutletComponent; } return c; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function shallowEqualArrays(a, b) { if (a.length !== b.length) return false; for (var i = 0; i < a.length; ++i) { if (!shallowEqual(a[i], b[i])) return false; } return true; } function shallowEqual(a, b) { var k1 = Object.keys(a); var k2 = Object.keys(b); if (k1.length != k2.length) { return false; } var key; for (var i = 0; i < k1.length; i++) { key = k1[i]; if (a[key] !== b[key]) { return false; } } return true; } /** * Flattens single-level nested arrays. */ function flatten(arr) { return Array.prototype.concat.apply([], arr); } /** * Return the last element of an array. */ function last(a) { return a.length > 0 ? a[a.length - 1] : null; } function forEach(map, callback) { for (var prop in map) { if (map.hasOwnProperty(prop)) { callback(map[prop], prop); } } } function waitForMap(obj, fn) { if (Object.keys(obj).length === 0) { return rxjs.of({}); } var waitHead = []; var waitTail = []; var res = {}; forEach(obj, function (a, k) { var mapped = fn(k, a).pipe(operators.map(function (r) { return res[k] = r; })); if (k === PRIMARY_OUTLET) { waitHead.push(mapped); } else { waitTail.push(mapped); } }); // Closure compiler has problem with using spread operator here. So just using Array.concat. return rxjs.of.apply(null, waitHead.concat(waitTail)).pipe(operators.concatAll(), operators.last(), operators.map(function () { return res; })); } /** * ANDs Observables by merging all input observables, reducing to an Observable verifying all * input Observables return `true`. */ function andObservables(observables) { return observables.pipe(operators.mergeAll(), operators.every(function (result) { return result === true; })); } function wrapIntoObservable(value) { if (core.ɵisObservable(value)) { return value; } if (core.ɵisPromise(value)) { // Use `Promise.resolve()` to wrap promise-like instances. // Required ie when a Resolver returns a AngularJS `$q` promise to correctly trigger the // change detection. return rxjs.from(Promise.resolve(value)); } return rxjs.of(value); } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function createEmptyUrlTree() { return new UrlTree(new UrlSegmentGroup([], {}), {}, null); } function containsTree(container, containee, exact) { if (exact) { return equalQueryParams(container.queryParams, containee.queryParams) && equalSegmentGroups(container.root, containee.root); } return containsQueryParams(container.queryParams, containee.queryParams) && containsSegmentGroup(container.root, containee.root); } function equalQueryParams(container, containee) { return shallowEqual(container, containee); } function equalSegmentGroups(container, containee) { if (!equalPath(container.segments, containee.segments)) return false; if (container.numberOfChildren !== containee.numberOfChildren) return false; for (var c in containee.children) { if (!container.children[c]) return false; if (!equalSegmentGroups(container.children[c], containee.children[c])) return false; } return true; } function containsQueryParams(container, containee) { return Object.keys(containee).length <= Object.keys(container).length && Object.keys(containee).every(function (key) { return containee[key] === container[key]; }); } function containsSegmentGroup(container, containee) { return containsSegmentGroupHelper(container, containee, containee.segments); } function containsSegmentGroupHelper(container, containee, containeePaths) { if (container.segments.length > containeePaths.length) { var current = container.segments.slice(0, containeePaths.length); if (!equalPath(current, containeePaths)) return false; if (containee.hasChildren()) return false; return true; } else if (container.segments.length === containeePaths.length) { if (!equalPath(container.segments, containeePaths)) return false; for (var c in containee.children) { if (!container.children[c]) return false; if (!containsSegmentGroup(container.children[c], containee.children[c])) return false; } return true; } else { var current = containeePaths.slice(0, container.segments.length); var next = containeePaths.slice(container.segments.length); if (!equalPath(container.segments, current)) return false; if (!container.children[PRIMARY_OUTLET]) return false; return containsSegmentGroupHelper(container.children[PRIMARY_OUTLET], containee, next); } } /** * @description * * Represents the parsed URL. * * Since a router state is a tree, and the URL is nothing but a serialized state, the URL is a * serialized tree. * UrlTree is a data structure that provides a lot of affordances in dealing with URLs * * ### Example * * ``` * @Component({templateUrl:'template.html'}) * class MyComponent { * constructor(router: Router) { * const tree: UrlTree = * router.parseUrl('/team/33/(user/victor//support:help)?debug=true#fragment'); * const f = tree.fragment; // return 'fragment' * const q = tree.queryParams; // returns {debug: 'true'} * const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET]; * const s: UrlSegment[] = g.segments; // returns 2 segments 'team' and '33' * g.children[PRIMARY_OUTLET].segments; // returns 2 segments 'user' and 'victor' * g.children['support'].segments; // return 1 segment 'help' * } * } * ``` * * */ var UrlTree = /** @class */ (function () { /** @internal */ function UrlTree( /** The root segment group of the URL tree */ root, /** The query params of the URL */ queryParams, /** The fragment of the URL */ fragment) { this.root = root; this.queryParams = queryParams; this.fragment = fragment; } Object.defineProperty(UrlTree.prototype, "queryParamMap", { get: function () { if (!this._queryParamMap) { this._queryParamMap = convertToParamMap(this.queryParams); } return this._queryParamMap; }, enumerable: true, configurable: true }); /** @docsNotRequired */ UrlTree.prototype.toString = function () { return DEFAULT_SERIALIZER.serialize(this); }; return UrlTree; }()); /** * @description * * Represents the parsed URL segment group. * * See `UrlTree` for more information. * * */ var UrlSegmentGroup = /** @class */ (function () { function UrlSegmentGroup( /** The URL segments of this group. See `UrlSegment` for more information */ segments, /** The list of children of this group */ children) { var _this = this; this.segments = segments; this.children = children; /** The parent node in the url tree */ this.parent = null; forEach(children, function (v, k) { return v.parent = _this; }); } /** Whether the segment has child segments */ UrlSegmentGroup.prototype.hasChildren = function () { return this.numberOfChildren > 0; }; Object.defineProperty(UrlSegmentGroup.prototype, "numberOfChildren", { /** Number of child segments */ get: function () { return Object.keys(this.children).length; }, enumerable: true, configurable: true }); /** @docsNotRequired */ UrlSegmentGroup.prototype.toString = function () { return serializePaths(this); }; return UrlSegmentGroup; }()); /** * @description * * Represents a single URL segment. * * A UrlSegment is a part of a URL between the two slashes. It contains a path and the matrix * parameters associated with the segment. * * ## Example * * ``` * @Component({templateUrl:'template.html'}) * class MyComponent { * constructor(router: Router) { * const tree: UrlTree = router.parseUrl('/team;id=33'); * const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET]; * const s: UrlSegment[] = g.segments; * s[0].path; // returns 'team' * s[0].parameters; // returns {id: 33} * } * } * ``` * * */ var UrlSegment = /** @class */ (function () { function UrlSegment( /** The path part of a URL segment */ path, /** The matrix parameters associated with a segment */ parameters) { this.path = path; this.parameters = parameters; } Object.defineProperty(UrlSegment.prototype, "parameterMap", { get: function () { if (!this._parameterMap) { this._parameterMap = convertToParamMap(this.parameters); } return this._parameterMap; }, enumerable: true, configurable: true }); /** @docsNotRequired */ UrlSegment.prototype.toString = function () { return serializePath(this); }; return UrlSegment; }()); function equalSegments(as, bs) { return equalPath(as, bs) && as.every(function (a, i) { return shallowEqual(a.parameters, bs[i].parameters); }); } function equalPath(as, bs) { if (as.length !== bs.length) return false; return as.every(function (a, i) { return a.path === bs[i].path; }); } function mapChildrenIntoArray(segment, fn) { var res = []; forEach(segment.children, function (child, childOutlet) { if (childOutlet === PRIMARY_OUTLET) { res = res.concat(fn(child, childOutlet)); } }); forEach(segment.children, function (child, childOutlet) { if (childOutlet !== PRIMARY_OUTLET) { res = res.concat(fn(child, childOutlet)); } }); return res; } /** * @description * * Serializes and deserializes a URL string into a URL tree. * * The url serialization strategy is customizable. You can * make all URLs case insensitive by providing a custom UrlSerializer. * * See `DefaultUrlSerializer` for an example of a URL serializer. * * */ var UrlSerializer = /** @class */ (function () { function UrlSerializer() { } return UrlSerializer; }()); /** * @description * * A default implementation of the `UrlSerializer`. * * Example URLs: * * ``` * /inbox/33(popup:compose) * /inbox/33;open=true/messages/44 * ``` * * DefaultUrlSerializer uses parentheses to serialize secondary segments (e.g., popup:compose), the * colon syntax to specify the outlet, and the ';parameter=value' syntax (e.g., open=true) to * specify route specific parameters. * * */ var DefaultUrlSerializer = /** @class */ (function () { function DefaultUrlSerializer() { } /** Parses a url into a `UrlTree` */ DefaultUrlSerializer.prototype.parse = function (url) { var p = new UrlParser(url); return new UrlTree(p.parseRootSegment(), p.parseQueryParams(), p.parseFragment()); }; /** Converts a `UrlTree` into a url */ DefaultUrlSerializer.prototype.serialize = function (tree) { var segment = "/" + serializeSegment(tree.root, true); var query = serializeQueryParams(tree.queryParams); var fragment = typeof tree.fragment === "string" ? "#" + encodeUriFragment(tree.fragment) : ''; return "" + segment + query + fragment; }; return DefaultUrlSerializer; }()); var DEFAULT_SERIALIZER = new DefaultUrlSerializer(); function serializePaths(segment) { return segment.segments.map(function (p) { return serializePath(p); }).join('/'); } function serializeSegment(segment, root) { if (!segment.hasChildren()) { return serializePaths(segment); } if (root) { var primary = segment.children[PRIMARY_OUTLET] ? serializeSegment(segment.children[PRIMARY_OUTLET], false) : ''; var children_1 = []; forEach(segment.children, function (v, k) { if (k !== PRIMARY_OUTLET) { children_1.push(k + ":" + serializeSegment(v, false)); } }); return children_1.length > 0 ? primary + "(" + children_1.join('//') + ")" : primary; } else { var children = mapChildrenIntoArray(segment, function (v, k) { if (k === PRIMARY_OUTLET) { return [serializeSegment(segment.children[PRIMARY_OUTLET], false)]; } return [k + ":" + serializeSegment(v, false)]; }); return serializePaths(segment) + "/(" + children.join('//') + ")"; } } /** * Encodes a URI string with the default encoding. This function will only ever be called from * `encodeUriQuery` or `encodeUriSegment` as it's the base set of encodings to be used. We need * a custom encoding because encodeURIComponent is too aggressive and encodes stuff that doesn't * have to be encoded per https://url.spec.whatwg.org. */ function encodeUriString(s) { return encodeURIComponent(s) .replace(/%40/g, '@') .replace(/%3A/gi, ':') .replace(/%24/g, '$') .replace(/%2C/gi, ','); } /** * This function should be used to encode both keys and values in a query string key/value. In * the following URL, you need to call encodeUriQuery on "k" and "v": * * http://www.site.org/html;mk=mv?k=v#f */ function encodeUriQuery(s) { return encodeUriString(s).replace(/%3B/gi, ';'); } /** * This function should be used to encode a URL fragment. In the following URL, you need to call * encodeUriFragment on "f": * * http://www.site.org/html;mk=mv?k=v#f */ function encodeUriFragment(s) { return encodeURI(s); } /** * This function should be run on any URI segment as well as the key and value in a key/value * pair for matrix params. In the following URL, you need to call encodeUriSegment on "html", * "mk", and "mv": * * http://www.site.org/html;mk=mv?k=v#f */ function encodeUriSegment(s) { return encodeUriString(s).replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/%26/gi, '&'); } function decode(s) { return decodeURIComponent(s); } // Query keys/values should have the "+" replaced first, as "+" in a query string is " ". // decodeURIComponent function will not decode "+" as a space. function decodeQuery(s) { return decode(s.replace(/\+/g, '%20')); } function serializePath(path) { return "" + encodeUriSegment(path.path) + serializeMatrixParams(path.parameters); } function serializeMatrixParams(params) { return Object.keys(params) .map(function (key) { return ";" + encodeUriSegment(key) + "=" + encodeUriSegment(params[key]); }) .join(''); } function serializeQueryParams(params) { var strParams = Object.keys(params).map(function (name) { var value = params[name]; return Array.isArray(value) ? value.map(function (v) { return encodeUriQuery(name) + "=" + encodeUriQuery(v); }).join('&') : encodeUriQuery(name) + "=" + encodeUriQuery(value); }); return strParams.length ? "?" + strParams.join("&") : ''; } var SEGMENT_RE = /^[^\/()?;=#]+/; function matchSegments(str) { var match = str.match(SEGMENT_RE); return match ? match[0] : ''; } var QUERY_PARAM_RE = /^[^=?&#]+/; // Return the name of the query param at the start of the string or an empty string function matchQueryParams(str) { var match = str.match(QUERY_PARAM_RE); return match ? match[0] : ''; } var QUERY_PARAM_VALUE_RE = /^[^?&#]+/; // Return the value of the query param at the start of the string or an empty string function matchUrlQueryParamValue(str) { var match = str.match(QUERY_PARAM_VALUE_RE); return match ? match[0] : ''; } var UrlParser = /** @class */ (function () { function UrlParser(url) { this.url = url; this.remaining = url; } UrlParser.prototype.parseRootSegment = function () { this.consumeOptional('/'); if (this.remaining === '' || this.peekStartsWith('?') || this.peekStartsWith('#')) { return new UrlSegmentGroup([], {}); } // The root segment group never has segments return new UrlSegmentGroup([], this.parseChildren()); }; UrlParser.prototype.parseQueryParams = function () { var params = {}; if (this.consumeOptional('?')) { do { this.parseQueryParam(params); } while (this.consumeOptional('&')); } return params; }; UrlParser.prototype.parseFragment = function () { return this.consumeOptional('#') ? decodeURIComponent(this.remaining) : null; }; UrlParser.prototype.parseChildren = function () { if (this.remaining === '') { return {}; } this.consumeOptional('/'); var segments = []; if (!this.peekStartsWith('(')) { segments.push(this.parseSegment()); } while (this.peekStartsWith('/') && !this.peekStartsWith('//') && !this.peekStartsWith('/(')) { this.capture('/'); segments.push(this.parseSegment()); } var children = {}; if (this.peekStartsWith('/(')) { this.capture('/'); children = this.parseParens(true); } var res = {}; if (this.peekStartsWith('(')) { res = this.parseParens(false); } if (segments.length > 0 || Object.keys(children).length > 0) { res[PRIMARY_OUTLET] = new UrlSegmentGroup(segments, children); } return res; }; // parse a segment with its matrix parameters // ie `name;k1=v1;k2` UrlParser.prototype.parseSegment = function () { var path = matchSegments(this.remaining); if (path === '' && this.peekStartsWith(';')) { throw new Error("Empty path url segment cannot have parameters: '" + this.remaining + "'."); } this.capture(path); return new UrlSegment(decode(path), this.parseMatrixParams()); }; UrlParser.prototype.parseMatrixParams = function () { var params = {}; while (this.consumeOptional(';')) { this.parseParam(params); } return params; }; UrlParser.prototype.parseParam = function (params) { var key = matchSegments(this.remaining); if (!key) { return; } this.capture(key); var value = ''; if (this.consumeOptional('=')) { var valueMatch = matchSegments(this.remaining); if (valueMatch) { value = valueMatch; this.capture(value); } } params[decode(key)] = decode(value); }; // Parse a single query parameter `name[=value]` UrlParser.prototype.parseQueryParam = function (params) { var key = matchQueryParams(this.remaining); if (!key) { return; } this.capture(key); var value = ''; if (this.consumeOptional('=')) { var valueMatch = matchUrlQueryParamValue(this.remaining); if (valueMatch) { value = valueMatch; this.capture(value); } } var decodedKey = decodeQuery(key); var decodedVal = decodeQuery(value); if (params.hasOwnProperty(decodedKey)) { // Append to existing values var currentVal = params[decodedKey]; if (!Array.isArray(currentVal)) { currentVal = [currentVal]; params[decodedKey] = currentVal; } currentVal.push(decodedVal); } else { // Create a new value params[decodedKey] = decodedVal; } }; // parse `(a/b//outlet_name:c/d)` UrlParser.prototype.parseParens = function (allowPrimary) { var segments = {}; this.capture('('); while (!this.consumeOptional(')') && this.remaining.length > 0) { var path = matchSegments(this.remaining); var next = this.remaining[path.length]; // if is is not one of these characters, then the segment was unescaped // or the group was not closed if (next !== '/' && next !== ')' && next !== ';') { throw new Error("Cannot parse url '" + this.url + "'"); } var outletName = undefined; if (path.indexOf(':') > -1) { outletName = path.substr(0, path.indexOf(':')); this.capture(outletName); this.capture(':'); } else if (allowPrimary) { outletName = PRIMARY_OUTLET; } var children = this.parseChildren(); segments[outletName] = Object.keys(children).length === 1 ? children[PRIMARY_OUTLET] : new UrlSegmentGroup([], children); this.consumeOptional('//'); } return segments; }; UrlParser.prototype.peekStartsWith = function (str) { return this.remaining.startsWith(str); }; // Consumes the prefix when it is present and returns whether it has been consumed UrlParser.prototype.consumeOptional = function (str) { if (this.peekStartsWith(str)) { this.remaining = this.remaining.substring(str.length); return true; } return false; }; UrlParser.prototype.capture = function (str) { if (!this.consumeOptional(str)) { throw new Error("Expected \"" + str + "\"."); } }; return UrlParser; }()); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var NoMatch = /** @class */ (function () { function NoMatch(segmentGroup) { this.segmentGroup = segmentGroup || null; } return NoMatch; }()); var AbsoluteRedirect = /** @class */ (function () { function AbsoluteRedirect(urlTree) { this.urlTree = urlTree; } return AbsoluteRedirect; }()); function noMatch(segmentGroup) { return new rxjs.Observable(function (obs) { return obs.error(new NoMatch(segmentGroup)); }); } function absoluteRedirect(newTree) { return new rxjs.Observable(function (obs) { return obs.error(new AbsoluteRedirect(newTree)); }); } function namedOutletsRedirect(redirectTo) { return new rxjs.Observable(function (obs) { return obs.error(new Error("Only absolute redirects can have named outlets. redirectTo: '" + redirectTo + "'")); }); } function canLoadFails(route) { return new rxjs.Observable(function (obs) { return obs.error(navigationCancelingError("Cannot load children because the guard of the route \"path: '" + route.path + "'\" returned false")); }); } /** * Returns the `UrlTree` with the redirection applied. * * Lazy modules are loaded along the way. */ function applyRedirects(moduleInjector, configLoader, urlSerializer, urlTree, config) { return new ApplyRedirects(moduleInjector, configLoader, urlSerializer, urlTree, config).apply(); } var ApplyRedirects = /** @class */ (function () { function ApplyRedirects(moduleInjector, configLoader, urlSerializer, urlTree, config) { this.configLoader = configLoader; this.urlSerializer = urlSerializer; this.urlTree = urlTree; this.config = config; this.allowRedirects = true; this.ngModule = moduleInjector.get(core.NgModuleRef); } ApplyRedirects.prototype.apply = function () { var _this = this; var expanded$ = this.expandSegmentGroup(this.ngModule, this.config, this.urlTree.root, PRIMARY_OUTLET); var urlTrees$ = expanded$.pipe(operators.map(function (rootSegmentGroup) { return _this.createUrlTree(rootSegmentGroup, _this.urlTree.queryParams, _this.urlTree.fragment); })); return urlTrees$.pipe(operators.catchError(function (e) { if (e instanceof AbsoluteRedirect) { // after an absolute redirect we do not apply any more redirects! _this.allowRedirects = false; // we need to run matching, so we can fetch all lazy-loaded modules return _this.match(e.urlTree); } if (e instanceof NoMatch) { throw _this.noMatchError(e); } throw e; })); }; ApplyRedirects.prototype.match = function (tree) { var _this = this; var expanded$ = this.expandSegmentGroup(this.ngModule, this.config, tree.root, PRIMARY_OUTLET); var mapped$ = expanded$.pipe(operators.map(function (rootSegmentGroup) { return _this.createUrlTree(rootSegmentGroup, tree.queryParams, tree.fragment); })); return mapped$.pipe(operators.catchError(function (e) { if (e instanceof NoMatch) { throw _this.noMatchError(e); } throw e; })); }; ApplyRedirects.prototype.noMatchError = function (e) { return new Error("Cannot match any routes. URL Segment: '" + e.segmentGroup + "'"); }; ApplyRedirects.prototype.createUrlTree = function (rootCandidate, queryParams, fragment) { var root = rootCandidate.segments.length > 0 ? new UrlSegmentGroup([], (_a = {}, _a[PRIMARY_OUTLET] = rootCandidate, _a)) : rootCandidate; return new UrlTree(root, queryParams, fragment); var _a; }; ApplyRedirects.prototype.expandSegmentGroup = function (ngModule, routes, segmentGroup, outlet) { if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) { return this.expandChildren(ngModule, routes, segmentGroup) .pipe(operators.map(function (children) { return new UrlSegmentGroup([], children); })); } return this.expandSegment(ngModule, segmentGroup, routes, segmentGroup.segments, outlet, true); }; // Recursively expand segment groups for all the child outlets ApplyRedirects.prototype.expandChildren = function (ngModule, routes, segmentGroup) { var _this = this; return waitForMap(segmentGroup.children, function (childOutlet, child) { return _this.expandSegmentGroup(ngModule, routes, child, childOutlet); }); }; ApplyRedirects.prototype.expandSegment = function (ngModule, segmentGroup, routes, segments, outlet, allowRedirects) { var _this = this; return rxjs.of.apply(void 0, __spread(routes)).pipe(operators.map(function (r) { var expanded$ = _this.expandSegmentAgainstRoute(ngModule, segmentGroup, routes, r, segments, outlet, allowRedirects); return expanded$.pipe(operators.catchError(function (e) { if (e instanceof NoMatch) { // TODO(i): this return type doesn't match the declared Observable - // talk to Jason return rxjs.of(null); } throw e; })); }), operators.concatAll(), operators.first(function (s) { return !!s; }), operators.catchError(function (e, _) { if (e instanceof rxjs.EmptyError || e.name === 'EmptyError') { if (_this.noLeftoversInUrl(segmentGroup, segments, outlet)) { return rxjs.of(new UrlSegmentGroup([], {})); } throw new NoMatch(segmentGroup); } throw e; })); }; ApplyRedirects.prototype.noLeftoversInUrl = function (segmentGroup, segments, outlet) { return segments.length === 0 && !segmentGroup.children[outlet]; }; ApplyRedirects.prototype.expandSegmentAgainstRoute = function (ngModule, segmentGroup, routes, route, paths, outlet, allowRedirects) { if (getOutlet(route) !== outlet) { return noMatch(segmentGroup); } if (route.redirectTo === undefined) { return this.matchSegmentAgainstRoute(ngModule, segmentGroup, route, paths); } if (allowRedirects && this.allowRedirects) { return this.expandSegmentAgainstRouteUsingRedirect(ngModule, segmentGroup, routes, route, paths, outlet); } return noMatch(segmentGroup); }; ApplyRedirects.prototype.expandSegmentAgainstRouteUsingRedirect = function (ngModule, segmentGroup, routes, route, segments, outlet) { if (route.path === '**') { return this.expandWildCardWithParamsAgainstRouteUsingRedirect(ngModule, routes, route, outlet); } return this.expandRegularSegmentAgainstRouteUsingRedirect(ngModule, segmentGroup, routes, route, segments, outlet); }; ApplyRedirects.prototype.expandWildCardWithParamsAgainstRouteUsingRedirect = function (ngModule, routes, route, outlet) { var _this = this; var newTree = this.applyRedirectCommands([], route.redirectTo, {}); if (route.redirectTo.startsWith('/')) { return absoluteRedirect(newTree); } return this.lineralizeSegments(route, newTree).pipe(operators.mergeMap(function (newSegments) { var group = new UrlSegmentGroup(newSegments, {}); return _this.expandSegment(ngModule, group, routes, newSegments, outlet, false); })); }; ApplyRedirects.prototype.expandRegularSegmentAgainstRouteUsingRedirect = function (ngModule, segmentGroup, routes, route, segments, outlet) { var _this = this; var _a = match(segmentGroup, route, segments), matched = _a.matched, consumedSegments = _a.consumedSegments, lastChild = _a.lastChild, positionalParamSegments = _a.positionalParamSegments; if (!matched) return noMatch(segmentGroup); var newTree = this.applyRedirectCommands(consumedSegments, route.redirectTo, positionalParamSegments); if (route.redirectTo.startsWith('/')) { return absoluteRedirect(newTree); } return this.lineralizeSegments(route, newTree).pipe(operators.mergeMap(function (newSegments) { return _this.expandSegment(ngModule, segmentGroup, routes, newSegments.concat(segments.slice(lastChild)), outlet, false); })); }; ApplyRedirects.prototype.matchSegmentAgainstRoute = function (ngModule, rawSegmentGroup, route, segments) { var _this = this; if (route.path === '**') { if (route.loadChildren) { return this.configLoader.load(ngModule.injector, route) .pipe(operators.map(function (cfg) { route._loadedConfig = cfg; return new UrlSegmentGroup(segments, {}); })); } return rxjs.of(new UrlSegmentGroup(segments, {})); } var _a = match(rawSegmentGroup, route, segments), matched = _a.matched, consumedSegments = _a.consumedSegments, lastChild = _a.lastChild; if (!matched) return noMatch(rawSegmentGroup); var rawSlicedSegments = segments.slice(lastChild); var childConfig$ = this.getChildConfig(ngModule, route); return childConfig$.pipe(operators.mergeMap(function (routerConfig) { var childModule = routerConfig.module; var childConfig = routerConfig.routes; var _a = split(rawSegmentGroup, consumedSegments, rawSlicedSegments, childConfig), segmentGroup = _a.segmentGroup, slicedSegments = _a.slicedSegments; if (slicedSegments.length === 0 && segmentGroup.hasChildren()) { var expanded$_1 = _this.expandChildren(childModule, childConfig, segmentGroup); return expanded$_1.pipe(operators.map(function (children) { return new UrlSegmentGroup(consumedSegments, children); })); } if (childConfig.length === 0 && slicedSegments.length === 0) { return rxjs.of(new UrlSegmentGroup(consumedSegments, {})); } var expanded$ = _this.expandSegment(childModule, segmentGroup, childConfig, slicedSegments, PRIMARY_OUTLET, true); return expanded$.pipe(operators.map(function (cs) { return new UrlSegmentGroup(consumedSegments.concat(cs.segments), cs.children); })); })); }; ApplyRedirects.prototype.getChildConfig = function (ngModule, route) { var _this = this; if (route.children) { // The children belong to the same module return rxjs.of(new LoadedRouterConfig(route.children, ngModule)); } if (route.loadChildren) { // lazy children belong to the loaded module if (route._loadedConfig !== undefined) { return rxjs.of(route._loadedConfig); } return runCanLoadGuard(ngModule.injector, route).pipe(operators.mergeMap(function (shouldLoad) { if (shouldLoad) { return _this.configLoader.load(ngModule.injector, route) .pipe(operators.map(function (cfg) { route._loadedConfig = cfg; return cfg; })); } return canLoadFails(route); })); } return rxjs.of(new LoadedRouterConfig([], ngModule)); }; ApplyRedirects.prototype.lineralizeSegments = function (route, urlTree) { var res = []; var c = urlTree.root; while (true) { res = res.concat(c.segments); if (c.numberOfChildren === 0) { return rxjs.of(res); } if (c.numberOfChildren > 1 || !c.children[PRIMARY_OUTLET]) { return namedOutletsRedirect(route.redirectTo); } c = c.children[PRIMARY_OUTLET]; } }; ApplyRedirects.prototype.applyRedirectCommands = function (segments, redirectTo, posParams) { return this.applyRedirectCreatreUrlTree(redirectTo, this.urlSerializer.parse(redirectTo), segments, posParams); }; ApplyRedirects.prototype.applyRedirectCreatreUrlTree = function (redirectTo, urlTree, segments, posParams) { var newRoot = this.createSegmentGroup(redirectTo, urlTree.root, segments, posParams); return new UrlTree(newRoot, this.createQueryParams(urlTree.queryParams, this.urlTree.queryParams), urlTree.fragment); }; ApplyRedirects.prototype.createQueryParams = function (redirectToParams, actualParams) { var res = {}; forEach(redirectToParams, function (v, k) { var copySourceValue = typeof v === 'string' && v.startsWith(':'); if (copySourceValue) { var sourceName = v.substring(1); res[k] = actualParams[sourceName]; } else { res[k] = v; } }); return res; }; ApplyRedirects.prototype.createSegmentGroup = function (redirectTo, group, segments, posParams) { var _this = this; var updatedSegments = this.createSegments(redirectTo, group.segments, segments, posParams); var children = {}; forEach(group.children, function (child, name) { children[name] = _this.createSegmentGroup(redirectTo, child, segments, posParams); }); return new UrlSegmentGroup(updatedSegments, children); }; ApplyRedirects.prototype.createSegments = function (redirectTo, redirectToSegments, actualSegments, posParams) { var _this = this; return redirectToSegments.map(function (s) { return s.path.startsWith(':') ? _this.findPosParam(redirectTo, s, posParams) : _this.findOrReturn(s, actualSegments); }); }; ApplyRedirects.prototype.findPosParam = function (redirectTo, redirectToUrlSegment, posParams) { var pos = posParams[redirectToUrlSegment.path.substring(1)]; if (!pos) throw new Error("Cannot redirect to '" + redirectTo + "'. Cannot find '" + redirectToUrlSegment.path + "'."); return pos; }; ApplyRedirects.prototype.findOrReturn = function (redirectToUrlSegment, actualSegments) { var idx = 0; try { for (var actualSegments_1 = __values(actualSegments), actualSegments_1_1 = actualSegments_1.next(); !actualSegments_1_1.done; actualSegments_1_1 = actualSegments_1.next()) { var s = actualSegments_1_1.value; if (s.path === redirectToUrlSegment.path) { actualSegments.splice(idx); return s; } idx++; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (actualSegments_1_1 && !actualSegments_1_1.done && (_a = actualSegments_1.return)) _a.call(actualSegments_1); } finally { if (e_1) throw e_1.error; } } return redirectToUrlSegment; var e_1, _a; }; return ApplyRedirects; }()); function runCanLoadGuard(moduleInjector, route) { var canLoad = route.canLoad; if (!canLoad || canLoad.length === 0) return rxjs.of(true); var obs = rxjs.from(canLoad).pipe(operators.map(function (injectionToken) { var guard = moduleInjector.get(injectionToken); return wrapIntoObservable(guard.canLoad ? guard.canLoad(route) : guard(route)); })); return andObservables(obs); } function match(segmentGroup, route, segments) { if (route.path === '') { if ((route.pathMatch === 'full') && (segmentGroup.hasChildren() || segments.length > 0)) { return { matched: false, consumedSegments: [], lastChild: 0, positionalParamSegments: {} }; } return { matched: true, consumedSegments: [], lastChild: 0, positionalParamSegments: {} }; } var matcher = route.matcher || defaultUrlMatcher; var res = matcher(segments, segmentGroup, route); if (!res) { return { matched: false, consumedSegments: [], lastChild: 0, positionalParamSegments: {}, }; } return { matched: true, consumedSegments: res.consumed, lastChild: res.consumed.length, positionalParamSegments: res.posParams, }; } function split(segmentGroup, consumedSegments, slicedSegments, config) { if (slicedSegments.length > 0 && containsEmptyPathRedirectsWithNamedOutlets(segmentGroup, slicedSegments, config)) { var s = new UrlSegmentGroup(consumedSegments, createChildrenForEmptySegments(config, new UrlSegmentGroup(slicedSegments, segmentGroup.children))); return { segmentGroup: mergeTrivialChildren(s), slicedSegments: [] }; } if (slicedSegments.length === 0 && containsEmptyPathRedirects(segmentGroup, slicedSegments, config)) { var s = new UrlSegmentGroup(segmentGroup.segments, addEmptySegmentsToChildrenIfNeeded(segmentGroup, slicedSegments, config, segmentGroup.children)); return { segmentGroup: mergeTrivialChildren(s), slicedSegments: slicedSegments }; } return { segmentGroup: segmentGroup, slicedSegments: slicedSegments }; } function mergeTrivialChildren(s) { if (s.numberOfChildren === 1 && s.children[PRIMARY_OUTLET]) { var c = s.children[PRIMARY_OUTLET]; return new UrlSegmentGroup(s.segments.concat(c.segments), c.children); } return s; } function addEmptySegmentsToChildrenIfNeeded(segmentGroup, slicedSegments, routes, children) { var res = {}; try { for (var routes_1 = __values(routes), routes_1_1 = routes_1.next(); !routes_1_1.done; routes_1_1 = routes_1.next()) { var r = routes_1_1.value; if (isEmptyPathRedirect(segmentGroup, slicedSegments, r) && !children[getOutlet(r)]) { res[getOutlet(r)] = new UrlSegmentGroup([], {}); } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1); } finally { if (e_2) throw e_2.error; } } return __assign({}, children, res); var e_2, _a; } function createChildrenForEmptySegments(routes, primarySegmentGroup) { var res = {}; res[PRIMARY_OUTLET] = primarySegmentGroup; try { for (var routes_2 = __values(routes), routes_2_1 = routes_2.next(); !routes_2_1.done; routes_2_1 = routes_2.next()) { var r = routes_2_1.value; if (r.path === '' && getOutlet(r) !== PRIMARY_OUTLET) { res[getOutlet(r)] = new UrlSegmentGroup([], {}); } } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2); } finally { if (e_3) throw e_3.error; } } return res; var e_3, _a; } function containsEmptyPathRedirectsWithNamedOutlets(segmentGroup, segments, routes) { return routes.some(function (r) { return isEmptyPathRedirect(segmentGroup, segments, r) && getOutlet(r) !== PRIMARY_OUTLET; }); } function containsEmptyPathRedirects(segmentGroup, segments, routes) { return routes.some(function (r) { return isEmptyPathRedirect(segmentGroup, segments, r); }); } function isEmptyPathRedirect(segmentGroup, segments, r) { if ((segmentGroup.hasChildren() || segments.length > 0) && r.pathMatch === 'full') { return false; } return r.path === '' && r.redirectTo !== undefined; } function getOutlet(route) { return route.outlet || PRIMARY_OUTLET; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var Tree = /** @class */ (function () { function Tree(root) { this._root = root; } Object.defineProperty(Tree.prototype, "root", { get: function () { return this._root.value; }, enumerable: true, configurable: true }); /** * @internal */ Tree.prototype.parent = function (t) { var p = this.pathFromRoot(t); return p.length > 1 ? p[p.length - 2] : null; }; /** * @internal */ Tree.prototype.children = function (t) { var n = findNode(t, this._root); return n ? n.children.map(function (t) { return t.value; }) : []; }; /** * @internal */ Tree.prototype.firstChild = function (t) { var n = findNode(t, this._root); return n && n.children.length > 0 ? n.children[0].value : null; }; /** * @internal */ Tree.prototype.siblings = function (t) { var p = findPath(t, this._root); if (p.length < 2) return []; var c = p[p.length - 2].children.map(function (c) { return c.value; }); return c.filter(function (cc) { return cc !== t; }); }; /** * @internal */ Tree.prototype.pathFromRoot = function (t) { return findPath(t, this._root).map(function (s) { return s.value; }); }; return Tree; }()); // DFS for the node matching the value function findNode(value, node) { if (value === node.value) return node; try { for (var _a = __values(node.children), _b = _a.next(); !_b.done; _b = _a.next()) { var child = _b.value; var node_1 = findNode(value, child); if (node_1) return node_1; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_1) throw e_1.error; } } return null; var e_1, _c; } // Return the path to the node with the given value using DFS function findPath(value, node) { if (value === node.value) return [node]; try { for (var _a = __values(node.children), _b = _a.next(); !_b.done; _b = _a.next()) { var child = _b.value; var path = findPath(value, child); if (path.length) { path.unshift(node); return path; } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_2) throw e_2.error; } } return []; var e_2, _c; } var TreeNode = /** @class */ (function () { function TreeNode(value, children) { this.value = value; this.children = children; } TreeNode.prototype.toString = function () { return "TreeNode(" + this.value + ")"; }; return TreeNode; }()); // Return the list of T indexed by outlet name function nodeChildrenAsMap(node) { var map = {}; if (node) { node.children.forEach(function (child) { return map[child.value.outlet] = child; }); } return map; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @description * * Represents the state of the router. * * RouterState is a tree of activated routes. Every node in this tree knows about the "consumed" URL * segments, the extracted parameters, and the resolved data. * * ### Example * * ``` * @Component({templateUrl:'template.html'}) * class MyComponent { * constructor(router: Router) { * const state: RouterState = router.routerState; * const root: ActivatedRoute = state.root; * const child = root.firstChild; * const id: Observable = child.params.map(p => p.id); * //... * } * } * ``` * * See `ActivatedRoute` for more information. * * */ var RouterState = /** @class */ (function (_super) { __extends(RouterState, _super); /** @internal */ function RouterState(root, /** The current snapshot of the router state */ snapshot) { var _this = _super.call(this, root) || this; _this.snapshot = snapshot; setRouterState(_this, root); return _this; } RouterState.prototype.toString = function () { return this.snapshot.toString(); }; return RouterState; }(Tree)); function createEmptyState(urlTree, rootComponent) { var snapshot = createEmptyStateSnapshot(urlTree, rootComponent); var emptyUrl = new rxjs.BehaviorSubject([new UrlSegment('', {})]); var emptyParams = new rxjs.BehaviorSubject({}); var emptyData = new rxjs.BehaviorSubject({}); var emptyQueryParams = new rxjs.BehaviorSubject({}); var fragment = new rxjs.BehaviorSubject(''); var activated = new ActivatedRoute(emptyUrl, emptyParams, emptyQueryParams, fragment, emptyData, PRIMARY_OUTLET, rootComponent, snapshot.root); activated.snapshot = snapshot.root; return new RouterState(new TreeNode(activated, []), snapshot); } function createEmptyStateSnapshot(urlTree, rootComponent) { var emptyParams = {}; var emptyData = {}; var emptyQueryParams = {}; var fragment = ''; var activated = new ActivatedRouteSnapshot([], emptyParams, emptyQueryParams, fragment, emptyData, PRIMARY_OUTLET, rootComponent, null, urlTree.root, -1, {}); return new RouterStateSnapshot('', new TreeNode(activated, [])); } /** * @description * * Contains the information about a route associated with a component loaded in an * outlet. An `ActivatedRoute` can also be used to traverse the router state tree. * * ``` * @Component({...}) * class MyComponent { * constructor(route: ActivatedRoute) { * const id: Observable = route.params.map(p => p.id); * const url: Observable = route.url.map(segments => segments.join('')); * // route.data includes both `data` and `resolve` * const user = route.data.map(d => d.user); * } * } * ``` * * */ var ActivatedRoute = /** @class */ (function () { /** @internal */ function ActivatedRoute( /** An observable of the URL segments matched by this route */ url, /** An observable of the matrix parameters scoped to this route */ params, /** An observable of the query parameters shared by all the routes */ queryParams, /** An observable of the URL fragment shared by all the routes */ fragment, /** An observable of the static and resolved data of this route. */ data, /** The outlet name of the route. It's a constant */ outlet, /** The component of the route. It's a constant */ // TODO(vsavkin): remove |string component, futureSnapshot) { this.url = url; this.params = params; this.queryParams = queryParams; this.fragment = fragment; this.data = data; this.outlet = outlet; this.component = component; this._futureSnapshot = futureSnapshot; } Object.defineProperty(ActivatedRoute.prototype, "routeConfig", { /** The configuration used to match this route */ get: function () { return this._futureSnapshot.routeConfig; }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRoute.prototype, "root", { /** The root of the router state */ get: function () { return this._routerState.root; }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRoute.prototype, "parent", { /** The parent of this route in the router state tree */ get: function () { return this._routerState.parent(this); }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRoute.prototype, "firstChild", { /** The first child of this route in the router state tree */ get: function () { return this._routerState.firstChild(this); }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRoute.prototype, "children", { /** The children of this route in the router state tree */ get: function () { return this._routerState.children(this); }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRoute.prototype, "pathFromRoot", { /** The path from the root of the router state tree to this route */ get: function () { return this._routerState.pathFromRoot(this); }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRoute.prototype, "paramMap", { get: function () { if (!this._paramMap) { this._paramMap = this.params.pipe(operators.map(function (p) { return convertToParamMap(p); })); } return this._paramMap; }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRoute.prototype, "queryParamMap", { get: function () { if (!this._queryParamMap) { this._queryParamMap = this.queryParams.pipe(operators.map(function (p) { return convertToParamMap(p); })); } return this._queryParamMap; }, enumerable: true, configurable: true }); ActivatedRoute.prototype.toString = function () { return this.snapshot ? this.snapshot.toString() : "Future(" + this._futureSnapshot + ")"; }; return ActivatedRoute; }()); /** * Returns the inherited params, data, and resolve for a given route. * By default, this only inherits values up to the nearest path-less or component-less route. * @internal */ function inheritedParamsDataResolve(route, paramsInheritanceStrategy) { if (paramsInheritanceStrategy === void 0) { paramsInheritanceStrategy = 'emptyOnly'; } var pathFromRoot = route.pathFromRoot; var inheritingStartingFrom = 0; if (paramsInheritanceStrategy !== 'always') { inheritingStartingFrom = pathFromRoot.length - 1; while (inheritingStartingFrom >= 1) { var current = pathFromRoot[inheritingStartingFrom]; var parent_1 = pathFromRoot[inheritingStartingFrom - 1]; // current route is an empty path => inherits its parent's params and data if (current.routeConfig && current.routeConfig.path === '') { inheritingStartingFrom--; // parent is componentless => current route should inherit its params and data } else if (!parent_1.component) { inheritingStartingFrom--; } else { break; } } } return flattenInherited(pathFromRoot.slice(inheritingStartingFrom)); } /** @internal */ function flattenInherited(pathFromRoot) { return pathFromRoot.reduce(function (res, curr) { var params = __assign({}, res.params, curr.params); var data = __assign({}, res.data, curr.data); var resolve = __assign({}, res.resolve, curr._resolvedData); return { params: params, data: data, resolve: resolve }; }, { params: {}, data: {}, resolve: {} }); } /** * @description * * Contains the information about a route associated with a component loaded in an * outlet at a particular moment in time. ActivatedRouteSnapshot can also be used to * traverse the router state tree. * * ``` * @Component({templateUrl:'./my-component.html'}) * class MyComponent { * constructor(route: ActivatedRoute) { * const id: string = route.snapshot.params.id; * const url: string = route.snapshot.url.join(''); * const user = route.snapshot.data.user; * } * } * ``` * * */ var ActivatedRouteSnapshot = /** @class */ (function () { /** @internal */ function ActivatedRouteSnapshot( /** The URL segments matched by this route */ url, /** The matrix parameters scoped to this route */ params, /** The query parameters shared by all the routes */ queryParams, /** The URL fragment shared by all the routes */ fragment, /** The static and resolved data of this route */ data, /** The outlet name of the route */ outlet, /** The component of the route */ component, routeConfig, urlSegment, lastPathIndex, resolve) { this.url = url; this.params = params; this.queryParams = queryParams; this.fragment = fragment; this.data = data; this.outlet = outlet; this.component = component; this.routeConfig = routeConfig; this._urlSegment = urlSegment; this._lastPathIndex = lastPathIndex; this._resolve = resolve; } Object.defineProperty(ActivatedRouteSnapshot.prototype, "root", { /** The root of the router state */ get: function () { return this._routerState.root; }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRouteSnapshot.prototype, "parent", { /** The parent of this route in the router state tree */ get: function () { return this._routerState.parent(this); }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRouteSnapshot.prototype, "firstChild", { /** The first child of this route in the router state tree */ get: function () { return this._routerState.firstChild(this); }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRouteSnapshot.prototype, "children", { /** The children of this route in the router state tree */ get: function () { return this._routerState.children(this); }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRouteSnapshot.prototype, "pathFromRoot", { /** The path from the root of the router state tree to this route */ get: function () { return this._routerState.pathFromRoot(this); }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRouteSnapshot.prototype, "paramMap", { get: function () { if (!this._paramMap) { this._paramMap = convertToParamMap(this.params); } return this._paramMap; }, enumerable: true, configurable: true }); Object.defineProperty(ActivatedRouteSnapshot.prototype, "queryParamMap", { get: function () { if (!this._queryParamMap) { this._queryParamMap = convertToParamMap(this.queryParams); } return this._queryParamMap; }, enumerable: true, configurable: true }); ActivatedRouteSnapshot.prototype.toString = function () { var url = this.url.map(function (segment) { return segment.toString(); }).join('/'); var matched = this.routeConfig ? this.routeConfig.path : ''; return "Route(url:'" + url + "', path:'" + matched + "')"; }; return ActivatedRouteSnapshot; }()); /** * @description * * Represents the state of the router at a moment in time. * * This is a tree of activated route snapshots. Every node in this tree knows about * the "consumed" URL segments, the extracted parameters, and the resolved data. * * ### Example * * ``` * @Component({templateUrl:'template.html'}) * class MyComponent { * constructor(router: Router) { * const state: RouterState = router.routerState; * const snapshot: RouterStateSnapshot = state.snapshot; * const root: ActivatedRouteSnapshot = snapshot.root; * const child = root.firstChild; * const id: Observable = child.params.map(p => p.id); * //... * } * } * ``` * * */ var RouterStateSnapshot = /** @class */ (function (_super) { __extends(RouterStateSnapshot, _super); /** @internal */ function RouterStateSnapshot( /** The url from which this snapshot was created */ url, root) { var _this = _super.call(this, root) || this; _this.url = url; setRouterState(_this, root); return _this; } RouterStateSnapshot.prototype.toString = function () { return serializeNode(this._root); }; return RouterStateSnapshot; }(Tree)); function setRouterState(state, node) { node.value._routerState = state; node.children.forEach(function (c) { return setRouterState(state, c); }); } function serializeNode(node) { var c = node.children.length > 0 ? " { " + node.children.map(serializeNode).join(', ') + " } " : ''; return "" + node.value + c; } /** * The expectation is that the activate route is created with the right set of parameters. * So we push new values into the observables only when they are not the initial values. * And we detect that by checking if the snapshot field is set. */ function advanceActivatedRoute(route) { if (route.snapshot) { var currentSnapshot = route.snapshot; var nextSnapshot = route._futureSnapshot; route.snapshot = nextSnapshot; if (!shallowEqual(currentSnapshot.queryParams, nextSnapshot.queryParams)) { route.queryParams.next(nextSnapshot.queryParams); } if (currentSnapshot.fragment !== nextSnapshot.fragment) { route.fragment.next(nextSnapshot.fragment); } if (!shallowEqual(currentSnapshot.params, nextSnapshot.params)) { route.params.next(nextSnapshot.params); } if (!shallowEqualArrays(currentSnapshot.url, nextSnapshot.url)) { route.url.next(nextSnapshot.url); } if (!shallowEqual(currentSnapshot.data, nextSnapshot.data)) { route.data.next(nextSnapshot.data); } } else { route.snapshot = route._futureSnapshot; // this is for resolved data route.data.next(route._futureSnapshot.data); } } function equalParamsAndUrlSegments(a, b) { var equalUrlParams = shallowEqual(a.params, b.params) && equalSegments(a.url, b.url); var parentsMismatch = !a.parent !== !b.parent; return equalUrlParams && !parentsMismatch && (!a.parent || equalParamsAndUrlSegments(a.parent, b.parent)); } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function createRouterState(routeReuseStrategy, curr, prevState) { var root = createNode(routeReuseStrategy, curr._root, prevState ? prevState._root : undefined); return new RouterState(root, curr); } function createNode(routeReuseStrategy, curr, prevState) { // reuse an activated route that is currently displayed on the screen if (prevState && routeReuseStrategy.shouldReuseRoute(curr.value, prevState.value.snapshot)) { var value = prevState.value; value._futureSnapshot = curr.value; var children = createOrReuseChildren(routeReuseStrategy, curr, prevState); return new TreeNode(value, children); // retrieve an activated route that is used to be displayed, but is not currently displayed } else { var detachedRouteHandle = routeReuseStrategy.retrieve(curr.value); if (detachedRouteHandle) { var tree = detachedRouteHandle.route; setFutureSnapshotsOfActivatedRoutes(curr, tree); return tree; } else { var value = createActivatedRoute(curr.value); var children = curr.children.map(function (c) { return createNode(routeReuseStrategy, c); }); return new TreeNode(value, children); } } } function setFutureSnapshotsOfActivatedRoutes(curr, result) { if (curr.value.routeConfig !== result.value.routeConfig) { throw new Error('Cannot reattach ActivatedRouteSnapshot created from a different route'); } if (curr.children.length !== result.children.length) { throw new Error('Cannot reattach ActivatedRouteSnapshot with a different number of children'); } result.value._futureSnapshot = curr.value; for (var i = 0; i < curr.children.length; ++i) { setFutureSnapshotsOfActivatedRoutes(curr.children[i], result.children[i]); } } function createOrReuseChildren(routeReuseStrategy, curr, prevState) { return curr.children.map(function (child) { try { for (var _a = __values(prevState.children), _b = _a.next(); !_b.done; _b = _a.next()) { var p = _b.value; if (routeReuseStrategy.shouldReuseRoute(p.value.snapshot, child.value)) { return createNode(routeReuseStrategy, child, p); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_1) throw e_1.error; } } return createNode(routeReuseStrategy, child); var e_1, _c; }); } function createActivatedRoute(c) { return new ActivatedRoute(new rxjs.BehaviorSubject(c.url), new rxjs.BehaviorSubject(c.params), new rxjs.BehaviorSubject(c.queryParams), new rxjs.BehaviorSubject(c.fragment), new rxjs.BehaviorSubject(c.data), c.outlet, c.component, c); } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function createUrlTree(route, urlTree, commands, queryParams, fragment) { if (commands.length === 0) { return tree(urlTree.root, urlTree.root, urlTree, queryParams, fragment); } var nav = computeNavigation(commands); if (nav.toRoot()) { return tree(urlTree.root, new UrlSegmentGroup([], {}), urlTree, queryParams, fragment); } var startingPosition = findStartingPosition(nav, urlTree, route); var segmentGroup = startingPosition.processChildren ? updateSegmentGroupChildren(startingPosition.segmentGroup, startingPosition.index, nav.commands) : updateSegmentGroup(startingPosition.segmentGroup, startingPosition.index, nav.commands); return tree(startingPosition.segmentGroup, segmentGroup, urlTree, queryParams, fragment); } function isMatrixParams(command) { return typeof command === 'object' && command != null && !command.outlets && !command.segmentPath; } function tree(oldSegmentGroup, newSegmentGroup, urlTree, queryParams, fragment) { var qp = {}; if (queryParams) { forEach(queryParams, function (value, name) { qp[name] = Array.isArray(value) ? value.map(function (v) { return "" + v; }) : "" + value; }); } if (urlTree.root === oldSegmentGroup) { return new UrlTree(newSegmentGroup, qp, fragment); } return new UrlTree(replaceSegment(urlTree.root, oldSegmentGroup, newSegmentGroup), qp, fragment); } function replaceSegment(current, oldSegment, newSegment) { var children = {}; forEach(current.children, function (c, outletName) { if (c === oldSegment) { children[outletName] = newSegment; } else { children[outletName] = replaceSegment(c, oldSegment, newSegment); } }); return new UrlSegmentGroup(current.segments, children); } var Navigation = /** @class */ (function () { function Navigation(isAbsolute, numberOfDoubleDots, commands) { this.isAbsolute = isAbsolute; this.numberOfDoubleDots = numberOfDoubleDots; this.commands = commands; if (isAbsolute && commands.length > 0 && isMatrixParams(commands[0])) { throw new Error('Root segment cannot have matrix parameters'); } var cmdWithOutlet = commands.find(function (c) { return typeof c === 'object' && c != null && c.outlets; }); if (cmdWithOutlet && cmdWithOutlet !== last(commands)) { throw new Error('{outlets:{}} has to be the last command'); } } Navigation.prototype.toRoot = function () { return this.isAbsolute && this.commands.length === 1 && this.commands[0] == '/'; }; return Navigation; }()); /** Transforms commands to a normalized `Navigation` */ function computeNavigation(commands) { if ((typeof commands[0] === 'string') && commands.length === 1 && commands[0] === '/') { return new Navigation(true, 0, commands); } var numberOfDoubleDots = 0; var isAbsolute = false; var res = commands.reduce(function (res, cmd, cmdIdx) { if (typeof cmd === 'object' && cmd != null) { if (cmd.outlets) { var outlets_1 = {}; forEach(cmd.outlets, function (commands, name) { outlets_1[name] = typeof commands === 'string' ? commands.split('/') : commands; }); return __spread(res, [{ outlets: outlets_1 }]); } if (cmd.segmentPath) { return __spread(res, [cmd.segmentPath]); } } if (!(typeof cmd === 'string')) { return __spread(res, [cmd]); } if (cmdIdx === 0) { cmd.split('/').forEach(function (urlPart, partIndex) { if (partIndex == 0 && urlPart === '.') ; else if (partIndex == 0 && urlPart === '') { isAbsolute = true; } else if (urlPart === '..') { numberOfDoubleDots++; } else if (urlPart != '') { res.push(urlPart); } }); return res; } return __spread(res, [cmd]); }, []); return new Navigation(isAbsolute, numberOfDoubleDots, res); } var Position = /** @class */ (function () { function Position(segmentGroup, processChildren, index) { this.segmentGroup = segmentGroup; this.processChildren = processChildren; this.index = index; } return Position; }()); function findStartingPosition(nav, tree, route) { if (nav.isAbsolute) { return new Position(tree.root, true, 0); } if (route.snapshot._lastPathIndex === -1) { return new Position(route.snapshot._urlSegment, true, 0); } var modifier = isMatrixParams(nav.commands[0]) ? 0 : 1; var index = route.snapshot._lastPathIndex + modifier; return createPositionApplyingDoubleDots(route.snapshot._urlSegment, index, nav.numberOfDoubleDots); } function createPositionApplyingDoubleDots(group, index, numberOfDoubleDots) { var g = group; var ci = index; var dd = numberOfDoubleDots; while (dd > ci) { dd -= ci; g = g.parent; if (!g) { throw new Error('Invalid number of \'../\''); } ci = g.segments.length; } return new Position(g, false, ci - dd); } function getPath(command) { if (typeof command === 'object' && command != null && command.outlets) { return command.outlets[PRIMARY_OUTLET]; } return "" + command; } function getOutlets(commands) { if (!(typeof commands[0] === 'object')) return _a = {}, _a[PRIMARY_OUTLET] = commands, _a; if (commands[0].outlets === undefined) return _b = {}, _b[PRIMARY_OUTLET] = commands, _b; return commands[0].outlets; var _a, _b; } function updateSegmentGroup(segmentGroup, startIndex, commands) { if (!segmentGroup) { segmentGroup = new UrlSegmentGroup([], {}); } if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) { return updateSegmentGroupChildren(segmentGroup, startIndex, commands); } var m = prefixedWith(segmentGroup, startIndex, commands); var slicedCommands = commands.slice(m.commandIndex); if (m.match && m.pathIndex < segmentGroup.segments.length) { var g = new UrlSegmentGroup(segmentGroup.segments.slice(0, m.pathIndex), {}); g.children[PRIMARY_OUTLET] = new UrlSegmentGroup(segmentGroup.segments.slice(m.pathIndex), segmentGroup.children); return updateSegmentGroupChildren(g, 0, slicedCommands); } else if (m.match && slicedCommands.length === 0) { return new UrlSegmentGroup(segmentGroup.segments, {}); } else if (m.match && !segmentGroup.hasChildren()) { return createNewSegmentGroup(segmentGroup, startIndex, commands); } else if (m.match) { return updateSegmentGroupChildren(segmentGroup, 0, slicedCommands); } else { return createNewSegmentGroup(segmentGroup, startIndex, commands); } } function updateSegmentGroupChildren(segmentGroup, startIndex, commands) { if (commands.length === 0) { return new UrlSegmentGroup(segmentGroup.segments, {}); } else { var outlets_2 = getOutlets(commands); var children_1 = {}; forEach(outlets_2, function (commands, outlet) { if (commands !== null) { children_1[outlet] = updateSegmentGroup(segmentGroup.children[outlet], startIndex, commands); } }); forEach(segmentGroup.children, function (child, childOutlet) { if (outlets_2[childOutlet] === undefined) { children_1[childOutlet] = child; } }); return new UrlSegmentGroup(segmentGroup.segments, children_1); } } function prefixedWith(segmentGroup, startIndex, commands) { var currentCommandIndex = 0; var currentPathIndex = startIndex; var noMatch = { match: false, pathIndex: 0, commandIndex: 0 }; while (currentPathIndex < segmentGroup.segments.length) { if (currentCommandIndex >= commands.length) return noMatch; var path = segmentGroup.segments[currentPathIndex]; var curr = getPath(commands[currentCommandIndex]); var next = currentCommandIndex < commands.length - 1 ? commands[currentCommandIndex + 1] : null; if (currentPathIndex > 0 && curr === undefined) break; if (curr && next && (typeof next === 'object') && next.outlets === undefined) { if (!compare(curr, next, path)) return noMatch; currentCommandIndex += 2; } else { if (!compare(curr, {}, path)) return noMatch; currentCommandIndex++; } currentPathIndex++; } return { match: true, pathIndex: currentPathIndex, commandIndex: currentCommandIndex }; } function createNewSegmentGroup(segmentGroup, startIndex, commands) { var paths = segmentGroup.segments.slice(0, startIndex); var i = 0; while (i < commands.length) { if (typeof commands[i] === 'object' && commands[i].outlets !== undefined) { var children = createNewSegmentChildren(commands[i].outlets); return new UrlSegmentGroup(paths, children); } // if we start with an object literal, we need to reuse the path part from the segment if (i === 0 && isMatrixParams(commands[0])) { var p = segmentGroup.segments[startIndex]; paths.push(new UrlSegment(p.path, commands[0])); i++; continue; } var curr = getPath(commands[i]); var next = (i < commands.length - 1) ? commands[i + 1] : null; if (curr && next && isMatrixParams(next)) { paths.push(new UrlSegment(curr, stringify(next))); i += 2; } else { paths.push(new UrlSegment(curr, {})); i++; } } return new UrlSegmentGroup(paths, {}); } function createNewSegmentChildren(outlets) { var children = {}; forEach(outlets, function (commands, outlet) { if (commands !== null) { children[outlet] = createNewSegmentGroup(new UrlSegmentGroup([], {}), 0, commands); } }); return children; } function stringify(params) { var res = {}; forEach(params, function (v, k) { return res[k] = "" + v; }); return res; } function compare(path, params, segment) { return path == segment.path && shallowEqual(params, segment.parameters); } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var CanActivate = /** @class */ (function () { function CanActivate(path) { this.path = path; this.route = this.path[this.path.length - 1]; } return CanActivate; }()); var CanDeactivate = /** @class */ (function () { function CanDeactivate(component, route) { this.component = component; this.route = route; } return CanDeactivate; }()); /** * This class bundles the actions involved in preactivation of a route. */ var PreActivation = /** @class */ (function () { function PreActivation(future, curr, moduleInjector, forwardEvent) { this.future = future; this.curr = curr; this.moduleInjector = moduleInjector; this.forwardEvent = forwardEvent; this.canActivateChecks = []; this.canDeactivateChecks = []; } PreActivation.prototype.initialize = function (parentContexts) { var futureRoot = this.future._root; var currRoot = this.curr ? this.curr._root : null; this.setupChildRouteGuards(futureRoot, currRoot, parentContexts, [futureRoot.value]); }; PreActivation.prototype.checkGuards = function () { var _this = this; if (!this.isDeactivating() && !this.isActivating()) { return rxjs.of(true); } var canDeactivate$ = this.runCanDeactivateChecks(); return canDeactivate$.pipe(operators.mergeMap(function (canDeactivate) { return canDeactivate ? _this.runCanActivateChecks() : rxjs.of(false); })); }; PreActivation.prototype.resolveData = function (paramsInheritanceStrategy) { var _this = this; if (!this.isActivating()) return rxjs.of(null); return rxjs.from(this.canActivateChecks) .pipe(operators.concatMap(function (check) { return _this.runResolve(check.route, paramsInheritanceStrategy); }), operators.reduce(function (_, __) { return _; })); }; PreActivation.prototype.isDeactivating = function () { return this.canDeactivateChecks.length !== 0; }; PreActivation.prototype.isActivating = function () { return this.canActivateChecks.length !== 0; }; /** * Iterates over child routes and calls recursive `setupRouteGuards` to get `this` instance in * proper state to run `checkGuards()` method. */ PreActivation.prototype.setupChildRouteGuards = function (futureNode, currNode, contexts, futurePath) { var _this = this; var prevChildren = nodeChildrenAsMap(currNode); // Process the children of the future route futureNode.children.forEach(function (c) { _this.setupRouteGuards(c, prevChildren[c.value.outlet], contexts, futurePath.concat([c.value])); delete prevChildren[c.value.outlet]; }); // Process any children left from the current route (not active for the future route) forEach(prevChildren, function (v, k) { return _this.deactivateRouteAndItsChildren(v, contexts.getContext(k)); }); }; /** * Iterates over child routes and calls recursive `setupRouteGuards` to get `this` instance in * proper state to run `checkGuards()` method. */ PreActivation.prototype.setupRouteGuards = function (futureNode, currNode, parentContexts, futurePath) { var future = futureNode.value; var curr = currNode ? currNode.value : null; var context = parentContexts ? parentContexts.getContext(futureNode.value.outlet) : null; // reusing the node if (curr && future.routeConfig === curr.routeConfig) { var shouldRunGuardsAndResolvers = this.shouldRunGuardsAndResolvers(curr, future, future.routeConfig.runGuardsAndResolvers); if (shouldRunGuardsAndResolvers) { this.canActivateChecks.push(new CanActivate(futurePath)); } else { // we need to set the data future.data = curr.data; future._resolvedData = curr._resolvedData; } // If we have a component, we need to go through an outlet. if (future.component) { this.setupChildRouteGuards(futureNode, currNode, context ? context.children : null, futurePath); // if we have a componentless route, we recurse but keep the same outlet map. } else { this.setupChildRouteGuards(futureNode, currNode, parentContexts, futurePath); } if (shouldRunGuardsAndResolvers) { var outlet = context.outlet; this.canDeactivateChecks.push(new CanDeactivate(outlet.component, curr)); } } else { if (curr) { this.deactivateRouteAndItsChildren(currNode, context); } this.canActivateChecks.push(new CanActivate(futurePath)); // If we have a component, we need to go through an outlet. if (future.component) { this.setupChildRouteGuards(futureNode, null, context ? context.children : null, futurePath); // if we have a componentless route, we recurse but keep the same outlet map. } else { this.setupChildRouteGuards(futureNode, null, parentContexts, futurePath); } } }; PreActivation.prototype.shouldRunGuardsAndResolvers = function (curr, future, mode) { switch (mode) { case 'always': return true; case 'paramsOrQueryParamsChange': return !equalParamsAndUrlSegments(curr, future) || !shallowEqual(curr.queryParams, future.queryParams); case 'paramsChange': default: return !equalParamsAndUrlSegments(curr, future); } }; PreActivation.prototype.deactivateRouteAndItsChildren = function (route, context) { var _this = this; var children = nodeChildrenAsMap(route); var r = route.value; forEach(children, function (node, childName) { if (!r.component) { _this.deactivateRouteAndItsChildren(node, context); } else if (context) { _this.deactivateRouteAndItsChildren(node, context.children.getContext(childName)); } else { _this.deactivateRouteAndItsChildren(node, null); } }); if (!r.component) { this.canDeactivateChecks.push(new CanDeactivate(null, r)); } else if (context && context.outlet && context.outlet.isActivated) { this.canDeactivateChecks.push(new CanDeactivate(context.outlet.component, r)); } else { this.canDeactivateChecks.push(new CanDeactivate(null, r)); } }; PreActivation.prototype.runCanDeactivateChecks = function () { var _this = this; return rxjs.from(this.canDeactivateChecks) .pipe(operators.mergeMap(function (check) { return _this.runCanDeactivate(check.component, check.route); }), operators.every(function (result) { return result === true; })); }; PreActivation.prototype.runCanActivateChecks = function () { var _this = this; return rxjs.from(this.canActivateChecks) .pipe(operators.concatMap(function (check) { return andObservables(rxjs.from([ _this.fireChildActivationStart(check.route.parent), _this.fireActivationStart(check.route), _this.runCanActivateChild(check.path), _this.runCanActivate(check.route) ])); }), operators.every(function (result) { return result === true; })); // this.fireChildActivationStart(check.path), }; /** * This should fire off `ActivationStart` events for each route being activated at this * level. * In other words, if you're activating `a` and `b` below, `path` will contain the * `ActivatedRouteSnapshot`s for both and we will fire `ActivationStart` for both. Always * return * `true` so checks continue to run. */ PreActivation.prototype.fireActivationStart = function (snapshot) { if (snapshot !== null && this.forwardEvent) { this.forwardEvent(new ActivationStart(snapshot)); } return rxjs.of(true); }; /** * This should fire off `ChildActivationStart` events for each route being activated at this * level. * In other words, if you're activating `a` and `b` below, `path` will contain the * `ActivatedRouteSnapshot`s for both and we will fire `ChildActivationStart` for both. Always * return * `true` so checks continue to run. */ PreActivation.prototype.fireChildActivationStart = function (snapshot) { if (snapshot !== null && this.forwardEvent) { this.forwardEvent(new ChildActivationStart(snapshot)); } return rxjs.of(true); }; PreActivation.prototype.runCanActivate = function (future) { var _this = this; var canActivate = future.routeConfig ? future.routeConfig.canActivate : null; if (!canActivate || canActivate.length === 0) return rxjs.of(true); var obs = rxjs.from(canActivate).pipe(operators.map(function (c) { var guard = _this.getToken(c, future); var observable; if (guard.canActivate) { observable = wrapIntoObservable(guard.canActivate(future, _this.future)); } else { observable = wrapIntoObservable(guard(future, _this.future)); } return observable.pipe(operators.first()); })); return andObservables(obs); }; PreActivation.prototype.runCanActivateChild = function (path) { var _this = this; var future = path[path.length - 1]; var canActivateChildGuards = path.slice(0, path.length - 1) .reverse() .map(function (p) { return _this.extractCanActivateChild(p); }) .filter(function (_) { return _ !== null; }); return andObservables(rxjs.from(canActivateChildGuards).pipe(operators.map(function (d) { var obs = rxjs.from(d.guards).pipe(operators.map(function (c) { var guard = _this.getToken(c, d.node); var observable; if (guard.canActivateChild) { observable = wrapIntoObservable(guard.canActivateChild(future, _this.future)); } else { observable = wrapIntoObservable(guard(future, _this.future)); } return observable.pipe(operators.first()); })); return andObservables(obs); }))); }; PreActivation.prototype.extractCanActivateChild = function (p) { var canActivateChild = p.routeConfig ? p.routeConfig.canActivateChild : null; if (!canActivateChild || canActivateChild.length === 0) return null; return { node: p, guards: canActivateChild }; }; PreActivation.prototype.runCanDeactivate = function (component, curr) { var _this = this; var canDeactivate = curr && curr.routeConfig ? curr.routeConfig.canDeactivate : null; if (!canDeactivate || canDeactivate.length === 0) return rxjs.of(true); var canDeactivate$ = rxjs.from(canDeactivate).pipe(operators.mergeMap(function (c) { var guard = _this.getToken(c, curr); var observable; if (guard.canDeactivate) { observable = wrapIntoObservable(guard.canDeactivate(component, curr, _this.curr, _this.future)); } else { observable = wrapIntoObservable(guard(component, curr, _this.curr, _this.future)); } return observable.pipe(operators.first()); })); return canDeactivate$.pipe(operators.every(function (result) { return result === true; })); }; PreActivation.prototype.runResolve = function (future, paramsInheritanceStrategy) { var resolve = future._resolve; return this.resolveNode(resolve, future).pipe(operators.map(function (resolvedData) { future._resolvedData = resolvedData; future.data = __assign({}, future.data, inheritedParamsDataResolve(future, paramsInheritanceStrategy).resolve); return null; })); }; PreActivation.prototype.resolveNode = function (resolve, future) { var _this = this; var keys = Object.keys(resolve); if (keys.length === 0) { return rxjs.of({}); } if (keys.length === 1) { var key_1 = keys[0]; return this.getResolver(resolve[key_1], future).pipe(operators.map(function (value) { return _a = {}, _a[key_1] = value, _a; var _a; })); } var data = {}; var runningResolvers$ = rxjs.from(keys).pipe(operators.mergeMap(function (key) { return _this.getResolver(resolve[key], future).pipe(operators.map(function (value) { data[key] = value; return value; })); })); return runningResolvers$.pipe(operators.last(), operators.map(function () { return data; })); }; PreActivation.prototype.getResolver = function (injectionToken, future) { var resolver = this.getToken(injectionToken, future); return resolver.resolve ? wrapIntoObservable(resolver.resolve(future, this.future)) : wrapIntoObservable(resolver(future, this.future)); }; PreActivation.prototype.getToken = function (token, snapshot) { var config = closestLoadedConfig(snapshot); var injector = config ? config.module.injector : this.moduleInjector; return injector.get(token); }; return PreActivation; }()); function closestLoadedConfig(snapshot) { if (!snapshot) return null; for (var s = snapshot.parent; s; s = s.parent) { var route = s.routeConfig; if (route && route._loadedConfig) return route._loadedConfig; } return null; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var NoMatch$1 = /** @class */ (function () { function NoMatch() { } return NoMatch; }()); function recognize(rootComponentType, config, urlTree, url, paramsInheritanceStrategy) { if (paramsInheritanceStrategy === void 0) { paramsInheritanceStrategy = 'emptyOnly'; } return new Recognizer(rootComponentType, config, urlTree, url, paramsInheritanceStrategy) .recognize(); } var Recognizer = /** @class */ (function () { function Recognizer(rootComponentType, config, urlTree, url, paramsInheritanceStrategy) { this.rootComponentType = rootComponentType; this.config = config; this.urlTree = urlTree; this.url = url; this.paramsInheritanceStrategy = paramsInheritanceStrategy; } Recognizer.prototype.recognize = function () { try { var rootSegmentGroup = split$1(this.urlTree.root, [], [], this.config).segmentGroup; var children = this.processSegmentGroup(this.config, rootSegmentGroup, PRIMARY_OUTLET); var root = new ActivatedRouteSnapshot([], Object.freeze({}), Object.freeze(__assign({}, this.urlTree.queryParams)), this.urlTree.fragment, {}, PRIMARY_OUTLET, this.rootComponentType, null, this.urlTree.root, -1, {}); var rootNode = new TreeNode(root, children); var routeState = new RouterStateSnapshot(this.url, rootNode); this.inheritParamsAndData(routeState._root); return rxjs.of(routeState); } catch (e) { return new rxjs.Observable(function (obs) { return obs.error(e); }); } }; Recognizer.prototype.inheritParamsAndData = function (routeNode) { var _this = this; var route = routeNode.value; var i = inheritedParamsDataResolve(route, this.paramsInheritanceStrategy); route.params = Object.freeze(i.params); route.data = Object.freeze(i.data); routeNode.children.forEach(function (n) { return _this.inheritParamsAndData(n); }); }; Recognizer.prototype.processSegmentGroup = function (config, segmentGroup, outlet) { if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) { return this.processChildren(config, segmentGroup); } return this.processSegment(config, segmentGroup, segmentGroup.segments, outlet); }; Recognizer.prototype.processChildren = function (config, segmentGroup) { var _this = this; var children = mapChildrenIntoArray(segmentGroup, function (child, childOutlet) { return _this.processSegmentGroup(config, child, childOutlet); }); checkOutletNameUniqueness(children); sortActivatedRouteSnapshots(children); return children; }; Recognizer.prototype.processSegment = function (config, segmentGroup, segments, outlet) { try { for (var config_1 = __values(config), config_1_1 = config_1.next(); !config_1_1.done; config_1_1 = config_1.next()) { var r = config_1_1.value; try { return this.processSegmentAgainstRoute(r, segmentGroup, segments, outlet); } catch (e) { if (!(e instanceof NoMatch$1)) throw e; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (config_1_1 && !config_1_1.done && (_a = config_1.return)) _a.call(config_1); } finally { if (e_1) throw e_1.error; } } if (this.noLeftoversInUrl(segmentGroup, segments, outlet)) { return []; } throw new NoMatch$1(); var e_1, _a; }; Recognizer.prototype.noLeftoversInUrl = function (segmentGroup, segments, outlet) { return segments.length === 0 && !segmentGroup.children[outlet]; }; Recognizer.prototype.processSegmentAgainstRoute = function (route, rawSegment, segments, outlet) { if (route.redirectTo) throw new NoMatch$1(); if ((route.outlet || PRIMARY_OUTLET) !== outlet) throw new NoMatch$1(); var snapshot; var consumedSegments = []; var rawSlicedSegments = []; if (route.path === '**') { var params = segments.length > 0 ? last(segments).parameters : {}; 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)); } else { var result = match$1(rawSegment, route, segments); consumedSegments = result.consumedSegments; rawSlicedSegments = segments.slice(result.lastChild); 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)); } var childConfig = getChildConfig(route); var _a = split$1(rawSegment, consumedSegments, rawSlicedSegments, childConfig), segmentGroup = _a.segmentGroup, slicedSegments = _a.slicedSegments; if (slicedSegments.length === 0 && segmentGroup.hasChildren()) { var children_1 = this.processChildren(childConfig, segmentGroup); return [new TreeNode(snapshot, children_1)]; } if (childConfig.length === 0 && slicedSegments.length === 0) { return [new TreeNode(snapshot, [])]; } var children = this.processSegment(childConfig, segmentGroup, slicedSegments, PRIMARY_OUTLET); return [new TreeNode(snapshot, children)]; }; return Recognizer; }()); function sortActivatedRouteSnapshots(nodes) { nodes.sort(function (a, b) { if (a.value.outlet === PRIMARY_OUTLET) return -1; if (b.value.outlet === PRIMARY_OUTLET) return 1; return a.value.outlet.localeCompare(b.value.outlet); }); } function getChildConfig(route) { if (route.children) { return route.children; } if (route.loadChildren) { return route._loadedConfig.routes; } return []; } function match$1(segmentGroup, route, segments) { if (route.path === '') { if (route.pathMatch === 'full' && (segmentGroup.hasChildren() || segments.length > 0)) { throw new NoMatch$1(); } return { consumedSegments: [], lastChild: 0, parameters: {} }; } var matcher = route.matcher || defaultUrlMatcher; var res = matcher(segments, segmentGroup, route); if (!res) throw new NoMatch$1(); var posParams = {}; forEach(res.posParams, function (v, k) { posParams[k] = v.path; }); var parameters = res.consumed.length > 0 ? __assign({}, posParams, res.consumed[res.consumed.length - 1].parameters) : posParams; return { consumedSegments: res.consumed, lastChild: res.consumed.length, parameters: parameters }; } function checkOutletNameUniqueness(nodes) { var names = {}; nodes.forEach(function (n) { var routeWithSameOutletName = names[n.value.outlet]; if (routeWithSameOutletName) { var p = routeWithSameOutletName.url.map(function (s) { return s.toString(); }).join('/'); var c = n.value.url.map(function (s) { return s.toString(); }).join('/'); throw new Error("Two segments cannot have the same outlet name: '" + p + "' and '" + c + "'."); } names[n.value.outlet] = n.value; }); } function getSourceSegmentGroup(segmentGroup) { var s = segmentGroup; while (s._sourceSegment) { s = s._sourceSegment; } return s; } function getPathIndexShift(segmentGroup) { var s = segmentGroup; var res = (s._segmentIndexShift ? s._segmentIndexShift : 0); while (s._sourceSegment) { s = s._sourceSegment; res += (s._segmentIndexShift ? s._segmentIndexShift : 0); } return res - 1; } function split$1(segmentGroup, consumedSegments, slicedSegments, config) { if (slicedSegments.length > 0 && containsEmptyPathMatchesWithNamedOutlets(segmentGroup, slicedSegments, config)) { var s_1 = new UrlSegmentGroup(consumedSegments, createChildrenForEmptyPaths(segmentGroup, consumedSegments, config, new UrlSegmentGroup(slicedSegments, segmentGroup.children))); s_1._sourceSegment = segmentGroup; s_1._segmentIndexShift = consumedSegments.length; return { segmentGroup: s_1, slicedSegments: [] }; } if (slicedSegments.length === 0 && containsEmptyPathMatches(segmentGroup, slicedSegments, config)) { var s_2 = new UrlSegmentGroup(segmentGroup.segments, addEmptyPathsToChildrenIfNeeded(segmentGroup, slicedSegments, config, segmentGroup.children)); s_2._sourceSegment = segmentGroup; s_2._segmentIndexShift = consumedSegments.length; return { segmentGroup: s_2, slicedSegments: slicedSegments }; } var s = new UrlSegmentGroup(segmentGroup.segments, segmentGroup.children); s._sourceSegment = segmentGroup; s._segmentIndexShift = consumedSegments.length; return { segmentGroup: s, slicedSegments: slicedSegments }; } function addEmptyPathsToChildrenIfNeeded(segmentGroup, slicedSegments, routes, children) { var res = {}; try { for (var routes_1 = __values(routes), routes_1_1 = routes_1.next(); !routes_1_1.done; routes_1_1 = routes_1.next()) { var r = routes_1_1.value; if (emptyPathMatch(segmentGroup, slicedSegments, r) && !children[getOutlet$1(r)]) { var s = new UrlSegmentGroup([], {}); s._sourceSegment = segmentGroup; s._segmentIndexShift = segmentGroup.segments.length; res[getOutlet$1(r)] = s; } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1); } finally { if (e_2) throw e_2.error; } } return __assign({}, children, res); var e_2, _a; } function createChildrenForEmptyPaths(segmentGroup, consumedSegments, routes, primarySegment) { var res = {}; res[PRIMARY_OUTLET] = primarySegment; primarySegment._sourceSegment = segmentGroup; primarySegment._segmentIndexShift = consumedSegments.length; try { for (var routes_2 = __values(routes), routes_2_1 = routes_2.next(); !routes_2_1.done; routes_2_1 = routes_2.next()) { var r = routes_2_1.value; if (r.path === '' && getOutlet$1(r) !== PRIMARY_OUTLET) { var s = new UrlSegmentGroup([], {}); s._sourceSegment = segmentGroup; s._segmentIndexShift = consumedSegments.length; res[getOutlet$1(r)] = s; } } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2); } finally { if (e_3) throw e_3.error; } } return res; var e_3, _a; } function containsEmptyPathMatchesWithNamedOutlets(segmentGroup, slicedSegments, routes) { return routes.some(function (r) { return emptyPathMatch(segmentGroup, slicedSegments, r) && getOutlet$1(r) !== PRIMARY_OUTLET; }); } function containsEmptyPathMatches(segmentGroup, slicedSegments, routes) { return routes.some(function (r) { return emptyPathMatch(segmentGroup, slicedSegments, r); }); } function emptyPathMatch(segmentGroup, slicedSegments, r) { if ((segmentGroup.hasChildren() || slicedSegments.length > 0) && r.pathMatch === 'full') { return false; } return r.path === '' && r.redirectTo === undefined; } function getOutlet$1(route) { return route.outlet || PRIMARY_OUTLET; } function getData(route) { return route.data || {}; } function getResolve(route) { return route.resolve || {}; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @description * * Provides a way to customize when activated routes get reused. * * @experimental */ var RouteReuseStrategy = /** @class */ (function () { function RouteReuseStrategy() { } return RouteReuseStrategy; }()); /** * Does not detach any subtrees. Reuses routes as long as their route config is the same. */ var DefaultRouteReuseStrategy = /** @class */ (function () { function DefaultRouteReuseStrategy() { } DefaultRouteReuseStrategy.prototype.shouldDetach = function (route) { return false; }; DefaultRouteReuseStrategy.prototype.store = function (route, detachedTree) { }; DefaultRouteReuseStrategy.prototype.shouldAttach = function (route) { return false; }; DefaultRouteReuseStrategy.prototype.retrieve = function (route) { return null; }; DefaultRouteReuseStrategy.prototype.shouldReuseRoute = function (future, curr) { return future.routeConfig === curr.routeConfig; }; return DefaultRouteReuseStrategy; }()); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @docsNotRequired * @experimental */ var ROUTES = new core.InjectionToken('ROUTES'); var RouterConfigLoader = /** @class */ (function () { function RouterConfigLoader(loader, compiler, onLoadStartListener, onLoadEndListener) { this.loader = loader; this.compiler = compiler; this.onLoadStartListener = onLoadStartListener; this.onLoadEndListener = onLoadEndListener; } RouterConfigLoader.prototype.load = function (parentInjector, route) { var _this = this; if (this.onLoadStartListener) { this.onLoadStartListener(route); } var moduleFactory$ = this.loadModuleFactory(route.loadChildren); return moduleFactory$.pipe(operators.map(function (factory) { if (_this.onLoadEndListener) { _this.onLoadEndListener(route); } var module = factory.create(parentInjector); return new LoadedRouterConfig(flatten(module.injector.get(ROUTES)).map(standardizeConfig), module); })); }; RouterConfigLoader.prototype.loadModuleFactory = function (loadChildren) { var _this = this; if (typeof loadChildren === 'string') { return rxjs.from(this.loader.load(loadChildren)); } else { return wrapIntoObservable(loadChildren()).pipe(operators.mergeMap(function (t) { if (t instanceof core.NgModuleFactory) { return rxjs.of(t); } else { return rxjs.from(_this.compiler.compileModuleAsync(t)); } })); } }; return RouterConfigLoader; }()); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @description * * Provides a way to migrate AngularJS applications to Angular. * * @experimental */ var UrlHandlingStrategy = /** @class */ (function () { function UrlHandlingStrategy() { } return UrlHandlingStrategy; }()); /** * @experimental */ var DefaultUrlHandlingStrategy = /** @class */ (function () { function DefaultUrlHandlingStrategy() { } DefaultUrlHandlingStrategy.prototype.shouldProcessUrl = function (url) { return true; }; DefaultUrlHandlingStrategy.prototype.extract = function (url) { return url; }; DefaultUrlHandlingStrategy.prototype.merge = function (newUrlPart, wholeUrl) { return newUrlPart; }; return DefaultUrlHandlingStrategy; }()); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function defaultErrorHandler(error) { throw error; } function defaultMalformedUriErrorHandler(error, urlSerializer, url) { return urlSerializer.parse('/'); } /** * @internal */ function defaultRouterHook(snapshot) { return rxjs.of(null); } /** * @description * * Provides the navigation and url manipulation capabilities. * * See `Routes` for more details and examples. * * @ngModule RouterModule * * */ var Router = /** @class */ (function () { /** * Creates the router service. */ // TODO: vsavkin make internal after the final is out. function Router(rootComponentType, urlSerializer, rootContexts, location, injector, loader, compiler, config) { var _this = this; this.rootComponentType = rootComponentType; this.urlSerializer = urlSerializer; this.rootContexts = rootContexts; this.location = location; this.config = config; this.navigations = new rxjs.BehaviorSubject(null); this.navigationId = 0; this.events = new rxjs.Subject(); /** * Error handler that is invoked when a navigation errors. * * See `ErrorHandler` for more information. */ this.errorHandler = defaultErrorHandler; /** * Malformed uri error handler is invoked when `Router.parseUrl(url)` throws an * error due to containing an invalid character. The most common case would be a `%` sign * that's not encoded and is not part of a percent encoded sequence. */ this.malformedUriErrorHandler = defaultMalformedUriErrorHandler; /** * Indicates if at least one navigation happened. */ this.navigated = false; this.lastSuccessfulId = -1; /** * Used by RouterModule. This allows us to * pause the navigation either before preactivation or after it. * @internal */ this.hooks = { beforePreactivation: defaultRouterHook, afterPreactivation: defaultRouterHook }; /** * Extracts and merges URLs. Used for AngularJS to Angular migrations. */ this.urlHandlingStrategy = new DefaultUrlHandlingStrategy(); this.routeReuseStrategy = new DefaultRouteReuseStrategy(); /** * Define what the router should do if it receives a navigation request to the current URL. * By default, the router will ignore this navigation. However, this prevents features such * as a "refresh" button. Use this option to configure the behavior when navigating to the * current URL. Default is 'ignore'. */ this.onSameUrlNavigation = 'ignore'; /** * Defines how the router merges params, data and resolved data from parent to child * routes. Available options are: * * - `'emptyOnly'`, the default, only inherits parent params for path-less or component-less * routes. * - `'always'`, enables unconditional inheritance of parent params. */ this.paramsInheritanceStrategy = 'emptyOnly'; var onLoadStart = function (r) { return _this.triggerEvent(new RouteConfigLoadStart(r)); }; var onLoadEnd = function (r) { return _this.triggerEvent(new RouteConfigLoadEnd(r)); }; this.ngModule = injector.get(core.NgModuleRef); this.resetConfig(config); this.currentUrlTree = createEmptyUrlTree(); this.rawUrlTree = this.currentUrlTree; this.configLoader = new RouterConfigLoader(loader, compiler, onLoadStart, onLoadEnd); this.routerState = createEmptyState(this.currentUrlTree, this.rootComponentType); this.processNavigations(); } /** * @internal * TODO: this should be removed once the constructor of the router made internal */ Router.prototype.resetRootComponentType = function (rootComponentType) { this.rootComponentType = rootComponentType; // TODO: vsavkin router 4.0 should make the root component set to null // this will simplify the lifecycle of the router. this.routerState.root.component = this.rootComponentType; }; /** * Sets up the location change listener and performs the initial navigation. */ Router.prototype.initialNavigation = function () { this.setUpLocationChangeListener(); if (this.navigationId === 0) { this.navigateByUrl(this.location.path(true), { replaceUrl: true }); } }; /** * Sets up the location change listener. */ Router.prototype.setUpLocationChangeListener = function () { var _this = this; // Don't need to use Zone.wrap any more, because zone.js // already patch onPopState, so location change callback will // run into ngZone if (!this.locationSubscription) { this.locationSubscription = this.location.subscribe(function (change) { var rawUrlTree = _this.parseUrl(change['url']); var source = change['type'] === 'popstate' ? 'popstate' : 'hashchange'; var state = change.state && change.state.navigationId ? { navigationId: change.state.navigationId } : null; setTimeout(function () { _this.scheduleNavigation(rawUrlTree, source, state, { replaceUrl: true }); }, 0); }); } }; Object.defineProperty(Router.prototype, "url", { /** The current url */ get: function () { return this.serializeUrl(this.currentUrlTree); }, enumerable: true, configurable: true }); /** @internal */ Router.prototype.triggerEvent = function (e) { this.events.next(e); }; /** * Resets the configuration used for navigation and generating links. * * ### Usage * * ``` * router.resetConfig([ * { path: 'team/:id', component: TeamCmp, children: [ * { path: 'simple', component: SimpleCmp }, * { path: 'user/:name', component: UserCmp } * ]} * ]); * ``` */ Router.prototype.resetConfig = function (config) { validateConfig(config); this.config = config.map(standardizeConfig); this.navigated = false; this.lastSuccessfulId = -1; }; /** @docsNotRequired */ Router.prototype.ngOnDestroy = function () { this.dispose(); }; /** Disposes of the router */ Router.prototype.dispose = function () { if (this.locationSubscription) { this.locationSubscription.unsubscribe(); this.locationSubscription = null; } }; /** * Applies an array of commands to the current url tree and creates a new url tree. * * When given an activate route, applies the given commands starting from the route. * When not given a route, applies the given command starting from the root. * * ### Usage * * ``` * // create /team/33/user/11 * router.createUrlTree(['/team', 33, 'user', 11]); * * // create /team/33;expand=true/user/11 * router.createUrlTree(['/team', 33, {expand: true}, 'user', 11]); * * // you can collapse static segments like this (this works only with the first passed-in value): * router.createUrlTree(['/team/33/user', userId]); * * // If the first segment can contain slashes, and you do not want the router to split it, you * // can do the following: * * router.createUrlTree([{segmentPath: '/one/two'}]); * * // create /team/33/(user/11//right:chat) * router.createUrlTree(['/team', 33, {outlets: {primary: 'user/11', right: 'chat'}}]); * * // remove the right secondary node * router.createUrlTree(['/team', 33, {outlets: {primary: 'user/11', right: null}}]); * * // assuming the current url is `/team/33/user/11` and the route points to `user/11` * * // navigate to /team/33/user/11/details * router.createUrlTree(['details'], {relativeTo: route}); * * // navigate to /team/33/user/22 * router.createUrlTree(['../22'], {relativeTo: route}); * * // navigate to /team/44/user/22 * router.createUrlTree(['../../team/44/user/22'], {relativeTo: route}); * ``` */ Router.prototype.createUrlTree = function (commands, navigationExtras) { if (navigationExtras === void 0) { navigationExtras = {}; } var relativeTo = navigationExtras.relativeTo, queryParams = navigationExtras.queryParams, fragment = navigationExtras.fragment, preserveQueryParams = navigationExtras.preserveQueryParams, queryParamsHandling = navigationExtras.queryParamsHandling, preserveFragment = navigationExtras.preserveFragment; if (core.isDevMode() && preserveQueryParams && console && console.warn) { console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.'); } var a = relativeTo || this.routerState.root; var f = preserveFragment ? this.currentUrlTree.fragment : fragment; var q = null; if (queryParamsHandling) { switch (queryParamsHandling) { case 'merge': q = __assign({}, this.currentUrlTree.queryParams, queryParams); break; case 'preserve': q = this.currentUrlTree.queryParams; break; default: q = queryParams || null; } } else { q = preserveQueryParams ? this.currentUrlTree.queryParams : queryParams || null; } if (q !== null) { q = this.removeEmptyProps(q); } return createUrlTree(a, this.currentUrlTree, commands, q, f); }; /** * Navigate based on the provided url. This navigation is always absolute. * * Returns a promise that: * - resolves to 'true' when navigation succeeds, * - resolves to 'false' when navigation fails, * - is rejected when an error happens. * * ### Usage * * ``` * router.navigateByUrl("/team/33/user/11"); * * // Navigate without updating the URL * router.navigateByUrl("/team/33/user/11", { skipLocationChange: true }); * ``` * * In opposite to `navigate`, `navigateByUrl` takes a whole URL * and does not apply any delta to the current one. */ Router.prototype.navigateByUrl = function (url, extras) { if (extras === void 0) { extras = { skipLocationChange: false }; } var urlTree = url instanceof UrlTree ? url : this.parseUrl(url); var mergedTree = this.urlHandlingStrategy.merge(urlTree, this.rawUrlTree); return this.scheduleNavigation(mergedTree, 'imperative', null, extras); }; /** * Navigate based on the provided array of commands and a starting point. * If no starting route is provided, the navigation is absolute. * * Returns a promise that: * - resolves to 'true' when navigation succeeds, * - resolves to 'false' when navigation fails, * - is rejected when an error happens. * * ### Usage * * ``` * router.navigate(['team', 33, 'user', 11], {relativeTo: route}); * * // Navigate without updating the URL * router.navigate(['team', 33, 'user', 11], {relativeTo: route, skipLocationChange: true}); * ``` * * In opposite to `navigateByUrl`, `navigate` always takes a delta that is applied to the current * URL. */ Router.prototype.navigate = function (commands, extras) { if (extras === void 0) { extras = { skipLocationChange: false }; } validateCommands(commands); return this.navigateByUrl(this.createUrlTree(commands, extras), extras); }; /** Serializes a `UrlTree` into a string */ Router.prototype.serializeUrl = function (url) { return this.urlSerializer.serialize(url); }; /** Parses a string into a `UrlTree` */ Router.prototype.parseUrl = function (url) { var urlTree; try { urlTree = this.urlSerializer.parse(url); } catch (e) { urlTree = this.malformedUriErrorHandler(e, this.urlSerializer, url); } return urlTree; }; /** Returns whether the url is activated */ Router.prototype.isActive = function (url, exact) { if (url instanceof UrlTree) { return containsTree(this.currentUrlTree, url, exact); } var urlTree = this.parseUrl(url); return containsTree(this.currentUrlTree, urlTree, exact); }; Router.prototype.removeEmptyProps = function (params) { return Object.keys(params).reduce(function (result, key) { var value = params[key]; if (value !== null && value !== undefined) { result[key] = value; } return result; }, {}); }; Router.prototype.processNavigations = function () { var _this = this; this.navigations .pipe(operators.concatMap(function (nav) { if (nav) { _this.executeScheduledNavigation(nav); // a failed navigation should not stop the router from processing // further navigations => the catch return nav.promise.catch(function () { }); } else { return rxjs.of(null); } })) .subscribe(function () { }); }; Router.prototype.scheduleNavigation = function (rawUrl, source, state, extras) { var lastNavigation = this.navigations.value; // If the user triggers a navigation imperatively (e.g., by using navigateByUrl), // and that navigation results in 'replaceState' that leads to the same URL, // we should skip those. if (lastNavigation && source !== 'imperative' && lastNavigation.source === 'imperative' && lastNavigation.rawUrl.toString() === rawUrl.toString()) { return Promise.resolve(true); // return value is not used } // Because of a bug in IE and Edge, the location class fires two events (popstate and // hashchange) every single time. The second one should be ignored. Otherwise, the URL will // flicker. Handles the case when a popstate was emitted first. if (lastNavigation && source == 'hashchange' && lastNavigation.source === 'popstate' && lastNavigation.rawUrl.toString() === rawUrl.toString()) { return Promise.resolve(true); // return value is not used } // Because of a bug in IE and Edge, the location class fires two events (popstate and // hashchange) every single time. The second one should be ignored. Otherwise, the URL will // flicker. Handles the case when a hashchange was emitted first. if (lastNavigation && source == 'popstate' && lastNavigation.source === 'hashchange' && lastNavigation.rawUrl.toString() === rawUrl.toString()) { return Promise.resolve(true); // return value is not used } var resolve = null; var reject = null; var promise = new Promise(function (res, rej) { resolve = res; reject = rej; }); var id = ++this.navigationId; this.navigations.next({ id: id, source: source, state: state, rawUrl: rawUrl, extras: extras, resolve: resolve, reject: reject, promise: promise }); // Make sure that the error is propagated even though `processNavigations` catch // handler does not rethrow return promise.catch(function (e) { return Promise.reject(e); }); }; Router.prototype.executeScheduledNavigation = function (_a) { var _this = this; var id = _a.id, rawUrl = _a.rawUrl, extras = _a.extras, resolve = _a.resolve, reject = _a.reject, source = _a.source, state = _a.state; var url = this.urlHandlingStrategy.extract(rawUrl); var urlTransition = !this.navigated || url.toString() !== this.currentUrlTree.toString(); if ((this.onSameUrlNavigation === 'reload' ? true : urlTransition) && this.urlHandlingStrategy.shouldProcessUrl(rawUrl)) { this.events .next(new NavigationStart(id, this.serializeUrl(url), source, state)); Promise.resolve() .then(function (_) { return _this.runNavigate(url, rawUrl, !!extras.skipLocationChange, !!extras.replaceUrl, id, null); }) .then(resolve, reject); // we cannot process the current URL, but we could process the previous one => // we need to do some cleanup } else if (urlTransition && this.rawUrlTree && this.urlHandlingStrategy.shouldProcessUrl(this.rawUrlTree)) { this.events .next(new NavigationStart(id, this.serializeUrl(url), source, state)); Promise.resolve() .then(function (_) { return _this.runNavigate(url, rawUrl, false, false, id, createEmptyState(url, _this.rootComponentType).snapshot); }) .then(resolve, reject); } else { this.rawUrlTree = rawUrl; resolve(null); } }; Router.prototype.runNavigate = function (url, rawUrl, skipLocationChange, replaceUrl, id, precreatedState) { var _this = this; if (id !== this.navigationId) { this.events .next(new NavigationCancel(id, this.serializeUrl(url), "Navigation ID " + id + " is not equal to the current navigation id " + this.navigationId)); return Promise.resolve(false); } return new Promise(function (resolvePromise, rejectPromise) { // create an observable of the url and route state snapshot // this operation do not result in any side effects var urlAndSnapshot$; if (!precreatedState) { var moduleInjector = _this.ngModule.injector; var redirectsApplied$ = applyRedirects(moduleInjector, _this.configLoader, _this.urlSerializer, url, _this.config); urlAndSnapshot$ = redirectsApplied$.pipe(operators.mergeMap(function (appliedUrl) { return recognize(_this.rootComponentType, _this.config, appliedUrl, _this.serializeUrl(appliedUrl), _this.paramsInheritanceStrategy) .pipe(operators.map(function (snapshot) { _this.events .next(new RoutesRecognized(id, _this.serializeUrl(url), _this.serializeUrl(appliedUrl), snapshot)); return { appliedUrl: appliedUrl, snapshot: snapshot }; })); })); } else { urlAndSnapshot$ = rxjs.of({ appliedUrl: url, snapshot: precreatedState }); } var beforePreactivationDone$ = urlAndSnapshot$.pipe(operators.mergeMap(function (p) { if (typeof p === 'boolean') return rxjs.of(p); return _this.hooks.beforePreactivation(p.snapshot).pipe(operators.map(function () { return p; })); })); // run preactivation: guards and data resolvers var preActivation; var preactivationSetup$ = beforePreactivationDone$.pipe(operators.map(function (p) { if (typeof p === 'boolean') return p; var appliedUrl = p.appliedUrl, snapshot = p.snapshot; var moduleInjector = _this.ngModule.injector; preActivation = new PreActivation(snapshot, _this.routerState.snapshot, moduleInjector, function (evt) { return _this.triggerEvent(evt); }); preActivation.initialize(_this.rootContexts); return { appliedUrl: appliedUrl, snapshot: snapshot }; })); var preactivationCheckGuards$ = preactivationSetup$.pipe(operators.mergeMap(function (p) { if (typeof p === 'boolean' || _this.navigationId !== id) return rxjs.of(false); var appliedUrl = p.appliedUrl, snapshot = p.snapshot; _this.triggerEvent(new GuardsCheckStart(id, _this.serializeUrl(url), _this.serializeUrl(appliedUrl), snapshot)); return preActivation.checkGuards().pipe(operators.map(function (shouldActivate) { _this.triggerEvent(new GuardsCheckEnd(id, _this.serializeUrl(url), _this.serializeUrl(appliedUrl), snapshot, shouldActivate)); return { appliedUrl: appliedUrl, snapshot: snapshot, shouldActivate: shouldActivate }; })); })); var preactivationResolveData$ = preactivationCheckGuards$.pipe(operators.mergeMap(function (p) { if (typeof p === 'boolean' || _this.navigationId !== id) return rxjs.of(false); if (p.shouldActivate && preActivation.isActivating()) { _this.triggerEvent(new ResolveStart(id, _this.serializeUrl(url), _this.serializeUrl(p.appliedUrl), p.snapshot)); return preActivation.resolveData(_this.paramsInheritanceStrategy).pipe(operators.map(function () { _this.triggerEvent(new ResolveEnd(id, _this.serializeUrl(url), _this.serializeUrl(p.appliedUrl), p.snapshot)); return p; })); } else { return rxjs.of(p); } })); var preactivationDone$ = preactivationResolveData$.pipe(operators.mergeMap(function (p) { if (typeof p === 'boolean' || _this.navigationId !== id) return rxjs.of(false); return _this.hooks.afterPreactivation(p.snapshot).pipe(operators.map(function () { return p; })); })); // create router state // this operation has side effects => route state is being affected var routerState$ = preactivationDone$.pipe(operators.map(function (p) { if (typeof p === 'boolean' || _this.navigationId !== id) return false; var appliedUrl = p.appliedUrl, snapshot = p.snapshot, shouldActivate = p.shouldActivate; if (shouldActivate) { var state = createRouterState(_this.routeReuseStrategy, snapshot, _this.routerState); return { appliedUrl: appliedUrl, state: state, shouldActivate: shouldActivate }; } else { return { appliedUrl: appliedUrl, state: null, shouldActivate: shouldActivate }; } })); _this.activateRoutes(routerState$, _this.routerState, _this.currentUrlTree, id, url, rawUrl, skipLocationChange, replaceUrl, resolvePromise, rejectPromise); }); }; /** * Performs the logic of activating routes. This is a synchronous process by default. While this * is a private method, it could be overridden to make activation asynchronous. */ Router.prototype.activateRoutes = function (state, storedState, storedUrl, id, url, rawUrl, skipLocationChange, replaceUrl, resolvePromise, rejectPromise) { var _this = this; // applied the new router state // this operation has side effects var navigationIsSuccessful; state .forEach(function (p) { if (typeof p === 'boolean' || !p.shouldActivate || id !== _this.navigationId || !p.state) { navigationIsSuccessful = false; return; } var appliedUrl = p.appliedUrl, state = p.state; _this.currentUrlTree = appliedUrl; _this.rawUrlTree = _this.urlHandlingStrategy.merge(_this.currentUrlTree, rawUrl); _this.routerState = state; if (!skipLocationChange) { var path = _this.urlSerializer.serialize(_this.rawUrlTree); if (_this.location.isCurrentPathEqualTo(path) || replaceUrl) { _this.location.replaceState(path, '', { navigationId: id }); } else { _this.location.go(path, '', { navigationId: id }); } } new ActivateRoutes(_this.routeReuseStrategy, state, storedState, function (evt) { return _this.triggerEvent(evt); }) .activate(_this.rootContexts); navigationIsSuccessful = true; }) .then(function () { if (navigationIsSuccessful) { _this.navigated = true; _this.lastSuccessfulId = id; _this.events .next(new NavigationEnd(id, _this.serializeUrl(url), _this.serializeUrl(_this.currentUrlTree))); resolvePromise(true); } else { _this.resetUrlToCurrentUrlTree(); _this.events .next(new NavigationCancel(id, _this.serializeUrl(url), '')); resolvePromise(false); } }, function (e) { if (isNavigationCancelingError(e)) { _this.navigated = true; _this.resetStateAndUrl(storedState, storedUrl, rawUrl); _this.events .next(new NavigationCancel(id, _this.serializeUrl(url), e.message)); resolvePromise(false); } else { _this.resetStateAndUrl(storedState, storedUrl, rawUrl); _this.events .next(new NavigationError(id, _this.serializeUrl(url), e)); try { resolvePromise(_this.errorHandler(e)); } catch (ee) { rejectPromise(ee); } } }); }; Router.prototype.resetStateAndUrl = function (storedState, storedUrl, rawUrl) { this.routerState = storedState; this.currentUrlTree = storedUrl; this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, rawUrl); this.resetUrlToCurrentUrlTree(); }; Router.prototype.resetUrlToCurrentUrlTree = function () { this.location.replaceState(this.urlSerializer.serialize(this.rawUrlTree), '', { navigationId: this.lastSuccessfulId }); }; return Router; }()); var ActivateRoutes = /** @class */ (function () { function ActivateRoutes(routeReuseStrategy, futureState, currState, forwardEvent) { this.routeReuseStrategy = routeReuseStrategy; this.futureState = futureState; this.currState = currState; this.forwardEvent = forwardEvent; } ActivateRoutes.prototype.activate = function (parentContexts) { var futureRoot = this.futureState._root; var currRoot = this.currState ? this.currState._root : null; this.deactivateChildRoutes(futureRoot, currRoot, parentContexts); advanceActivatedRoute(this.futureState.root); this.activateChildRoutes(futureRoot, currRoot, parentContexts); }; // De-activate the child route that are not re-used for the future state ActivateRoutes.prototype.deactivateChildRoutes = function (futureNode, currNode, contexts) { var _this = this; var children = nodeChildrenAsMap(currNode); // Recurse on the routes active in the future state to de-activate deeper children futureNode.children.forEach(function (futureChild) { var childOutletName = futureChild.value.outlet; _this.deactivateRoutes(futureChild, children[childOutletName], contexts); delete children[childOutletName]; }); // De-activate the routes that will not be re-used forEach(children, function (v, childName) { _this.deactivateRouteAndItsChildren(v, contexts); }); }; ActivateRoutes.prototype.deactivateRoutes = function (futureNode, currNode, parentContext) { var future = futureNode.value; var curr = currNode ? currNode.value : null; if (future === curr) { // Reusing the node, check to see if the children need to be de-activated if (future.component) { // If we have a normal route, we need to go through an outlet. var context = parentContext.getContext(future.outlet); if (context) { this.deactivateChildRoutes(futureNode, currNode, context.children); } } else { // if we have a componentless route, we recurse but keep the same outlet map. this.deactivateChildRoutes(futureNode, currNode, parentContext); } } else { if (curr) { // Deactivate the current route which will not be re-used this.deactivateRouteAndItsChildren(currNode, parentContext); } } }; ActivateRoutes.prototype.deactivateRouteAndItsChildren = function (route, parentContexts) { if (this.routeReuseStrategy.shouldDetach(route.value.snapshot)) { this.detachAndStoreRouteSubtree(route, parentContexts); } else { this.deactivateRouteAndOutlet(route, parentContexts); } }; ActivateRoutes.prototype.detachAndStoreRouteSubtree = function (route, parentContexts) { var context = parentContexts.getContext(route.value.outlet); if (context && context.outlet) { var componentRef = context.outlet.detach(); var contexts = context.children.onOutletDeactivated(); this.routeReuseStrategy.store(route.value.snapshot, { componentRef: componentRef, route: route, contexts: contexts }); } }; ActivateRoutes.prototype.deactivateRouteAndOutlet = function (route, parentContexts) { var _this = this; var context = parentContexts.getContext(route.value.outlet); if (context) { var children = nodeChildrenAsMap(route); var contexts_1 = route.value.component ? context.children : parentContexts; forEach(children, function (v, k) { return _this.deactivateRouteAndItsChildren(v, contexts_1); }); if (context.outlet) { // Destroy the component context.outlet.deactivate(); // Destroy the contexts for all the outlets that were in the component context.children.onOutletDeactivated(); } } }; ActivateRoutes.prototype.activateChildRoutes = function (futureNode, currNode, contexts) { var _this = this; var children = nodeChildrenAsMap(currNode); futureNode.children.forEach(function (c) { _this.activateRoutes(c, children[c.value.outlet], contexts); _this.forwardEvent(new ActivationEnd(c.value.snapshot)); }); if (futureNode.children.length) { this.forwardEvent(new ChildActivationEnd(futureNode.value.snapshot)); } }; ActivateRoutes.prototype.activateRoutes = function (futureNode, currNode, parentContexts) { var future = futureNode.value; var curr = currNode ? currNode.value : null; advanceActivatedRoute(future); // reusing the node if (future === curr) { if (future.component) { // If we have a normal route, we need to go through an outlet. var context = parentContexts.getOrCreateContext(future.outlet); this.activateChildRoutes(futureNode, currNode, context.children); } else { // if we have a componentless route, we recurse but keep the same outlet map. this.activateChildRoutes(futureNode, currNode, parentContexts); } } else { if (future.component) { // if we have a normal route, we need to place the component into the outlet and recurse. var context = parentContexts.getOrCreateContext(future.outlet); if (this.routeReuseStrategy.shouldAttach(future.snapshot)) { var stored = this.routeReuseStrategy.retrieve(future.snapshot); this.routeReuseStrategy.store(future.snapshot, null); context.children.onOutletReAttached(stored.contexts); context.attachRef = stored.componentRef; context.route = stored.route.value; if (context.outlet) { // Attach right away when the outlet has already been instantiated // Otherwise attach from `RouterOutlet.ngOnInit` when it is instantiated context.outlet.attach(stored.componentRef, stored.route.value); } advanceActivatedRouteNodeAndItsChildren(stored.route); } else { var config = parentLoadedConfig(future.snapshot); var cmpFactoryResolver = config ? config.module.componentFactoryResolver : null; context.route = future; context.resolver = cmpFactoryResolver; if (context.outlet) { // Activate the outlet when it has already been instantiated // Otherwise it will get activated from its `ngOnInit` when instantiated context.outlet.activateWith(future, cmpFactoryResolver); } this.activateChildRoutes(futureNode, null, context.children); } } else { // if we have a componentless route, we recurse but keep the same outlet map. this.activateChildRoutes(futureNode, null, parentContexts); } } }; return ActivateRoutes; }()); function advanceActivatedRouteNodeAndItsChildren(node) { advanceActivatedRoute(node.value); node.children.forEach(advanceActivatedRouteNodeAndItsChildren); } function parentLoadedConfig(snapshot) { for (var s = snapshot.parent; s; s = s.parent) { var route = s.routeConfig; if (route && route._loadedConfig) return route._loadedConfig; if (route && route.component) return null; } return null; } function validateCommands(commands) { for (var i = 0; i < commands.length; i++) { var cmd = commands[i]; if (cmd == null) { throw new Error("The requested path contains " + cmd + " segment at index " + i); } } } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @description * * Lets you link to specific routes in your app. * * Consider the following route configuration: * `[{ path: 'user/:name', component: UserCmp }]`. * When linking to this `user/:name` route, you use the `RouterLink` directive. * * If the link is static, you can use the directive as follows: * `link to user component` * * If you use dynamic values to generate the link, you can pass an array of path * segments, followed by the params for each segment. * * For instance `['/team', teamId, 'user', userName, {details: true}]` * means that we want to generate a link to `/team/11/user/bob;details=true`. * * Multiple static segments can be merged into one * (e.g., `['/team/11/user', userName, {details: true}]`). * * The first segment name can be prepended with `/`, `./`, or `../`: * * If the first segment begins with `/`, the router will look up the route from the root of the * app. * * If the first segment begins with `./`, or doesn't begin with a slash, the router will * instead look in the children of the current activated route. * * And if the first segment begins with `../`, the router will go up one level. * * You can set query params and fragment as follows: * * ``` * * link to user component * * ``` * RouterLink will use these to generate this link: `/user/bob#education?debug=true`. * * (Deprecated in v4.0.0 use `queryParamsHandling` instead) You can also tell the * directive to preserve the current query params and fragment: * * ``` * * link to user component * * ``` * * You can tell the directive to how to handle queryParams, available options are: * - `'merge'`: merge the queryParams into the current queryParams * - `'preserve'`: preserve the current queryParams * - default/`''`: use the queryParams only * * Same options for {@link NavigationExtras#queryParamsHandling * NavigationExtras#queryParamsHandling}. * * ``` * * link to user component * * ``` * * The router link directive always treats the provided input as a delta to the current url. * * For instance, if the current url is `/user/(box//aux:team)`. * * Then the following link `Jim` will generate the link * `/user/(jim//aux:team)`. * * See {@link Router#createUrlTree createUrlTree} for more information. * * @ngModule RouterModule * * */ var RouterLink = /** @class */ (function () { function RouterLink(router, route, tabIndex, renderer, el) { this.router = router; this.route = route; this.commands = []; if (tabIndex == null) { renderer.setAttribute(el.nativeElement, 'tabindex', '0'); } } Object.defineProperty(RouterLink.prototype, "routerLink", { set: function (commands) { if (commands != null) { this.commands = Array.isArray(commands) ? commands : [commands]; } else { this.commands = []; } }, enumerable: true, configurable: true }); Object.defineProperty(RouterLink.prototype, "preserveQueryParams", { /** * @deprecated 4.0.0 use `queryParamsHandling` instead. */ set: function (value) { if (core.isDevMode() && console && console.warn) { console.warn('preserveQueryParams is deprecated!, use queryParamsHandling instead.'); } this.preserve = value; }, enumerable: true, configurable: true }); RouterLink.prototype.onClick = function () { var extras = { skipLocationChange: attrBoolValue(this.skipLocationChange), replaceUrl: attrBoolValue(this.replaceUrl), }; this.router.navigateByUrl(this.urlTree, extras); return true; }; Object.defineProperty(RouterLink.prototype, "urlTree", { get: function () { return this.router.createUrlTree(this.commands, { relativeTo: this.route, queryParams: this.queryParams, fragment: this.fragment, preserveQueryParams: attrBoolValue(this.preserve), queryParamsHandling: this.queryParamsHandling, preserveFragment: attrBoolValue(this.preserveFragment), }); }, enumerable: true, configurable: true }); RouterLink.decorators = [ { type: core.Directive, args: [{ selector: ':not(a)[routerLink]' },] } ]; /** @nocollapse */ RouterLink.ctorParameters = function () { return [ { type: Router }, { type: ActivatedRoute }, { type: String, decorators: [{ type: core.Attribute, args: ['tabindex',] }] }, { type: core.Renderer2 }, { type: core.ElementRef } ]; }; RouterLink.propDecorators = { queryParams: [{ type: core.Input }], fragment: [{ type: core.Input }], queryParamsHandling: [{ type: core.Input }], preserveFragment: [{ type: core.Input }], skipLocationChange: [{ type: core.Input }], replaceUrl: [{ type: core.Input }], routerLink: [{ type: core.Input }], preserveQueryParams: [{ type: core.Input }], onClick: [{ type: core.HostListener, args: ['click',] }] }; return RouterLink; }()); /** * @description * * Lets you link to specific routes in your app. * * See `RouterLink` for more information. * * @ngModule RouterModule * * */ var RouterLinkWithHref = /** @class */ (function () { function RouterLinkWithHref(router, route, locationStrategy) { var _this = this; this.router = router; this.route = route; this.locationStrategy = locationStrategy; this.commands = []; this.subscription = router.events.subscribe(function (s) { if (s instanceof NavigationEnd) { _this.updateTargetUrlAndHref(); } }); } Object.defineProperty(RouterLinkWithHref.prototype, "routerLink", { set: function (commands) { if (commands != null) { this.commands = Array.isArray(commands) ? commands : [commands]; } else { this.commands = []; } }, enumerable: true, configurable: true }); Object.defineProperty(RouterLinkWithHref.prototype, "preserveQueryParams", { set: function (value) { if (core.isDevMode() && console && console.warn) { console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.'); } this.preserve = value; }, enumerable: true, configurable: true }); RouterLinkWithHref.prototype.ngOnChanges = function (changes) { this.updateTargetUrlAndHref(); }; RouterLinkWithHref.prototype.ngOnDestroy = function () { this.subscription.unsubscribe(); }; RouterLinkWithHref.prototype.onClick = function (button, ctrlKey, metaKey, shiftKey) { if (button !== 0 || ctrlKey || metaKey || shiftKey) { return true; } if (typeof this.target === 'string' && this.target != '_self') { return true; } var extras = { skipLocationChange: attrBoolValue(this.skipLocationChange), replaceUrl: attrBoolValue(this.replaceUrl), }; this.router.navigateByUrl(this.urlTree, extras); return false; }; RouterLinkWithHref.prototype.updateTargetUrlAndHref = function () { this.href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.urlTree)); }; Object.defineProperty(RouterLinkWithHref.prototype, "urlTree", { get: function () { return this.router.createUrlTree(this.commands, { relativeTo: this.route, queryParams: this.queryParams, fragment: this.fragment, preserveQueryParams: attrBoolValue(this.preserve), queryParamsHandling: this.queryParamsHandling, preserveFragment: attrBoolValue(this.preserveFragment), }); }, enumerable: true, configurable: true }); RouterLinkWithHref.decorators = [ { type: core.Directive, args: [{ selector: 'a[routerLink]' },] } ]; /** @nocollapse */ RouterLinkWithHref.ctorParameters = function () { return [ { type: Router }, { type: ActivatedRoute }, { type: common.LocationStrategy } ]; }; RouterLinkWithHref.propDecorators = { target: [{ type: core.HostBinding, args: ['attr.target',] }, { type: core.Input }], queryParams: [{ type: core.Input }], fragment: [{ type: core.Input }], queryParamsHandling: [{ type: core.Input }], preserveFragment: [{ type: core.Input }], skipLocationChange: [{ type: core.Input }], replaceUrl: [{ type: core.Input }], href: [{ type: core.HostBinding }], routerLink: [{ type: core.Input }], preserveQueryParams: [{ type: core.Input }], onClick: [{ type: core.HostListener, args: ['click', ['$event.button', '$event.ctrlKey', '$event.metaKey', '$event.shiftKey'],] }] }; return RouterLinkWithHref; }()); function attrBoolValue(s) { return s === '' || !!s; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * * @description * * Lets you add a CSS class to an element when the link's route becomes active. * * This directive lets you add a CSS class to an element when the link's route * becomes active. * * Consider the following example: * * ``` * Bob * ``` * * When the url is either '/user' or '/user/bob', the active-link class will * be added to the `a` tag. If the url changes, the class will be removed. * * You can set more than one class, as follows: * * ``` * Bob * Bob * ``` * * You can configure RouterLinkActive by passing `exact: true`. This will add the classes * only when the url matches the link exactly. * * ``` * Bob * ``` * * You can assign the RouterLinkActive instance to a template variable and directly check * the `isActive` status. * ``` * * Bob {{ rla.isActive ? '(already open)' : ''}} * * ``` * * Finally, you can apply the RouterLinkActive directive to an ancestor of a RouterLink. * * ``` *
* Jim * Bob *
* ``` * * This will set the active-link class on the div tag if the url is either '/user/jim' or * '/user/bob'. * * @ngModule RouterModule * * */ var RouterLinkActive = /** @class */ (function () { function RouterLinkActive(router, element, renderer, cdr) { var _this = this; this.router = router; this.element = element; this.renderer = renderer; this.cdr = cdr; this.classes = []; this.isActive = false; this.routerLinkActiveOptions = { exact: false }; this.subscription = router.events.subscribe(function (s) { if (s instanceof NavigationEnd) { _this.update(); } }); } RouterLinkActive.prototype.ngAfterContentInit = function () { var _this = this; this.links.changes.subscribe(function (_) { return _this.update(); }); this.linksWithHrefs.changes.subscribe(function (_) { return _this.update(); }); this.update(); }; Object.defineProperty(RouterLinkActive.prototype, "routerLinkActive", { set: function (data) { var classes = Array.isArray(data) ? data : data.split(' '); this.classes = classes.filter(function (c) { return !!c; }); }, enumerable: true, configurable: true }); RouterLinkActive.prototype.ngOnChanges = function (changes) { this.update(); }; RouterLinkActive.prototype.ngOnDestroy = function () { this.subscription.unsubscribe(); }; RouterLinkActive.prototype.update = function () { var _this = this; if (!this.links || !this.linksWithHrefs || !this.router.navigated) return; Promise.resolve().then(function () { var hasActiveLinks = _this.hasActiveLinks(); if (_this.isActive !== hasActiveLinks) { _this.isActive = hasActiveLinks; _this.classes.forEach(function (c) { if (hasActiveLinks) { _this.renderer.addClass(_this.element.nativeElement, c); } else { _this.renderer.removeClass(_this.element.nativeElement, c); } }); } }); }; RouterLinkActive.prototype.isLinkActive = function (router) { var _this = this; return function (link) { return router.isActive(link.urlTree, _this.routerLinkActiveOptions.exact); }; }; RouterLinkActive.prototype.hasActiveLinks = function () { return this.links.some(this.isLinkActive(this.router)) || this.linksWithHrefs.some(this.isLinkActive(this.router)); }; RouterLinkActive.decorators = [ { type: core.Directive, args: [{ selector: '[routerLinkActive]', exportAs: 'routerLinkActive', },] } ]; /** @nocollapse */ RouterLinkActive.ctorParameters = function () { return [ { type: Router }, { type: core.ElementRef }, { type: core.Renderer2 }, { type: core.ChangeDetectorRef } ]; }; RouterLinkActive.propDecorators = { links: [{ type: core.ContentChildren, args: [RouterLink, { descendants: true },] }], linksWithHrefs: [{ type: core.ContentChildren, args: [RouterLinkWithHref, { descendants: true },] }], routerLinkActiveOptions: [{ type: core.Input }], routerLinkActive: [{ type: core.Input }] }; return RouterLinkActive; }()); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Store contextual information about a `RouterOutlet` * * */ var OutletContext = /** @class */ (function () { function OutletContext() { this.outlet = null; this.route = null; this.resolver = null; this.children = new ChildrenOutletContexts(); this.attachRef = null; } return OutletContext; }()); /** * Store contextual information about the children (= nested) `RouterOutlet` * * */ var ChildrenOutletContexts = /** @class */ (function () { function ChildrenOutletContexts() { // contexts for child outlets, by name. this.contexts = new Map(); } /** Called when a `RouterOutlet` directive is instantiated */ ChildrenOutletContexts.prototype.onChildOutletCreated = function (childName, outlet) { var context = this.getOrCreateContext(childName); context.outlet = outlet; this.contexts.set(childName, context); }; /** * Called when a `RouterOutlet` directive is destroyed. * We need to keep the context as the outlet could be destroyed inside a NgIf and might be * re-created later. */ ChildrenOutletContexts.prototype.onChildOutletDestroyed = function (childName) { var context = this.getContext(childName); if (context) { context.outlet = null; } }; /** * Called when the corresponding route is deactivated during navigation. * Because the component get destroyed, all children outlet are destroyed. */ ChildrenOutletContexts.prototype.onOutletDeactivated = function () { var contexts = this.contexts; this.contexts = new Map(); return contexts; }; ChildrenOutletContexts.prototype.onOutletReAttached = function (contexts) { this.contexts = contexts; }; ChildrenOutletContexts.prototype.getOrCreateContext = function (childName) { var context = this.getContext(childName); if (!context) { context = new OutletContext(); this.contexts.set(childName, context); } return context; }; ChildrenOutletContexts.prototype.getContext = function (childName) { return this.contexts.get(childName) || null; }; return ChildrenOutletContexts; }()); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @description * * Acts as a placeholder that Angular dynamically fills based on the current router state. * * ``` * * * * ``` * * A router outlet will emit an activate event any time a new component is being instantiated, * and a deactivate event when it is being destroyed. * * ``` * * ``` * @ngModule RouterModule * * */ var RouterOutlet = /** @class */ (function () { function RouterOutlet(parentContexts, location, resolver, name, changeDetector) { this.parentContexts = parentContexts; this.location = location; this.resolver = resolver; this.changeDetector = changeDetector; this.activated = null; this._activatedRoute = null; this.activateEvents = new core.EventEmitter(); this.deactivateEvents = new core.EventEmitter(); this.name = name || PRIMARY_OUTLET; parentContexts.onChildOutletCreated(this.name, this); } RouterOutlet.prototype.ngOnDestroy = function () { this.parentContexts.onChildOutletDestroyed(this.name); }; RouterOutlet.prototype.ngOnInit = function () { if (!this.activated) { // If the outlet was not instantiated at the time the route got activated we need to populate // the outlet when it is initialized (ie inside a NgIf) var context = this.parentContexts.getContext(this.name); if (context && context.route) { if (context.attachRef) { // `attachRef` is populated when there is an existing component to mount this.attach(context.attachRef, context.route); } else { // otherwise the component defined in the configuration is created this.activateWith(context.route, context.resolver || null); } } } }; Object.defineProperty(RouterOutlet.prototype, "isActivated", { get: function () { return !!this.activated; }, enumerable: true, configurable: true }); Object.defineProperty(RouterOutlet.prototype, "component", { get: function () { if (!this.activated) throw new Error('Outlet is not activated'); return this.activated.instance; }, enumerable: true, configurable: true }); Object.defineProperty(RouterOutlet.prototype, "activatedRoute", { get: function () { if (!this.activated) throw new Error('Outlet is not activated'); return this._activatedRoute; }, enumerable: true, configurable: true }); Object.defineProperty(RouterOutlet.prototype, "activatedRouteData", { get: function () { if (this._activatedRoute) { return this._activatedRoute.snapshot.data; } return {}; }, enumerable: true, configurable: true }); /** * Called when the `RouteReuseStrategy` instructs to detach the subtree */ RouterOutlet.prototype.detach = function () { if (!this.activated) throw new Error('Outlet is not activated'); this.location.detach(); var cmp = this.activated; this.activated = null; this._activatedRoute = null; return cmp; }; /** * Called when the `RouteReuseStrategy` instructs to re-attach a previously detached subtree */ RouterOutlet.prototype.attach = function (ref, activatedRoute) { this.activated = ref; this._activatedRoute = activatedRoute; this.location.insert(ref.hostView); }; RouterOutlet.prototype.deactivate = function () { if (this.activated) { var c = this.component; this.activated.destroy(); this.activated = null; this._activatedRoute = null; this.deactivateEvents.emit(c); } }; RouterOutlet.prototype.activateWith = function (activatedRoute, resolver) { if (this.isActivated) { throw new Error('Cannot activate an already activated outlet'); } this._activatedRoute = activatedRoute; var snapshot = activatedRoute._futureSnapshot; var component = snapshot.routeConfig.component; resolver = resolver || this.resolver; var factory = resolver.resolveComponentFactory(component); var childContexts = this.parentContexts.getOrCreateContext(this.name).children; var injector = new OutletInjector(activatedRoute, childContexts, this.location.injector); this.activated = this.location.createComponent(factory, this.location.length, injector); // Calling `markForCheck` to make sure we will run the change detection when the // `RouterOutlet` is inside a `ChangeDetectionStrategy.OnPush` component. this.changeDetector.markForCheck(); this.activateEvents.emit(this.activated.instance); }; RouterOutlet.decorators = [ { type: core.Directive, args: [{ selector: 'router-outlet', exportAs: 'outlet' },] } ]; /** @nocollapse */ RouterOutlet.ctorParameters = function () { return [ { type: ChildrenOutletContexts }, { type: core.ViewContainerRef }, { type: core.ComponentFactoryResolver }, { type: String, decorators: [{ type: core.Attribute, args: ['name',] }] }, { type: core.ChangeDetectorRef } ]; }; RouterOutlet.propDecorators = { activateEvents: [{ type: core.Output, args: ['activate',] }], deactivateEvents: [{ type: core.Output, args: ['deactivate',] }] }; return RouterOutlet; }()); var OutletInjector = /** @class */ (function () { function OutletInjector(route, childContexts, parent) { this.route = route; this.childContexts = childContexts; this.parent = parent; } OutletInjector.prototype.get = function (token, notFoundValue) { if (token === ActivatedRoute) { return this.route; } if (token === ChildrenOutletContexts) { return this.childContexts; } return this.parent.get(token, notFoundValue); }; return OutletInjector; }()); /** *@license *Copyright Google Inc. All Rights Reserved. * *Use of this source code is governed by an MIT-style license that can be *found in the LICENSE file at https://angular.io/license */ /** * @description * * Provides a preloading strategy. * * @experimental */ var PreloadingStrategy = /** @class */ (function () { function PreloadingStrategy() { } return PreloadingStrategy; }()); /** * @description * * Provides a preloading strategy that preloads all modules as quickly as possible. * * ``` * RouteModule.forRoot(ROUTES, {preloadingStrategy: PreloadAllModules}) * ``` * * @experimental */ var PreloadAllModules = /** @class */ (function () { function PreloadAllModules() { } PreloadAllModules.prototype.preload = function (route, fn) { return fn().pipe(operators.catchError(function () { return rxjs.of(null); })); }; return PreloadAllModules; }()); /** * @description * * Provides a preloading strategy that does not preload any modules. * * This strategy is enabled by default. * * @experimental */ var NoPreloading = /** @class */ (function () { function NoPreloading() { } NoPreloading.prototype.preload = function (route, fn) { return rxjs.of(null); }; return NoPreloading; }()); /** * The preloader optimistically loads all router configurations to * make navigations into lazily-loaded sections of the application faster. * * The preloader runs in the background. When the router bootstraps, the preloader * starts listening to all navigation events. After every such event, the preloader * will check if any configurations can be loaded lazily. * * If a route is protected by `canLoad` guards, the preloaded will not load it. * * */ var RouterPreloader = /** @class */ (function () { function RouterPreloader(router, moduleLoader, compiler, injector, preloadingStrategy) { this.router = router; this.injector = injector; this.preloadingStrategy = preloadingStrategy; var onStartLoad = function (r) { return router.triggerEvent(new RouteConfigLoadStart(r)); }; var onEndLoad = function (r) { return router.triggerEvent(new RouteConfigLoadEnd(r)); }; this.loader = new RouterConfigLoader(moduleLoader, compiler, onStartLoad, onEndLoad); } RouterPreloader.prototype.setUpPreloading = function () { var _this = this; this.subscription = this.router.events .pipe(operators.filter(function (e) { return e instanceof NavigationEnd; }), operators.concatMap(function () { return _this.preload(); })) .subscribe(function () { }); }; RouterPreloader.prototype.preload = function () { var ngModule = this.injector.get(core.NgModuleRef); return this.processRoutes(ngModule, this.router.config); }; // TODO(jasonaden): This class relies on code external to the class to call setUpPreloading. If // this hasn't been done, ngOnDestroy will fail as this.subscription will be undefined. This // should be refactored. RouterPreloader.prototype.ngOnDestroy = function () { this.subscription.unsubscribe(); }; RouterPreloader.prototype.processRoutes = function (ngModule, routes) { var res = []; try { for (var routes_1 = __values(routes), routes_1_1 = routes_1.next(); !routes_1_1.done; routes_1_1 = routes_1.next()) { var route = routes_1_1.value; // we already have the config loaded, just recurse if (route.loadChildren && !route.canLoad && route._loadedConfig) { var childConfig = route._loadedConfig; res.push(this.processRoutes(childConfig.module, childConfig.routes)); // no config loaded, fetch the config } else if (route.loadChildren && !route.canLoad) { res.push(this.preloadConfig(ngModule, route)); // recurse into children } else if (route.children) { res.push(this.processRoutes(ngModule, route.children)); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1); } finally { if (e_1) throw e_1.error; } } return rxjs.from(res).pipe(operators.mergeAll(), operators.map(function (_) { return void 0; })); var e_1, _a; }; RouterPreloader.prototype.preloadConfig = function (ngModule, route) { var _this = this; return this.preloadingStrategy.preload(route, function () { var loaded$ = _this.loader.load(ngModule.injector, route); return loaded$.pipe(operators.mergeMap(function (config) { route._loadedConfig = config; return _this.processRoutes(config.module, config.routes); })); }); }; RouterPreloader.decorators = [ { type: core.Injectable } ]; /** @nocollapse */ RouterPreloader.ctorParameters = function () { return [ { type: Router }, { type: core.NgModuleFactoryLoader }, { type: core.Compiler }, { type: core.Injector }, { type: PreloadingStrategy } ]; }; return RouterPreloader; }()); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @description * * Contains a list of directives * * */ var ROUTER_DIRECTIVES = [RouterOutlet, RouterLink, RouterLinkWithHref, RouterLinkActive, EmptyOutletComponent]; /** * @description * * Is used in DI to configure the router. * * */ var ROUTER_CONFIGURATION = new core.InjectionToken('ROUTER_CONFIGURATION'); /** * @docsNotRequired */ var ROUTER_FORROOT_GUARD = new core.InjectionToken('ROUTER_FORROOT_GUARD'); var ROUTER_PROVIDERS = [ common.Location, { provide: UrlSerializer, useClass: DefaultUrlSerializer }, { provide: Router, useFactory: setupRouter, deps: [ core.ApplicationRef, UrlSerializer, ChildrenOutletContexts, common.Location, core.Injector, core.NgModuleFactoryLoader, core.Compiler, ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new core.Optional()], [RouteReuseStrategy, new core.Optional()] ] }, ChildrenOutletContexts, { provide: ActivatedRoute, useFactory: rootRoute, deps: [Router] }, { provide: core.NgModuleFactoryLoader, useClass: core.SystemJsNgModuleLoader }, RouterPreloader, NoPreloading, PreloadAllModules, { provide: ROUTER_CONFIGURATION, useValue: { enableTracing: false } }, ]; function routerNgProbeToken() { return new core.NgProbeToken('Router', Router); } /** * @usageNotes * * RouterModule can be imported multiple times: once per lazily-loaded bundle. * Since the router deals with a global shared resource--location, we cannot have * more than one router service active. * * That is why there are two ways to create the module: `RouterModule.forRoot` and * `RouterModule.forChild`. * * * `forRoot` creates a module that contains all the directives, the given routes, and the router * service itself. * * `forChild` creates a module that contains all the directives and the given routes, but does not * include the router service. * * When registered at the root, the module should be used as follows * * ``` * @NgModule({ * imports: [RouterModule.forRoot(ROUTES)] * }) * class MyNgModule {} * ``` * * For submodules and lazy loaded submodules the module should be used as follows: * * ``` * @NgModule({ * imports: [RouterModule.forChild(ROUTES)] * }) * class MyNgModule {} * ``` * * @description * * Adds router directives and providers. * * Managing state transitions is one of the hardest parts of building applications. This is * especially true on the web, where you also need to ensure that the state is reflected in the URL. * In addition, we often want to split applications into multiple bundles and load them on demand. * Doing this transparently is not trivial. * * The Angular router solves these problems. Using the router, you can declaratively specify * application states, manage state transitions while taking care of the URL, and load bundles on * demand. * * [Read this developer guide](https://angular.io/docs/ts/latest/guide/router.html) to get an * overview of how the router should be used. * * */ var RouterModule = /** @class */ (function () { // Note: We are injecting the Router so it gets created eagerly... function RouterModule(guard, router) { } /** * Creates a module with all the router providers and directives. It also optionally sets up an * application listener to perform an initial navigation. * * Options (see `ExtraOptions`): * * `enableTracing` makes the router log all its internal events to the console. * * `useHash` enables the location strategy that uses the URL fragment instead of the history * API. * * `initialNavigation` disables the initial navigation. * * `errorHandler` provides a custom error handler. * * `preloadingStrategy` configures a preloading strategy (see `PreloadAllModules`). * * `onSameUrlNavigation` configures how the router handles navigation to the current URL. See * `ExtraOptions` for more details. * * `paramsInheritanceStrategy` defines how the router merges params, data and resolved data * from parent to child routes. */ RouterModule.forRoot = function (routes, config) { return { ngModule: RouterModule, providers: [ ROUTER_PROVIDERS, provideRoutes(routes), { provide: ROUTER_FORROOT_GUARD, useFactory: provideForRootGuard, deps: [[Router, new core.Optional(), new core.SkipSelf()]] }, { provide: ROUTER_CONFIGURATION, useValue: config ? config : {} }, { provide: common.LocationStrategy, useFactory: provideLocationStrategy, deps: [ common.PlatformLocation, [new core.Inject(common.APP_BASE_HREF), new core.Optional()], ROUTER_CONFIGURATION ] }, { provide: PreloadingStrategy, useExisting: config && config.preloadingStrategy ? config.preloadingStrategy : NoPreloading }, { provide: core.NgProbeToken, multi: true, useFactory: routerNgProbeToken }, provideRouterInitializer(), ], }; }; /** * Creates a module with all the router directives and a provider registering routes. */ RouterModule.forChild = function (routes) { return { ngModule: RouterModule, providers: [provideRoutes(routes)] }; }; RouterModule.decorators = [ { type: core.NgModule, args: [{ declarations: ROUTER_DIRECTIVES, exports: ROUTER_DIRECTIVES, entryComponents: [EmptyOutletComponent] },] } ]; /** @nocollapse */ RouterModule.ctorParameters = function () { return [ { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [ROUTER_FORROOT_GUARD,] }] }, { type: Router, decorators: [{ type: core.Optional }] } ]; }; return RouterModule; }()); function provideLocationStrategy(platformLocationStrategy, baseHref, options) { if (options === void 0) { options = {}; } return options.useHash ? new common.HashLocationStrategy(platformLocationStrategy, baseHref) : new common.PathLocationStrategy(platformLocationStrategy, baseHref); } function provideForRootGuard(router) { if (router) { throw new Error("RouterModule.forRoot() called twice. Lazy loaded modules should use RouterModule.forChild() instead."); } return 'guarded'; } /** * @description * * Registers routes. * * ### Example * * ``` * @NgModule({ * imports: [RouterModule.forChild(ROUTES)], * providers: [provideRoutes(EXTRA_ROUTES)] * }) * class MyNgModule {} * ``` * * */ function provideRoutes(routes) { return [ { provide: core.ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes }, { provide: ROUTES, multi: true, useValue: routes }, ]; } function setupRouter(ref, urlSerializer, contexts, location, injector, loader, compiler, config, opts, urlHandlingStrategy, routeReuseStrategy) { if (opts === void 0) { opts = {}; } var router = new Router(null, urlSerializer, contexts, location, injector, loader, compiler, flatten(config)); if (urlHandlingStrategy) { router.urlHandlingStrategy = urlHandlingStrategy; } if (routeReuseStrategy) { router.routeReuseStrategy = routeReuseStrategy; } if (opts.errorHandler) { router.errorHandler = opts.errorHandler; } if (opts.malformedUriErrorHandler) { router.malformedUriErrorHandler = opts.malformedUriErrorHandler; } if (opts.enableTracing) { var dom_1 = platformBrowser.ɵgetDOM(); router.events.subscribe(function (e) { dom_1.logGroup("Router Event: " + e.constructor.name); dom_1.log(e.toString()); dom_1.log(e); dom_1.logGroupEnd(); }); } if (opts.onSameUrlNavigation) { router.onSameUrlNavigation = opts.onSameUrlNavigation; } if (opts.paramsInheritanceStrategy) { router.paramsInheritanceStrategy = opts.paramsInheritanceStrategy; } return router; } function rootRoute(router) { return router.routerState.root; } /** * To initialize the router properly we need to do in two steps: * * We need to start the navigation in a APP_INITIALIZER to block the bootstrap if * a resolver or a guards executes asynchronously. Second, we need to actually run * activation in a BOOTSTRAP_LISTENER. We utilize the afterPreactivation * hook provided by the router to do that. * * The router navigation starts, reaches the point when preactivation is done, and then * pauses. It waits for the hook to be resolved. We then resolve it only in a bootstrap listener. */ var RouterInitializer = /** @class */ (function () { function RouterInitializer(injector) { this.injector = injector; this.initNavigation = false; this.resultOfPreactivationDone = new rxjs.Subject(); } RouterInitializer.prototype.appInitializer = function () { var _this = this; var p = this.injector.get(common.LOCATION_INITIALIZED, Promise.resolve(null)); return p.then(function () { var resolve = null; var res = new Promise(function (r) { return resolve = r; }); var router = _this.injector.get(Router); var opts = _this.injector.get(ROUTER_CONFIGURATION); if (_this.isLegacyDisabled(opts) || _this.isLegacyEnabled(opts)) { resolve(true); } else if (opts.initialNavigation === 'disabled') { router.setUpLocationChangeListener(); resolve(true); } else if (opts.initialNavigation === 'enabled') { router.hooks.afterPreactivation = function () { // only the initial navigation should be delayed if (!_this.initNavigation) { _this.initNavigation = true; resolve(true); return _this.resultOfPreactivationDone; // subsequent navigations should not be delayed } else { return rxjs.of(null); } }; router.initialNavigation(); } else { throw new Error("Invalid initialNavigation options: '" + opts.initialNavigation + "'"); } return res; }); }; RouterInitializer.prototype.bootstrapListener = function (bootstrappedComponentRef) { var opts = this.injector.get(ROUTER_CONFIGURATION); var preloader = this.injector.get(RouterPreloader); var router = this.injector.get(Router); var ref = this.injector.get(core.ApplicationRef); if (bootstrappedComponentRef !== ref.components[0]) { return; } if (this.isLegacyEnabled(opts)) { router.initialNavigation(); } else if (this.isLegacyDisabled(opts)) { router.setUpLocationChangeListener(); } preloader.setUpPreloading(); router.resetRootComponentType(ref.componentTypes[0]); this.resultOfPreactivationDone.next(null); this.resultOfPreactivationDone.complete(); }; RouterInitializer.prototype.isLegacyEnabled = function (opts) { return opts.initialNavigation === 'legacy_enabled' || opts.initialNavigation === true || opts.initialNavigation === undefined; }; RouterInitializer.prototype.isLegacyDisabled = function (opts) { return opts.initialNavigation === 'legacy_disabled' || opts.initialNavigation === false; }; RouterInitializer.decorators = [ { type: core.Injectable } ]; /** @nocollapse */ RouterInitializer.ctorParameters = function () { return [ { type: core.Injector } ]; }; return RouterInitializer; }()); function getAppInitializer(r) { return r.appInitializer.bind(r); } function getBootstrapListener(r) { return r.bootstrapListener.bind(r); } /** * A token for the router initializer that will be called after the app is bootstrapped. * * @experimental */ var ROUTER_INITIALIZER = new core.InjectionToken('Router Initializer'); function provideRouterInitializer() { return [ RouterInitializer, { provide: core.APP_INITIALIZER, multi: true, useFactory: getAppInitializer, deps: [RouterInitializer] }, { provide: ROUTER_INITIALIZER, useFactory: getBootstrapListener, deps: [RouterInitializer] }, { provide: core.APP_BOOTSTRAP_LISTENER, multi: true, useExisting: ROUTER_INITIALIZER }, ]; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var VERSION = new core.Version('6.0.9'); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ // This file only reexports content of the `src` folder. Keep it that way. /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Generated bundle index. Do not edit. */ exports.ɵangular_packages_router_router_a = ROUTER_FORROOT_GUARD; exports.ɵangular_packages_router_router_g = RouterInitializer; exports.ɵangular_packages_router_router_h = getAppInitializer; exports.ɵangular_packages_router_router_i = getBootstrapListener; exports.ɵangular_packages_router_router_d = provideForRootGuard; exports.ɵangular_packages_router_router_c = provideLocationStrategy; exports.ɵangular_packages_router_router_j = provideRouterInitializer; exports.ɵangular_packages_router_router_f = rootRoute; exports.ɵangular_packages_router_router_b = routerNgProbeToken; exports.ɵangular_packages_router_router_e = setupRouter; exports.ɵangular_packages_router_router_k = Tree; exports.ɵangular_packages_router_router_l = TreeNode; exports.RouterLink = RouterLink; exports.RouterLinkWithHref = RouterLinkWithHref; exports.RouterLinkActive = RouterLinkActive; exports.RouterOutlet = RouterOutlet; exports.ActivationEnd = ActivationEnd; exports.ActivationStart = ActivationStart; exports.ChildActivationEnd = ChildActivationEnd; exports.ChildActivationStart = ChildActivationStart; exports.GuardsCheckEnd = GuardsCheckEnd; exports.GuardsCheckStart = GuardsCheckStart; exports.NavigationCancel = NavigationCancel; exports.NavigationEnd = NavigationEnd; exports.NavigationError = NavigationError; exports.NavigationStart = NavigationStart; exports.ResolveEnd = ResolveEnd; exports.ResolveStart = ResolveStart; exports.RouteConfigLoadEnd = RouteConfigLoadEnd; exports.RouteConfigLoadStart = RouteConfigLoadStart; exports.RouterEvent = RouterEvent; exports.RoutesRecognized = RoutesRecognized; exports.RouteReuseStrategy = RouteReuseStrategy; exports.Router = Router; exports.ROUTES = ROUTES; exports.ROUTER_CONFIGURATION = ROUTER_CONFIGURATION; exports.ROUTER_INITIALIZER = ROUTER_INITIALIZER; exports.RouterModule = RouterModule; exports.provideRoutes = provideRoutes; exports.ChildrenOutletContexts = ChildrenOutletContexts; exports.OutletContext = OutletContext; exports.NoPreloading = NoPreloading; exports.PreloadAllModules = PreloadAllModules; exports.PreloadingStrategy = PreloadingStrategy; exports.RouterPreloader = RouterPreloader; exports.ActivatedRoute = ActivatedRoute; exports.ActivatedRouteSnapshot = ActivatedRouteSnapshot; exports.RouterState = RouterState; exports.RouterStateSnapshot = RouterStateSnapshot; exports.PRIMARY_OUTLET = PRIMARY_OUTLET; exports.convertToParamMap = convertToParamMap; exports.UrlHandlingStrategy = UrlHandlingStrategy; exports.DefaultUrlSerializer = DefaultUrlSerializer; exports.UrlSegment = UrlSegment; exports.UrlSegmentGroup = UrlSegmentGroup; exports.UrlSerializer = UrlSerializer; exports.UrlTree = UrlTree; exports.VERSION = VERSION; exports.ɵEmptyOutletComponent = EmptyOutletComponent; exports.ɵROUTER_PROVIDERS = ROUTER_PROVIDERS; exports.ɵflatten = flatten; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=router.umd.js.map