From 9ba6ef338e4e4f5e21758b245d7ebf82fb364982 Mon Sep 17 00:00:00 2001 From: AureliaEffect Date: Wed, 17 Apr 2019 02:25:18 +0000 Subject: [PATCH] chore(all): add latest build artifacts --- dist/amd/aurelia-router.js | 4492 +++++++++++---------- dist/amd/aurelia-router.js.map | 2 +- dist/aurelia-router.d.ts | 831 ++-- dist/commonjs/aurelia-router.js | 3360 +++++++-------- dist/commonjs/aurelia-router.js.map | 2 +- dist/es2015/aurelia-router.js | 3117 +++++++------- dist/es2015/aurelia-router.js.map | 2 +- dist/native-modules/aurelia-router.js | 3360 +++++++-------- dist/native-modules/aurelia-router.js.map | 2 +- 9 files changed, 7838 insertions(+), 7330 deletions(-) diff --git a/dist/amd/aurelia-router.js b/dist/amd/aurelia-router.js index 4ffd7378..6242b856 100644 --- a/dist/amd/aurelia-router.js +++ b/dist/amd/aurelia-router.js @@ -1,2209 +1,2331 @@ define('aurelia-router', ['exports', 'aurelia-logging', 'aurelia-dependency-injection', 'aurelia-history', 'aurelia-route-recognizer', 'aurelia-event-aggregator'], function (exports, LogManager, aureliaDependencyInjection, aureliaHistory, aureliaRouteRecognizer, aureliaEventAggregator) { 'use strict'; - /** - * Determines if the provided object is a navigation command. - * A navigation command is anything with a navigate method. - * - * @param obj The object to check. - */ - function isNavigationCommand(obj) { - return obj && typeof obj.navigate === 'function'; - } - /** - * Used during the activation lifecycle to cause a redirect. - */ - var Redirect = /** @class */ (function () { - /** - * @param url The URL fragment to use as the navigation destination. - * @param options The navigation options. - */ - function Redirect(url, options) { - if (options === void 0) { options = {}; } - this.url = url; - this.options = Object.assign({ trigger: true, replace: true }, options); - this.shouldContinueProcessing = false; - } - /** - * Called by the activation system to set the child router. - * - * @param router The router. - */ - Redirect.prototype.setRouter = function (router) { - this.router = router; - }; - /** - * Called by the navigation pipeline to navigate. - * - * @param appRouter The router to be redirected. - */ - Redirect.prototype.navigate = function (appRouter) { - var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); - navigatingRouter.navigate(this.url, this.options); - }; - return Redirect; - }()); - /** - * Used during the activation lifecycle to cause a redirect to a named route. - */ - var RedirectToRoute = /** @class */ (function () { - /** - * @param route The name of the route. - * @param params The parameters to be sent to the activation method. - * @param options The options to use for navigation. - */ - function RedirectToRoute(route, params, options) { - if (params === void 0) { params = {}; } - if (options === void 0) { options = {}; } - this.route = route; - this.params = params; - this.options = Object.assign({ trigger: true, replace: true }, options); - this.shouldContinueProcessing = false; - } - /** - * Called by the activation system to set the child router. - * - * @param router The router. - */ - RedirectToRoute.prototype.setRouter = function (router) { - this.router = router; - }; - /** - * Called by the navigation pipeline to navigate. - * - * @param appRouter The router to be redirected. - */ - RedirectToRoute.prototype.navigate = function (appRouter) { - var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); - navigatingRouter.navigateToRoute(this.route, this.params, this.options); - }; - return RedirectToRoute; - }()); - - /** - * The strategy to use when activating modules during navigation. - */ - var activationStrategy = { - noChange: 'no-change', - invokeLifecycle: 'invoke-lifecycle', - replace: 'replace' - }; - /** - * Transform a navigation instruction into viewport plan record object, - * or a redirect request if user viewmodel demands - */ - var BuildNavigationPlanStep = /** @class */ (function () { - function BuildNavigationPlanStep() { - } - BuildNavigationPlanStep.prototype.run = function (navigationInstruction, next) { - return _buildNavigationPlan(navigationInstruction) - .then(function (plan) { - if (plan instanceof Redirect) { - return next.cancel(plan); - } - navigationInstruction.plan = plan; - return next(); - }) - .catch(next.cancel); - }; - return BuildNavigationPlanStep; - }()); - function _buildNavigationPlan(instruction, forceLifecycleMinimum) { - var config = instruction.config; - // todo: separate and export for unit tests - if ('redirect' in config) { - var router_1 = instruction.router; - return router_1 - ._createNavigationInstruction(config.redirect) - .then(function (newInstruction) { - var params = {}; - for (var key in newInstruction.params) { - // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this } - var val = newInstruction.params[key]; - if (typeof val === 'string' && val[0] === ':') { - val = val.slice(1); - // And if that param is found on the original instruction then use it - if (val in instruction.params) { - params[key] = instruction.params[val]; - } - } - else { - params[key] = newInstruction.params[key]; - } - } - var redirectLocation = router_1.generate(newInstruction.config, params, instruction.options); - // Special handling for child routes - for (var key in instruction.params) { - redirectLocation = redirectLocation.replace(":" + key, instruction.params[key]); - } - if (instruction.queryString) { - redirectLocation += '?' + instruction.queryString; - } - return Promise.resolve(new Redirect(redirectLocation)); - }); - } - var prev = instruction.previousInstruction; - var plan = {}; - var defaults = instruction.router.viewPortDefaults; - if (prev) { - var newParams = hasDifferentParameterValues(prev, instruction); - var pending_1 = []; - var _loop_1 = function (viewPortName) { - var _a; - var prevViewPortInstruction = prev.viewPortInstructions[viewPortName]; - var nextViewPortConfig = viewPortName in config.viewPorts ? config.viewPorts[viewPortName] : prevViewPortInstruction; - if (nextViewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) { - nextViewPortConfig = defaults[viewPortName]; - } - var viewPortPlan = plan[viewPortName] = { - name: viewPortName, - config: nextViewPortConfig, - prevComponent: prevViewPortInstruction.component, - prevModuleId: prevViewPortInstruction.moduleId - }; - if (prevViewPortInstruction.moduleId !== nextViewPortConfig.moduleId) { - viewPortPlan.strategy = activationStrategy.replace; - } - else if ('determineActivationStrategy' in prevViewPortInstruction.component.viewModel) { - viewPortPlan.strategy = (_a = prevViewPortInstruction.component.viewModel).determineActivationStrategy.apply(_a, instruction.lifecycleArgs); - } - else if (config.activationStrategy) { - viewPortPlan.strategy = config.activationStrategy; - } - else if (newParams || forceLifecycleMinimum) { - viewPortPlan.strategy = activationStrategy.invokeLifecycle; - } - else { - viewPortPlan.strategy = activationStrategy.noChange; - } - if (viewPortPlan.strategy !== activationStrategy.replace && prevViewPortInstruction.childRouter) { - var path = instruction.getWildcardPath(); - var task = prevViewPortInstruction - .childRouter - ._createNavigationInstruction(path, instruction) - .then(function (childInstruction) { - viewPortPlan.childNavigationInstruction = childInstruction; - return _buildNavigationPlan(childInstruction, viewPortPlan.strategy === activationStrategy.invokeLifecycle) - .then(function (childPlan) { - if (childPlan instanceof Redirect) { - return Promise.reject(childPlan); - } - childInstruction.plan = childPlan; - // for bluebird ? - return null; - }); - }); - pending_1.push(task); - } - }; - for (var viewPortName in prev.viewPortInstructions) { - _loop_1(viewPortName); - } - return Promise.all(pending_1).then(function () { return plan; }); - } - for (var viewPortName in config.viewPorts) { - var viewPortConfig = config.viewPorts[viewPortName]; - if (viewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) { - viewPortConfig = defaults[viewPortName]; - } - plan[viewPortName] = { - name: viewPortName, - strategy: activationStrategy.replace, - config: viewPortConfig - }; - } - return Promise.resolve(plan); - } - function hasDifferentParameterValues(prev, next) { - var prevParams = prev.params; - var nextParams = next.params; - var nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; - for (var key in nextParams) { - if (key === nextWildCardName) { - continue; - } - if (prevParams[key] !== nextParams[key]) { - return true; - } - } - for (var key in prevParams) { - if (key === nextWildCardName) { - continue; - } - if (prevParams[key] !== nextParams[key]) { - return true; - } - } - if (!next.options.compareQueryParams) { - return false; - } - var prevQueryParams = prev.queryParams; - var nextQueryParams = next.queryParams; - for (var key in nextQueryParams) { - if (prevQueryParams[key] !== nextQueryParams[key]) { - return true; - } - } - for (var key in prevQueryParams) { - if (prevQueryParams[key] !== nextQueryParams[key]) { - return true; - } - } - return false; - } - - /** - * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route - */ - var CanDeactivatePreviousStep = /** @class */ (function () { - function CanDeactivatePreviousStep() { - } - CanDeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { - return processDeactivatable(navigationInstruction, 'canDeactivate', next); - }; - return CanDeactivatePreviousStep; - }()); - /** - * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route - */ - var CanActivateNextStep = /** @class */ (function () { - function CanActivateNextStep() { - } - CanActivateNextStep.prototype.run = function (navigationInstruction, next) { - return processActivatable(navigationInstruction, 'canActivate', next); - }; - return CanActivateNextStep; - }()); - /** - * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route - */ - var DeactivatePreviousStep = /** @class */ (function () { - function DeactivatePreviousStep() { - } - DeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { - return processDeactivatable(navigationInstruction, 'deactivate', next, true); - }; - return DeactivatePreviousStep; - }()); - /** - * A pipeline step responsible for finding and activating method `activate` on a view model of a route - */ - var ActivateNextStep = /** @class */ (function () { - function ActivateNextStep() { - } - ActivateNextStep.prototype.run = function (navigationInstruction, next) { - return processActivatable(navigationInstruction, 'activate', next, true); - }; - return ActivateNextStep; - }()); - /** - * Recursively find list of deactivate-able view models - * and invoke the either 'canDeactivate' or 'deactivate' on each - */ - var processDeactivatable = function (navigationInstruction, callbackName, next, ignoreResult) { - var plan = navigationInstruction.plan; - var infos = findDeactivatable(plan, callbackName); - var i = infos.length; // query from inside out - function inspect(val) { - if (ignoreResult || shouldContinue(val)) { - return iterate(); - } - return next.cancel(val); - } - function iterate() { - if (i--) { - try { - var viewModel = infos[i]; - var result = viewModel[callbackName](navigationInstruction); - return processPotential(result, inspect, next.cancel); - } - catch (error) { - return next.cancel(error); - } - } - navigationInstruction.router.couldDeactivate = true; - return next(); - } - return iterate(); - }; - /** - * Recursively find and returns a list of deactivate-able view models - */ - var findDeactivatable = function (plan, callbackName, list) { - if (list === void 0) { list = []; } - for (var viewPortName in plan) { - var viewPortPlan = plan[viewPortName]; - var prevComponent = viewPortPlan.prevComponent; - if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace) - && prevComponent) { - var viewModel = prevComponent.viewModel; - if (callbackName in viewModel) { - list.push(viewModel); - } - } - if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) { - addPreviousDeactivatable(prevComponent, callbackName, list); - } - else if (viewPortPlan.childNavigationInstruction) { - findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list); - } - } - return list; - }; - var addPreviousDeactivatable = function (component, callbackName, list) { - var childRouter = component.childRouter; - if (childRouter && childRouter.currentInstruction) { - var viewPortInstructions = childRouter.currentInstruction.viewPortInstructions; - for (var viewPortName in viewPortInstructions) { - var viewPortInstruction = viewPortInstructions[viewPortName]; - var prevComponent = viewPortInstruction.component; - var prevViewModel = prevComponent.viewModel; - if (callbackName in prevViewModel) { - list.push(prevViewModel); - } - addPreviousDeactivatable(prevComponent, callbackName, list); - } - } - }; - var processActivatable = function (navigationInstruction, callbackName, next, ignoreResult) { - var infos = findActivatable(navigationInstruction, callbackName); - var length = infos.length; - var i = -1; // query from top down - function inspect(val, router) { - if (ignoreResult || shouldContinue(val, router)) { - return iterate(); - } - return next.cancel(val); - } - function iterate() { - var _a; - i++; - if (i < length) { - try { - var current_1 = infos[i]; - var result = (_a = current_1.viewModel)[callbackName].apply(_a, current_1.lifecycleArgs); - return processPotential(result, function (val) { return inspect(val, current_1.router); }, next.cancel); - } - catch (error) { - return next.cancel(error); - } - } - return next(); - } - return iterate(); - }; - /** - * Find list of activatable view model and add to list (3rd parameter) - */ - var findActivatable = function (navigationInstruction, callbackName, list, router) { - if (list === void 0) { list = []; } - var plan = navigationInstruction.plan; - Object - .keys(plan) - .forEach(function (viewPortName) { - var viewPortPlan = plan[viewPortName]; - var viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName]; - var viewPortComponent = viewPortInstruction.component; - var viewModel = viewPortComponent.viewModel; - if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle - || viewPortPlan.strategy === activationStrategy.replace) - && callbackName in viewModel) { - list.push({ - viewModel: viewModel, - lifecycleArgs: viewPortInstruction.lifecycleArgs, - router: router - }); - } - var childNavInstruction = viewPortPlan.childNavigationInstruction; - if (childNavInstruction) { - findActivatable(childNavInstruction, callbackName, list, viewPortComponent.childRouter || router); - } - }); - return list; - }; - var shouldContinue = function (output, router) { - if (output instanceof Error) { - return false; - } - if (isNavigationCommand(output)) { - if (typeof output.setRouter === 'function') { - output.setRouter(router); - } - return !!output.shouldContinueProcessing; - } - if (output === undefined) { - return true; - } - return output; - }; - /** - * wraps a subscription, allowing unsubscribe calls even if - * the first value comes synchronously - */ - var SafeSubscription = /** @class */ (function () { - function SafeSubscription(subscriptionFunc) { - this._subscribed = true; - this._subscription = subscriptionFunc(this); - if (!this._subscribed) { - this.unsubscribe(); - } - } - Object.defineProperty(SafeSubscription.prototype, "subscribed", { - get: function () { - return this._subscribed; - }, - enumerable: true, - configurable: true - }); - SafeSubscription.prototype.unsubscribe = function () { - if (this._subscribed && this._subscription) { - this._subscription.unsubscribe(); - } - this._subscribed = false; - }; - return SafeSubscription; - }()); - /** - * A function to process return value from `activate`/`canActivate` steps - * Supports observable/promise - * - * For observable, resolve at first next() or on complete() - */ - var processPotential = function (obj, resolve, reject) { - // if promise like - if (obj && typeof obj.then === 'function') { - return Promise.resolve(obj).then(resolve).catch(reject); - } - // if observable - if (obj && typeof obj.subscribe === 'function') { - var obs_1 = obj; - return new SafeSubscription(function (sub) { return obs_1.subscribe({ - next: function () { - if (sub.subscribed) { - sub.unsubscribe(); - resolve(obj); - } - }, - error: function (error) { - if (sub.subscribed) { - sub.unsubscribe(); - reject(error); - } - }, - complete: function () { - if (sub.subscribed) { - sub.unsubscribe(); - resolve(obj); - } - } - }); }); - } - // else just resolve - try { - return resolve(obj); - } - catch (error) { - return reject(error); - } - }; - - /*! ***************************************************************************** - 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 + /*! ***************************************************************************** + 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. + 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 */ + See the Apache Version 2.0 License for specific language governing permissions + and limitations under the License. + ***************************************************************************** */ + /* global Reflect, Promise */ - var extendStatics = function(d, b) { - 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]; }; - return extendStatics(d, b); - }; + var extendStatics = function(d, b) { + 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]; }; + return extendStatics(d, b); + }; - function __extends(d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - } + function __extends(d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + } + + /** + * Class used to represent an instruction during a navigation. + */ + var NavigationInstruction = /** @class */ (function () { + function NavigationInstruction(init) { + /** + * Current built viewport plan of this nav instruction + */ + this.plan = null; + this.options = {}; + Object.assign(this, init); + this.params = this.params || {}; + this.viewPortInstructions = {}; + var ancestorParams = []; + var current = this; + do { + var currentParams = Object.assign({}, current.params); + if (current.config && current.config.hasChildRouter) { + // remove the param for the injected child route segment + delete currentParams[current.getWildCardName()]; + } + ancestorParams.unshift(currentParams); + current = current.parentInstruction; + } while (current); + var allParams = Object.assign.apply(Object, [{}, this.queryParams].concat(ancestorParams)); + this.lifecycleArgs = [allParams, this.config, this]; + } + /** + * Gets an array containing this instruction and all child instructions for the current navigation. + */ + NavigationInstruction.prototype.getAllInstructions = function () { + var instructions = [this]; + var viewPortInstructions = this.viewPortInstructions; + for (var key in viewPortInstructions) { + var childInstruction = viewPortInstructions[key].childNavigationInstruction; + if (childInstruction) { + instructions.push.apply(instructions, childInstruction.getAllInstructions()); + } + } + return instructions; + }; + /** + * Gets an array containing the instruction and all child instructions for the previous navigation. + * Previous instructions are no longer available after navigation completes. + */ + NavigationInstruction.prototype.getAllPreviousInstructions = function () { + return this.getAllInstructions().map(function (c) { return c.previousInstruction; }).filter(function (c) { return c; }); + }; + NavigationInstruction.prototype.addViewPortInstruction = function (nameOrInitOptions, strategy, moduleId, component) { + var viewPortInstruction; + var viewPortName = typeof nameOrInitOptions === 'string' ? nameOrInitOptions : nameOrInitOptions.name; + var lifecycleArgs = this.lifecycleArgs; + var config = Object.assign({}, lifecycleArgs[1], { currentViewPort: viewPortName }); + if (typeof nameOrInitOptions === 'string') { + viewPortInstruction = { + name: nameOrInitOptions, + strategy: strategy, + moduleId: moduleId, + component: component, + childRouter: component.childRouter, + lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] + }; + } + else { + viewPortInstruction = { + name: viewPortName, + strategy: nameOrInitOptions.strategy, + component: nameOrInitOptions.component, + moduleId: nameOrInitOptions.moduleId, + childRouter: nameOrInitOptions.component.childRouter, + lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] + }; + } + return this.viewPortInstructions[viewPortName] = viewPortInstruction; + }; + /** + * Gets the name of the route pattern's wildcard parameter, if applicable. + */ + NavigationInstruction.prototype.getWildCardName = function () { + // todo: potential issue, or at least unsafe typings + var configRoute = this.config.route; + var wildcardIndex = configRoute.lastIndexOf('*'); + return configRoute.substr(wildcardIndex + 1); + }; + /** + * Gets the path and query string created by filling the route + * pattern's wildcard parameter with the matching param. + */ + NavigationInstruction.prototype.getWildcardPath = function () { + var wildcardName = this.getWildCardName(); + var path = this.params[wildcardName] || ''; + var queryString = this.queryString; + if (queryString) { + path += '?' + queryString; + } + return path; + }; + /** + * Gets the instruction's base URL, accounting for wildcard route parameters. + */ + NavigationInstruction.prototype.getBaseUrl = function () { + var _this = this; + var $encodeURI = encodeURI; + var fragment = decodeURI(this.fragment); + if (fragment === '') { + var nonEmptyRoute = this.router.routes.find(function (route) { + return route.name === _this.config.name && + route.route !== ''; + }); + if (nonEmptyRoute) { + fragment = nonEmptyRoute.route; + } + } + if (!this.params) { + return $encodeURI(fragment); + } + var wildcardName = this.getWildCardName(); + var path = this.params[wildcardName] || ''; + if (!path) { + return $encodeURI(fragment); + } + return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path))); + }; + /** + * Finalize a viewport instruction + * @internal + */ + NavigationInstruction.prototype._commitChanges = function (waitToSwap) { + var _this = this; + var router = this.router; + router.currentInstruction = this; + var previousInstruction = this.previousInstruction; + if (previousInstruction) { + previousInstruction.config.navModel.isActive = false; + } + this.config.navModel.isActive = true; + router.refreshNavigation(); + var loads = []; + var delaySwaps = []; + var viewPortInstructions = this.viewPortInstructions; + var _loop_1 = function (viewPortName) { + var viewPortInstruction = viewPortInstructions[viewPortName]; + var viewPort = router.viewPorts[viewPortName]; + if (!viewPort) { + throw new Error("There was no router-view found in the view for " + viewPortInstruction.moduleId + "."); + } + var childNavInstruction = viewPortInstruction.childNavigationInstruction; + if (viewPortInstruction.strategy === "replace" /* Replace */) { + if (childNavInstruction && childNavInstruction.parentCatchHandler) { + loads.push(childNavInstruction._commitChanges(waitToSwap)); + } + else { + if (waitToSwap) { + delaySwaps.push({ viewPort: viewPort, viewPortInstruction: viewPortInstruction }); + } + loads.push(viewPort + .process(viewPortInstruction, waitToSwap) + .then(function () { return childNavInstruction + ? childNavInstruction._commitChanges(waitToSwap) + : Promise.resolve(); })); + } + } + else { + if (childNavInstruction) { + loads.push(childNavInstruction._commitChanges(waitToSwap)); + } + } + }; + for (var viewPortName in viewPortInstructions) { + _loop_1(viewPortName); + } + return Promise + .all(loads) + .then(function () { + delaySwaps.forEach(function (x) { return x.viewPort.swap(x.viewPortInstruction); }); + return null; + }) + .then(function () { return prune(_this); }); + }; + /**@internal */ + NavigationInstruction.prototype._updateTitle = function () { + var router = this.router; + var title = this._buildTitle(router.titleSeparator); + if (title) { + router.history.setTitle(title); + } + }; + /**@internal */ + NavigationInstruction.prototype._buildTitle = function (separator) { + if (separator === void 0) { separator = ' | '; } + var title = ''; + var childTitles = []; + var navModelTitle = this.config.navModel.title; + var instructionRouter = this.router; + var viewPortInstructions = this.viewPortInstructions; + if (navModelTitle) { + title = instructionRouter.transformTitle(navModelTitle); + } + for (var viewPortName in viewPortInstructions) { + var viewPortInstruction = viewPortInstructions[viewPortName]; + var child_nav_instruction = viewPortInstruction.childNavigationInstruction; + if (child_nav_instruction) { + var childTitle = child_nav_instruction._buildTitle(separator); + if (childTitle) { + childTitles.push(childTitle); + } + } + } + if (childTitles.length) { + title = childTitles.join(separator) + (title ? separator : '') + title; + } + if (instructionRouter.title) { + title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title); + } + return title; + }; + return NavigationInstruction; + }()); + var prune = function (instruction) { + instruction.previousInstruction = null; + instruction.plan = null; + }; + + /** + * Class for storing and interacting with a route's navigation settings. + */ + var NavModel = /** @class */ (function () { + function NavModel(router, relativeHref) { + /** + * True if this nav item is currently active. + */ + this.isActive = false; + /** + * The title. + */ + this.title = null; + /** + * This nav item's absolute href. + */ + this.href = null; + /** + * This nav item's relative href. + */ + this.relativeHref = null; + /** + * Data attached to the route at configuration time. + */ + this.settings = {}; + /** + * The route config. + */ + this.config = null; + this.router = router; + this.relativeHref = relativeHref; + } + /** + * Sets the route's title and updates document.title. + * If the a navigation is in progress, the change will be applied + * to document.title when the navigation completes. + * + * @param title The new title. + */ + NavModel.prototype.setTitle = function (title) { + this.title = title; + if (this.isActive) { + this.router.updateTitle(); + } + }; + return NavModel; + }()); + + function _normalizeAbsolutePath(path, hasPushState, absolute) { + if (absolute === void 0) { absolute = false; } + if (!hasPushState && path[0] !== '#') { + path = '#' + path; + } + if (hasPushState && absolute) { + path = path.substring(1, path.length); + } + return path; + } + function _createRootedPath(fragment, baseUrl, hasPushState, absolute) { + if (isAbsoluteUrl.test(fragment)) { + return fragment; + } + var path = ''; + if (baseUrl.length && baseUrl[0] !== '/') { + path += '/'; + } + path += baseUrl; + if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') { + path += '/'; + } + if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') { + path = path.substring(0, path.length - 1); + } + return _normalizeAbsolutePath(path + fragment, hasPushState, absolute); + } + function _resolveUrl(fragment, baseUrl, hasPushState) { + if (isRootedPath.test(fragment)) { + return _normalizeAbsolutePath(fragment, hasPushState); + } + return _createRootedPath(fragment, baseUrl, hasPushState); + } + function _ensureArrayWithSingleRoutePerConfig(config) { + var routeConfigs = []; + if (Array.isArray(config.route)) { + for (var i = 0, ii = config.route.length; i < ii; ++i) { + var current = Object.assign({}, config); + current.route = config.route[i]; + routeConfigs.push(current); + } + } + else { + routeConfigs.push(Object.assign({}, config)); + } + return routeConfigs; + } + var isRootedPath = /^#?\//; + var isAbsoluteUrl = /^([a-z][a-z0-9+\-.]*:)?\/\//i; + + /** + * Class used to configure a [[Router]] instance. + * + * @constructor + */ + var RouterConfiguration = /** @class */ (function () { + function RouterConfiguration() { + this.instructions = []; + this.options = {}; + this.pipelineSteps = []; + } + /** + * Adds a step to be run during the [[Router]]'s navigation pipeline. + * + * @param name The name of the pipeline slot to insert the step into. + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPipelineStep = function (name, step) { + if (step === null || step === undefined) { + throw new Error('Pipeline step cannot be null or undefined.'); + } + this.pipelineSteps.push({ name: name, step: step }); + return this; + }; + /** + * Adds a step to be run during the [[Router]]'s authorize pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addAuthorizeStep = function (step) { + return this.addPipelineStep("authorize" /* Authorize */, step); + }; + /** + * Adds a step to be run during the [[Router]]'s preActivate pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPreActivateStep = function (step) { + return this.addPipelineStep("preActivate" /* PreActivate */, step); + }; + /** + * Adds a step to be run during the [[Router]]'s preRender pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPreRenderStep = function (step) { + return this.addPipelineStep("preRender" /* PreRender */, step); + }; + /** + * Adds a step to be run during the [[Router]]'s postRender pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPostRenderStep = function (step) { + return this.addPipelineStep("postRender" /* PostRender */, step); + }; + /** + * Configures a route that will be used if there is no previous location available on navigation cancellation. + * + * @param fragment The URL fragment to use as the navigation destination. + * @chainable + */ + RouterConfiguration.prototype.fallbackRoute = function (fragment) { + this._fallbackRoute = fragment; + return this; + }; + /** + * Maps one or more routes to be registered with the router. + * + * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map. + * @chainable + */ + RouterConfiguration.prototype.map = function (route) { + var _this = this; + if (Array.isArray(route)) { + route.forEach(function (r) { return _this.map(r); }); + return this; + } + return this.mapRoute(route); + }; + /** + * Configures defaults to use for any view ports. + * + * @param viewPortConfig a view port configuration object to use as a + * default, of the form { viewPortName: { moduleId } }. + * @chainable + */ + RouterConfiguration.prototype.useViewPortDefaults = function (viewPortConfig) { + this.viewPortDefaults = viewPortConfig; + return this; + }; + /** + * Maps a single route to be registered with the router. + * + * @param route The [[RouteConfig]] to map. + * @chainable + */ + RouterConfiguration.prototype.mapRoute = function (config) { + this.instructions.push(function (router) { + var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); + var navModel; + for (var i = 0, ii = routeConfigs.length; i < ii; ++i) { + var routeConfig = routeConfigs[i]; + routeConfig.settings = routeConfig.settings || {}; + if (!navModel) { + navModel = router.createNavModel(routeConfig); + } + router.addRoute(routeConfig, navModel); + } + }); + return this; + }; + /** + * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes. + * + * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the + * [[NavigationInstruction]] and selects a moduleId to load. + * @chainable + */ + RouterConfiguration.prototype.mapUnknownRoutes = function (config) { + this.unknownRouteConfig = config; + return this; + }; + /** + * Applies the current configuration to the specified [[Router]]. + * + * @param router The [[Router]] to apply the configuration to. + */ + RouterConfiguration.prototype.exportToRouter = function (router) { + var instructions = this.instructions; + for (var i = 0, ii = instructions.length; i < ii; ++i) { + instructions[i](router); + } + var _a = this, title = _a.title, titleSeparator = _a.titleSeparator, unknownRouteConfig = _a.unknownRouteConfig, _fallbackRoute = _a._fallbackRoute, viewPortDefaults = _a.viewPortDefaults; + if (title) { + router.title = title; + } + if (titleSeparator) { + router.titleSeparator = titleSeparator; + } + if (unknownRouteConfig) { + router.handleUnknownRoutes(unknownRouteConfig); + } + if (_fallbackRoute) { + router.fallbackRoute = _fallbackRoute; + } + if (viewPortDefaults) { + router.useViewPortDefaults(viewPortDefaults); + } + Object.assign(router.options, this.options); + var pipelineSteps = this.pipelineSteps; + var pipelineStepCount = pipelineSteps.length; + if (pipelineStepCount) { + if (!router.isRoot) { + throw new Error('Pipeline steps can only be added to the root router'); + } + var pipelineProvider = router.pipelineProvider; + for (var i = 0, ii = pipelineStepCount; i < ii; ++i) { + var _b = pipelineSteps[i], name_1 = _b.name, step = _b.step; + pipelineProvider.addStep(name_1, step); + } + } + }; + return RouterConfiguration; + }()); + + /** + * The primary class responsible for handling routing and navigation. + */ + var Router = /** @class */ (function () { + /** + * @param container The [[Container]] to use when child routers. + * @param history The [[History]] implementation to delegate navigation requests to. + */ + function Router(container, history) { + var _this = this; + /** + * The parent router, or null if this instance is not a child router. + */ + this.parent = null; + this.options = {}; + /** + * The defaults used when a viewport lacks specified content + */ + this.viewPortDefaults = {}; + /** + * Extension point to transform the document title before it is built and displayed. + * By default, child routers delegate to the parent router, and the app router + * returns the title unchanged. + */ + this.transformTitle = function (title) { + if (_this.parent) { + return _this.parent.transformTitle(title); + } + return title; + }; + this.container = container; + this.history = history; + this.reset(); + } + /** + * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. + * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. + */ + Router.prototype.reset = function () { + var _this = this; + this.viewPorts = {}; + this.routes = []; + this.baseUrl = ''; + this.isConfigured = false; + this.isNavigating = false; + this.isExplicitNavigation = false; + this.isExplicitNavigationBack = false; + this.isNavigatingFirst = false; + this.isNavigatingNew = false; + this.isNavigatingRefresh = false; + this.isNavigatingForward = false; + this.isNavigatingBack = false; + this.couldDeactivate = false; + this.navigation = []; + this.currentInstruction = null; + this.viewPortDefaults = {}; + this._fallbackOrder = 100; + this._recognizer = new aureliaRouteRecognizer.RouteRecognizer(); + this._childRecognizer = new aureliaRouteRecognizer.RouteRecognizer(); + this._configuredPromise = new Promise(function (resolve) { + _this._resolveConfiguredPromise = resolve; + }); + }; + Object.defineProperty(Router.prototype, "isRoot", { + /** + * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent. + */ + get: function () { + return !this.parent; + }, + enumerable: true, + configurable: true + }); + /** + * Registers a viewPort to be used as a rendering target for activated routes. + * + * @param viewPort The viewPort. + * @param name The name of the viewPort. 'default' if unspecified. + */ + Router.prototype.registerViewPort = function (viewPort, name) { + name = name || 'default'; + this.viewPorts[name] = viewPort; + }; + /** + * Returns a Promise that resolves when the router is configured. + */ + Router.prototype.ensureConfigured = function () { + return this._configuredPromise; + }; + /** + * Configures the router. + * + * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]]. + */ + Router.prototype.configure = function (callbackOrConfig) { + var _this = this; + this.isConfigured = true; + var result = callbackOrConfig; + var config; + if (typeof callbackOrConfig === 'function') { + config = new RouterConfiguration(); + result = callbackOrConfig(config); + } + return Promise + .resolve(result) + .then(function (c) { + if (c && c.exportToRouter) { + config = c; + } + config.exportToRouter(_this); + _this.isConfigured = true; + _this._resolveConfiguredPromise(); + }); + }; + /** + * Navigates to a new location. + * + * @param fragment The URL fragment to use as the navigation destination. + * @param options The navigation options. + */ + Router.prototype.navigate = function (fragment, options) { + if (!this.isConfigured && this.parent) { + return this.parent.navigate(fragment, options); + } + this.isExplicitNavigation = true; + return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options); + }; + /** + * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed + * by [[Router.navigate]]. + * + * @param route The name of the route to use when generating the navigation location. + * @param params The route parameters to be used when populating the route pattern. + * @param options The navigation options. + */ + Router.prototype.navigateToRoute = function (route, params, options) { + var path = this.generate(route, params); + return this.navigate(path, options); + }; + /** + * Navigates back to the most recent location in history. + */ + Router.prototype.navigateBack = function () { + this.isExplicitNavigationBack = true; + this.history.navigateBack(); + }; + /** + * Creates a child router of the current router. + * + * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified. + * @returns {Router} The new child Router. + */ + Router.prototype.createChild = function (container) { + var childRouter = new Router(container || this.container.createChild(), this.history); + childRouter.parent = this; + return childRouter; + }; + /** + * Generates a URL fragment matching the specified route pattern. + * + * @param name The name of the route whose pattern should be used to generate the fragment. + * @param params The route params to be used to populate the route pattern. + * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url. + * @returns {string} A string containing the generated URL fragment. + */ + Router.prototype.generate = function (nameOrRoute, params, options) { + if (params === void 0) { params = {}; } + if (options === void 0) { options = {}; } + // A child recognizer generates routes for potential child routes. Any potential child route is added + // to the childRoute property of params for the childRouter to recognize. When generating routes, we + // use the childRecognizer when childRoute params are available to generate a child router enabled route. + var recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer; + var hasRoute = recognizer.hasRoute(nameOrRoute); + if (!hasRoute) { + if (this.parent) { + return this.parent.generate(nameOrRoute, params, options); + } + throw new Error("A route with name '" + nameOrRoute + "' could not be found. Check that `name: '" + nameOrRoute + "'` was specified in the route's config."); + } + var path = recognizer.generate(nameOrRoute, params); + var rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute); + return options.absolute ? "" + this.history.getAbsoluteRoot() + rootedPath : rootedPath; + }; + /** + * Creates a [[NavModel]] for the specified route config. + * + * @param config The route config. + */ + Router.prototype.createNavModel = function (config) { + var navModel = new NavModel(this, 'href' in config + ? config.href + // potential error when config.route is a string[] ? + : config.route); + navModel.title = config.title; + navModel.order = config.nav; + navModel.href = config.href; + navModel.settings = config.settings; + navModel.config = config; + return navModel; + }; + /** + * Registers a new route with the router. + * + * @param config The [[RouteConfig]]. + * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes. + */ + Router.prototype.addRoute = function (config, navModel) { + if (Array.isArray(config.route)) { + var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); + // the following is wrong. todo: fix this after TS refactoring release + routeConfigs.forEach(this.addRoute.bind(this)); + return; + } + validateRouteConfig(config); + if (!('viewPorts' in config) && !config.navigationStrategy) { + config.viewPorts = { + 'default': { + moduleId: config.moduleId, + view: config.view + } + }; + } + if (!navModel) { + navModel = this.createNavModel(config); + } + this.routes.push(config); + var path = config.route; + if (path.charAt(0) === '/') { + path = path.substr(1); + } + var caseSensitive = config.caseSensitive === true; + var state = this._recognizer.add({ + path: path, + handler: config, + caseSensitive: caseSensitive + }); + if (path) { + var settings = config.settings; + delete config.settings; + var withChild = JSON.parse(JSON.stringify(config)); + config.settings = settings; + withChild.route = path + "/*childRoute"; + withChild.hasChildRouter = true; + this._childRecognizer.add({ + path: withChild.route, + handler: withChild, + caseSensitive: caseSensitive + }); + withChild.navModel = navModel; + withChild.settings = config.settings; + withChild.navigationStrategy = config.navigationStrategy; + } + config.navModel = navModel; + var navigation = this.navigation; + if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) { + if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) { + throw new Error('Invalid route config for "' + config.route + '" : dynamic routes must specify an "href:" to be included in the navigation model.'); + } + if (typeof navModel.order !== 'number') { + navModel.order = ++this._fallbackOrder; + } + navigation.push(navModel); + // this is a potential error / inconsistency between browsers + // + // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort + // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, + // but sorted with respect to all different elements. + // Note: the ECMAscript standard does not guarantee this behaviour, + // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this. + navigation.sort(function (a, b) { return a.order - b.order; }); + } + }; + /** + * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name. + * + * @param name The name of the route to check. + */ + Router.prototype.hasRoute = function (name) { + return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name)); + }; + /** + * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name. + * + * @param name The name of the route to check. + */ + Router.prototype.hasOwnRoute = function (name) { + return this._recognizer.hasRoute(name); + }; + /** + * Register a handler to use when the incoming URL fragment doesn't match any registered routes. + * + * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]]. + */ + Router.prototype.handleUnknownRoutes = function (config) { + var _this = this; + if (!config) { + throw new Error('Invalid unknown route handler'); + } + this.catchAllHandler = function (instruction) { + return _this + ._createRouteConfig(config, instruction) + .then(function (c) { + instruction.config = c; + return instruction; + }); + }; + }; + /** + * Updates the document title using the current navigation instruction. + */ + Router.prototype.updateTitle = function () { + var parentRouter = this.parent; + if (parentRouter) { + return parentRouter.updateTitle(); + } + var currentInstruction = this.currentInstruction; + if (currentInstruction) { + currentInstruction._updateTitle(); + } + return undefined; + }; + /** + * Updates the navigation routes with hrefs relative to the current location. + * Note: This method will likely move to a plugin in a future release. + */ + Router.prototype.refreshNavigation = function () { + var nav = this.navigation; + for (var i = 0, length_1 = nav.length; i < length_1; i++) { + var current = nav[i]; + if (!current.config.href) { + current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState); + } + else { + current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState); + } + } + }; + /** + * Sets the default configuration for the view ports. This specifies how to + * populate a view port for which no module is specified. The default is + * an empty view/view-model pair. + */ + Router.prototype.useViewPortDefaults = function ($viewPortDefaults) { + // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction + var viewPortDefaults = $viewPortDefaults; + for (var viewPortName in viewPortDefaults) { + var viewPortConfig = viewPortDefaults[viewPortName]; + this.viewPortDefaults[viewPortName] = { + moduleId: viewPortConfig.moduleId + }; + } + }; + /**@internal */ + Router.prototype._refreshBaseUrl = function () { + var parentRouter = this.parent; + if (parentRouter) { + this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction); + } + }; + /**@internal */ + Router.prototype._createNavigationInstruction = function (url, parentInstruction) { + if (url === void 0) { url = ''; } + if (parentInstruction === void 0) { parentInstruction = null; } + var fragment = url; + var queryString = ''; + var queryIndex = url.indexOf('?'); + if (queryIndex !== -1) { + fragment = url.substr(0, queryIndex); + queryString = url.substr(queryIndex + 1); + } + var urlRecognizationResults = this._recognizer.recognize(url); + if (!urlRecognizationResults || !urlRecognizationResults.length) { + urlRecognizationResults = this._childRecognizer.recognize(url); + } + var instructionInit = { + fragment: fragment, + queryString: queryString, + config: null, + parentInstruction: parentInstruction, + previousInstruction: this.currentInstruction, + router: this, + options: { + compareQueryParams: this.options.compareQueryParams + } + }; + var result; + if (urlRecognizationResults && urlRecognizationResults.length) { + var first = urlRecognizationResults[0]; + var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: first.params, + queryParams: first.queryParams || urlRecognizationResults.queryParams, + config: first.config || first.handler + })); + if (typeof first.handler === 'function') { + result = evaluateNavigationStrategy(instruction, first.handler, first); + } + else if (first.handler && typeof first.handler.navigationStrategy === 'function') { + result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); + } + else { + result = Promise.resolve(instruction); + } + } + else if (this.catchAllHandler) { + var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: { path: fragment }, + queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, + config: null // config will be created by the catchAllHandler + })); + result = evaluateNavigationStrategy(instruction, this.catchAllHandler); + } + else if (this.parent) { + var router = this._parentCatchAllHandler(this.parent); + if (router) { + var newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction); + var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: { path: fragment }, + queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, + router: router, + parentInstruction: newParentInstruction, + parentCatchHandler: true, + config: null // config will be created by the chained parent catchAllHandler + })); + result = evaluateNavigationStrategy(instruction, router.catchAllHandler); + } + } + if (result && parentInstruction) { + this.baseUrl = generateBaseUrl(this.parent, parentInstruction); + } + return result || Promise.reject(new Error("Route not found: " + url)); + }; + /**@internal */ + Router.prototype._findParentInstructionFromRouter = function (router, instruction) { + if (instruction.router === router) { + instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId + return instruction; + } + else if (instruction.parentInstruction) { + return this._findParentInstructionFromRouter(router, instruction.parentInstruction); + } + return undefined; + }; + /**@internal */ + Router.prototype._parentCatchAllHandler = function (router) { + if (router.catchAllHandler) { + return router; + } + else if (router.parent) { + return this._parentCatchAllHandler(router.parent); + } + return false; + }; + /** + * @internal + */ + Router.prototype._createRouteConfig = function (config, instruction) { + var _this = this; + return Promise + .resolve(config) + .then(function (c) { + if (typeof c === 'string') { + return { moduleId: c }; + } + else if (typeof c === 'function') { + return c(instruction); + } + return c; + }) + // typing here could be either RouteConfig or RedirectConfig + // but temporarily treat both as RouteConfig + // todo: improve typings precision + .then(function (c) { return typeof c === 'string' ? { moduleId: c } : c; }) + .then(function (c) { + c.route = instruction.params.path; + validateRouteConfig(c); + if (!c.navModel) { + c.navModel = _this.createNavModel(c); + } + return c; + }); + }; + return Router; + }()); + /* @internal exported for unit testing */ + var generateBaseUrl = function (router, instruction) { + return "" + (router.baseUrl || '') + (instruction.getBaseUrl() || ''); + }; + /* @internal exported for unit testing */ + var validateRouteConfig = function (config) { + if (typeof config !== 'object') { + throw new Error('Invalid Route Config'); + } + if (typeof config.route !== 'string') { + var name_1 = config.name || '(no name)'; + throw new Error('Invalid Route Config for "' + name_1 + '": You must specify a "route:" pattern.'); + } + if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) { + throw new Error('Invalid Route Config for "' + config.route + '": You must specify a "moduleId:", "redirect:", "navigationStrategy:", or "viewPorts:".'); + } + }; + /* @internal exported for unit testing */ + var evaluateNavigationStrategy = function (instruction, evaluator, context) { + return Promise + .resolve(evaluator.call(context, instruction)) + .then(function () { + if (!('viewPorts' in instruction.config)) { + instruction.config.viewPorts = { + 'default': { + moduleId: instruction.config.moduleId + } + }; + } + return instruction; + }); + }; + + /**@internal exported for unit testing */ + var createNextFn = function (instruction, steps) { + var index = -1; + var next = function () { + index++; + if (index < steps.length) { + var currentStep = steps[index]; + try { + return currentStep(instruction, next); + } + catch (e) { + return next.reject(e); + } + } + else { + return next.complete(); + } + }; + next.complete = createCompletionHandler(next, "completed" /* Completed */); + next.cancel = createCompletionHandler(next, "canceled" /* Canceled */); + next.reject = createCompletionHandler(next, "rejected" /* Rejected */); + return next; + }; + /**@internal exported for unit testing */ + var createCompletionHandler = function (next, status) { + return function (output) { return Promise + .resolve({ + status: status, + output: output, + completed: status === "completed" /* Completed */ + }); }; + }; + + /** + * The class responsible for managing and processing the navigation pipeline. + */ + var Pipeline = /** @class */ (function () { + function Pipeline() { + /** + * The pipeline steps. And steps added via addStep will be converted to a function + * The actualy running functions with correct step contexts of this pipeline + */ + this.steps = []; + } + /** + * Adds a step to the pipeline. + * + * @param step The pipeline step. + */ + Pipeline.prototype.addStep = function (step) { + var run; + if (typeof step === 'function') { + run = step; + } + else if (typeof step.getSteps === 'function') { + // getSteps is to enable support open slots + // where devs can add multiple steps into the same slot name + var steps = step.getSteps(); + for (var i = 0, l = steps.length; i < l; i++) { + this.addStep(steps[i]); + } + return this; + } + else { + run = step.run.bind(step); + } + this.steps.push(run); + return this; + }; + /** + * Runs the pipeline. + * + * @param instruction The navigation instruction to process. + */ + Pipeline.prototype.run = function (instruction) { + var nextFn = createNextFn(instruction, this.steps); + return nextFn(); + }; + return Pipeline; + }()); + + /** + * Determines if the provided object is a navigation command. + * A navigation command is anything with a navigate method. + * + * @param obj The object to check. + */ + function isNavigationCommand(obj) { + return obj && typeof obj.navigate === 'function'; + } + /** + * Used during the activation lifecycle to cause a redirect. + */ + var Redirect = /** @class */ (function () { + /** + * @param url The URL fragment to use as the navigation destination. + * @param options The navigation options. + */ + function Redirect(url, options) { + if (options === void 0) { options = {}; } + this.url = url; + this.options = Object.assign({ trigger: true, replace: true }, options); + this.shouldContinueProcessing = false; + } + /** + * Called by the activation system to set the child router. + * + * @param router The router. + */ + Redirect.prototype.setRouter = function (router) { + this.router = router; + }; + /** + * Called by the navigation pipeline to navigate. + * + * @param appRouter The router to be redirected. + */ + Redirect.prototype.navigate = function (appRouter) { + var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); + navigatingRouter.navigate(this.url, this.options); + }; + return Redirect; + }()); + /** + * Used during the activation lifecycle to cause a redirect to a named route. + */ + var RedirectToRoute = /** @class */ (function () { + /** + * @param route The name of the route. + * @param params The parameters to be sent to the activation method. + * @param options The options to use for navigation. + */ + function RedirectToRoute(route, params, options) { + if (params === void 0) { params = {}; } + if (options === void 0) { options = {}; } + this.route = route; + this.params = params; + this.options = Object.assign({ trigger: true, replace: true }, options); + this.shouldContinueProcessing = false; + } + /** + * Called by the activation system to set the child router. + * + * @param router The router. + */ + RedirectToRoute.prototype.setRouter = function (router) { + this.router = router; + }; + /** + * Called by the navigation pipeline to navigate. + * + * @param appRouter The router to be redirected. + */ + RedirectToRoute.prototype.navigate = function (appRouter) { + var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); + navigatingRouter.navigateToRoute(this.route, this.params, this.options); + }; + return RedirectToRoute; + }()); + + /** + * @internal exported for unit testing + */ + function _buildNavigationPlan(instruction, forceLifecycleMinimum) { + var config = instruction.config; + if ('redirect' in config) { + return buildRedirectPlan(instruction); + } + var prevInstruction = instruction.previousInstruction; + var defaultViewPortConfigs = instruction.router.viewPortDefaults; + if (prevInstruction) { + return buildTransitionPlans(instruction, prevInstruction, defaultViewPortConfigs, forceLifecycleMinimum); + } + // first navigation, only need to prepare a few information for each viewport plan + var viewPortPlans = {}; + var viewPortConfigs = config.viewPorts; + for (var viewPortName in viewPortConfigs) { + var viewPortConfig = viewPortConfigs[viewPortName]; + if (viewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) { + viewPortConfig = defaultViewPortConfigs[viewPortName]; + } + viewPortPlans[viewPortName] = { + name: viewPortName, + strategy: "replace" /* Replace */, + config: viewPortConfig + }; + } + return Promise.resolve(viewPortPlans); + } + /** + * Build redirect plan based on config of a navigation instruction + * @internal exported for unit testing + */ + var buildRedirectPlan = function (instruction) { + var config = instruction.config; + var router = instruction.router; + return router + ._createNavigationInstruction(config.redirect) + .then(function (redirectInstruction) { + var params = {}; + var originalInstructionParams = instruction.params; + var redirectInstructionParams = redirectInstruction.params; + for (var key in redirectInstructionParams) { + // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this } + var val = redirectInstructionParams[key]; + if (typeof val === 'string' && val[0] === ':') { + val = val.slice(1); + // And if that param is found on the original instruction then use it + if (val in originalInstructionParams) { + params[key] = originalInstructionParams[val]; + } + } + else { + params[key] = redirectInstructionParams[key]; + } + } + var redirectLocation = router.generate(redirectInstruction.config, params, instruction.options); + // Special handling for child routes + for (var key in originalInstructionParams) { + redirectLocation = redirectLocation.replace(":" + key, originalInstructionParams[key]); + } + var queryString = instruction.queryString; + if (queryString) { + redirectLocation += '?' + queryString; + } + return Promise.resolve(new Redirect(redirectLocation)); + }); + }; + /** + * @param viewPortPlans the Plan record that holds information about built plans + * @internal exported for unit testing + */ + var buildTransitionPlans = function (currentInstruction, previousInstruction, defaultViewPortConfigs, forceLifecycleMinimum) { + var viewPortPlans = {}; + var newInstructionConfig = currentInstruction.config; + var hasNewParams = hasDifferentParameterValues(previousInstruction, currentInstruction); + var pending = []; + var previousViewPortInstructions = previousInstruction.viewPortInstructions; + var _loop_1 = function (viewPortName) { + var prevViewPortInstruction = previousViewPortInstructions[viewPortName]; + var prevViewPortComponent = prevViewPortInstruction.component; + var newInstructionViewPortConfigs = newInstructionConfig.viewPorts; + // if this is invoked on a viewport without any changes, based on new url, + // newViewPortConfig will be the existing viewport instruction + var nextViewPortConfig = viewPortName in newInstructionViewPortConfigs + ? newInstructionViewPortConfigs[viewPortName] + : prevViewPortInstruction; + if (nextViewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) { + nextViewPortConfig = defaultViewPortConfigs[viewPortName]; + } + var viewPortActivationStrategy = determineActivationStrategy(currentInstruction, prevViewPortInstruction, nextViewPortConfig, hasNewParams, forceLifecycleMinimum); + var viewPortPlan = viewPortPlans[viewPortName] = { + name: viewPortName, + // ViewPortInstruction can quack like a RouteConfig + config: nextViewPortConfig, + prevComponent: prevViewPortComponent, + prevModuleId: prevViewPortInstruction.moduleId, + strategy: viewPortActivationStrategy + }; + // recursively build nav plans for all existing child routers/viewports of this viewport + // this is possible because existing child viewports and routers already have necessary information + // to process the wildcard path from parent instruction + if (viewPortActivationStrategy !== "replace" /* Replace */ && prevViewPortInstruction.childRouter) { + var path = currentInstruction.getWildcardPath(); + var task = prevViewPortInstruction + .childRouter + ._createNavigationInstruction(path, currentInstruction) + .then(function (childInstruction) { + viewPortPlan.childNavigationInstruction = childInstruction; + return _buildNavigationPlan(childInstruction, + // is it safe to assume viewPortPlan has not been changed from previous assignment? + // if so, can just use local variable viewPortPlanStrategy + // there could be user code modifying viewport plan during _createNavigationInstruction? + viewPortPlan.strategy === "invoke-lifecycle" /* InvokeLifecycle */) + .then(function (childPlan) { + if (childPlan instanceof Redirect) { + return Promise.reject(childPlan); + } + childInstruction.plan = childPlan; + // for bluebird ? + return null; + }); + }); + pending.push(task); + } + }; + for (var viewPortName in previousViewPortInstructions) { + _loop_1(viewPortName); + } + return Promise.all(pending).then(function () { return viewPortPlans; }); + }; + /** + * @param newViewPortConfig if this is invoked on a viewport without any changes, based on new url, newViewPortConfig will be the existing viewport instruction + * @internal exported for unit testing + */ + var determineActivationStrategy = function (currentNavInstruction, prevViewPortInstruction, newViewPortConfig, + // indicates whether there is difference between old and new url params + hasNewParams, forceLifecycleMinimum) { + var newInstructionConfig = currentNavInstruction.config; + var prevViewPortViewModel = prevViewPortInstruction.component.viewModel; + var viewPortPlanStrategy; + if (prevViewPortInstruction.moduleId !== newViewPortConfig.moduleId) { + viewPortPlanStrategy = "replace" /* Replace */; + } + else if ('determineActivationStrategy' in prevViewPortViewModel) { + viewPortPlanStrategy = prevViewPortViewModel.determineActivationStrategy.apply(prevViewPortViewModel, currentNavInstruction.lifecycleArgs); + } + else if (newInstructionConfig.activationStrategy) { + viewPortPlanStrategy = newInstructionConfig.activationStrategy; + } + else if (hasNewParams || forceLifecycleMinimum) { + viewPortPlanStrategy = "invoke-lifecycle" /* InvokeLifecycle */; + } + else { + viewPortPlanStrategy = "no-change" /* NoChange */; + } + return viewPortPlanStrategy; + }; + /**@internal exported for unit testing */ + var hasDifferentParameterValues = function (prev, next) { + var prevParams = prev.params; + var nextParams = next.params; + var nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; + for (var key in nextParams) { + if (key === nextWildCardName) { + continue; + } + if (prevParams[key] !== nextParams[key]) { + return true; + } + } + for (var key in prevParams) { + if (key === nextWildCardName) { + continue; + } + if (prevParams[key] !== nextParams[key]) { + return true; + } + } + if (!next.options.compareQueryParams) { + return false; + } + var prevQueryParams = prev.queryParams; + var nextQueryParams = next.queryParams; + for (var key in nextQueryParams) { + if (prevQueryParams[key] !== nextQueryParams[key]) { + return true; + } + } + for (var key in prevQueryParams) { + if (prevQueryParams[key] !== nextQueryParams[key]) { + return true; + } + } + return false; + }; - /** - * A pipeline step for instructing a piepline to commit changes on a navigation instruction - */ - var CommitChangesStep = /** @class */ (function () { - function CommitChangesStep() { - } - CommitChangesStep.prototype.run = function (navigationInstruction, next) { - return navigationInstruction - ._commitChanges(/*wait to swap?*/ true) - .then(function () { - navigationInstruction._updateTitle(); - return next(); - }); - }; - return CommitChangesStep; - }()); - /** - * Class used to represent an instruction during a navigation. - */ - var NavigationInstruction = /** @class */ (function () { - function NavigationInstruction(init) { - /** - * Current built viewport plan of this nav instruction - */ - this.plan = null; - this.options = {}; - Object.assign(this, init); - this.params = this.params || {}; - this.viewPortInstructions = {}; - var ancestorParams = []; - var current = this; - do { - var currentParams = Object.assign({}, current.params); - if (current.config && current.config.hasChildRouter) { - // remove the param for the injected child route segment - delete currentParams[current.getWildCardName()]; - } - ancestorParams.unshift(currentParams); - current = current.parentInstruction; - } while (current); - var allParams = Object.assign.apply(Object, [{}, this.queryParams].concat(ancestorParams)); - this.lifecycleArgs = [allParams, this.config, this]; - } - /** - * Gets an array containing this instruction and all child instructions for the current navigation. - */ - NavigationInstruction.prototype.getAllInstructions = function () { - var instructions = [this]; - var viewPortInstructions = this.viewPortInstructions; - for (var key in viewPortInstructions) { - var childInstruction = viewPortInstructions[key].childNavigationInstruction; - if (childInstruction) { - instructions.push.apply(instructions, childInstruction.getAllInstructions()); - } - } - return instructions; - }; - /** - * Gets an array containing the instruction and all child instructions for the previous navigation. - * Previous instructions are no longer available after navigation completes. - */ - NavigationInstruction.prototype.getAllPreviousInstructions = function () { - return this.getAllInstructions().map(function (c) { return c.previousInstruction; }).filter(function (c) { return c; }); - }; - /** - * Adds a viewPort instruction. Returns the newly created instruction based on parameters - */ - NavigationInstruction.prototype.addViewPortInstruction = function (name, strategy, moduleId, component) { - var lifecycleArgs = this.lifecycleArgs; - var config = Object.assign({}, lifecycleArgs[1], { currentViewPort: name }); - var viewportInstruction = this.viewPortInstructions[name] = { - name: name, - strategy: strategy, - moduleId: moduleId, - component: component, - childRouter: component.childRouter, - lifecycleArgs: [].concat(lifecycleArgs[0], config, lifecycleArgs[2]) - }; - return viewportInstruction; - }; - /** - * Gets the name of the route pattern's wildcard parameter, if applicable. - */ - NavigationInstruction.prototype.getWildCardName = function () { - // todo: potential issue, or at least unsafe typings - var configRoute = this.config.route; - var wildcardIndex = configRoute.lastIndexOf('*'); - return configRoute.substr(wildcardIndex + 1); - }; - /** - * Gets the path and query string created by filling the route - * pattern's wildcard parameter with the matching param. - */ - NavigationInstruction.prototype.getWildcardPath = function () { - var wildcardName = this.getWildCardName(); - var path = this.params[wildcardName] || ''; - var queryString = this.queryString; - if (queryString) { - path += '?' + queryString; - } - return path; - }; - /** - * Gets the instruction's base URL, accounting for wildcard route parameters. - */ - NavigationInstruction.prototype.getBaseUrl = function () { - var _this = this; - var $encodeURI = encodeURI; - var fragment = decodeURI(this.fragment); - if (fragment === '') { - var nonEmptyRoute = this.router.routes.find(function (route) { - return route.name === _this.config.name && - route.route !== ''; - }); - if (nonEmptyRoute) { - fragment = nonEmptyRoute.route; - } - } - if (!this.params) { - return $encodeURI(fragment); - } - var wildcardName = this.getWildCardName(); - var path = this.params[wildcardName] || ''; - if (!path) { - return $encodeURI(fragment); - } - return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path))); - }; - /**@internal */ - NavigationInstruction.prototype._commitChanges = function (waitToSwap) { - var _this = this; - var router = this.router; - router.currentInstruction = this; - var previousInstruction = this.previousInstruction; - if (previousInstruction) { - previousInstruction.config.navModel.isActive = false; - } - this.config.navModel.isActive = true; - router.refreshNavigation(); - var loads = []; - var delaySwaps = []; - var viewPortInstructions = this.viewPortInstructions; - var _loop_1 = function (viewPortName) { - var viewPortInstruction = viewPortInstructions[viewPortName]; - var viewPort = router.viewPorts[viewPortName]; - if (!viewPort) { - throw new Error("There was no router-view found in the view for " + viewPortInstruction.moduleId + "."); - } - var child_nav_instruction = viewPortInstruction.childNavigationInstruction; - if (viewPortInstruction.strategy === activationStrategy.replace) { - if (child_nav_instruction && child_nav_instruction.parentCatchHandler) { - loads.push(child_nav_instruction._commitChanges(waitToSwap)); - } - else { - if (waitToSwap) { - delaySwaps.push({ viewPort: viewPort, viewPortInstruction: viewPortInstruction }); - } - loads.push(viewPort - .process(viewPortInstruction, waitToSwap) - .then(function () { return child_nav_instruction - ? child_nav_instruction._commitChanges(waitToSwap) - : Promise.resolve(); })); - } - } - else { - if (child_nav_instruction) { - loads.push(child_nav_instruction._commitChanges(waitToSwap)); - } - } - }; - for (var viewPortName in viewPortInstructions) { - _loop_1(viewPortName); - } - return Promise - .all(loads) - .then(function () { - delaySwaps.forEach(function (x) { return x.viewPort.swap(x.viewPortInstruction); }); - return null; - }) - .then(function () { return prune(_this); }); - }; - /**@internal */ - NavigationInstruction.prototype._updateTitle = function () { - var router = this.router; - var title = this._buildTitle(router.titleSeparator); - if (title) { - router.history.setTitle(title); - } - }; - /**@internal */ - NavigationInstruction.prototype._buildTitle = function (separator) { - if (separator === void 0) { separator = ' | '; } - var title = ''; - var childTitles = []; - var navModelTitle = this.config.navModel.title; - var instructionRouter = this.router; - var viewPortInstructions = this.viewPortInstructions; - if (navModelTitle) { - title = instructionRouter.transformTitle(navModelTitle); - } - for (var viewPortName in viewPortInstructions) { - var viewPortInstruction = viewPortInstructions[viewPortName]; - var child_nav_instruction = viewPortInstruction.childNavigationInstruction; - if (child_nav_instruction) { - var childTitle = child_nav_instruction._buildTitle(separator); - if (childTitle) { - childTitles.push(childTitle); - } - } - } - if (childTitles.length) { - title = childTitles.join(separator) + (title ? separator : '') + title; - } - if (instructionRouter.title) { - title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title); - } - return title; - }; - return NavigationInstruction; - }()); - var prune = function (instruction) { - instruction.previousInstruction = null; - instruction.plan = null; - }; + /** + * Transform a navigation instruction into viewport plan record object, + * or a redirect request if user viewmodel demands + */ + var BuildNavigationPlanStep = /** @class */ (function () { + function BuildNavigationPlanStep() { + } + BuildNavigationPlanStep.prototype.run = function (navigationInstruction, next) { + return _buildNavigationPlan(navigationInstruction) + .then(function (plan) { + if (plan instanceof Redirect) { + return next.cancel(plan); + } + navigationInstruction.plan = plan; + return next(); + }) + .catch(next.cancel); + }; + return BuildNavigationPlanStep; + }()); - /** - * Class for storing and interacting with a route's navigation settings. - */ - var NavModel = /** @class */ (function () { - function NavModel(router, relativeHref) { - /** - * True if this nav item is currently active. - */ - this.isActive = false; - /** - * The title. - */ - this.title = null; - /** - * This nav item's absolute href. - */ - this.href = null; - /** - * This nav item's relative href. - */ - this.relativeHref = null; - /** - * Data attached to the route at configuration time. - */ - this.settings = {}; - /** - * The route config. - */ - this.config = null; - this.router = router; - this.relativeHref = relativeHref; - } - /** - * Sets the route's title and updates document.title. - * If the a navigation is in progress, the change will be applied - * to document.title when the navigation completes. - * - * @param title The new title. - */ - NavModel.prototype.setTitle = function (title) { - this.title = title; - if (this.isActive) { - this.router.updateTitle(); - } - }; - return NavModel; - }()); + /** + * @internal Exported for unit testing + */ + var loadNewRoute = function (routeLoader, navigationInstruction) { + var loadingPlans = determineLoadingPlans(navigationInstruction); + var loadPromises = loadingPlans.map(function (loadingPlan) { return loadRoute(routeLoader, loadingPlan.navigationInstruction, loadingPlan.viewPortPlan); }); + return Promise.all(loadPromises); + }; + /** + * @internal Exported for unit testing + */ + var determineLoadingPlans = function (navigationInstruction, loadingPlans) { + if (loadingPlans === void 0) { loadingPlans = []; } + var viewPortPlans = navigationInstruction.plan; + for (var viewPortName in viewPortPlans) { + var viewPortPlan = viewPortPlans[viewPortName]; + var childNavInstruction = viewPortPlan.childNavigationInstruction; + if (viewPortPlan.strategy === "replace" /* Replace */) { + loadingPlans.push({ viewPortPlan: viewPortPlan, navigationInstruction: navigationInstruction }); + if (childNavInstruction) { + determineLoadingPlans(childNavInstruction, loadingPlans); + } + } + else { + var viewPortInstruction = navigationInstruction.addViewPortInstruction({ + name: viewPortName, + strategy: viewPortPlan.strategy, + moduleId: viewPortPlan.prevModuleId, + component: viewPortPlan.prevComponent + }); + if (childNavInstruction) { + viewPortInstruction.childNavigationInstruction = childNavInstruction; + determineLoadingPlans(childNavInstruction, loadingPlans); + } + } + } + return loadingPlans; + }; + /** + * @internal Exported for unit testing + */ + var loadRoute = function (routeLoader, navigationInstruction, viewPortPlan) { + var planConfig = viewPortPlan.config; + var moduleId = planConfig ? planConfig.moduleId : null; + return loadComponent(routeLoader, navigationInstruction, planConfig) + .then(function (component) { + var viewPortInstruction = navigationInstruction.addViewPortInstruction({ + name: viewPortPlan.name, + strategy: viewPortPlan.strategy, + moduleId: moduleId, + component: component + }); + var childRouter = component.childRouter; + if (childRouter) { + var path = navigationInstruction.getWildcardPath(); + return childRouter + ._createNavigationInstruction(path, navigationInstruction) + .then(function (childInstruction) { + viewPortPlan.childNavigationInstruction = childInstruction; + return _buildNavigationPlan(childInstruction) + .then(function (childPlan) { + if (childPlan instanceof Redirect) { + return Promise.reject(childPlan); + } + childInstruction.plan = childPlan; + viewPortInstruction.childNavigationInstruction = childInstruction; + return loadNewRoute(routeLoader, childInstruction); + }); + }); + } + // ts complains without this, though they are same + return void 0; + }); + }; + /** + * Load a routed-component based on navigation instruction and route config + * @internal exported for unit testing only + */ + var loadComponent = function (routeLoader, navigationInstruction, config) { + var router = navigationInstruction.router; + var lifecycleArgs = navigationInstruction.lifecycleArgs; + return Promise.resolve() + .then(function () { return routeLoader.loadRoute(router, config, navigationInstruction); }) + .then( + /** + * @param component an object carrying information about loaded route + * typically contains information about view model, childContainer, view and router + */ + function (component) { + var viewModel = component.viewModel, childContainer = component.childContainer; + component.router = router; + component.config = config; + if ('configureRouter' in viewModel) { + var childRouter_1 = childContainer.getChildRouter(); + component.childRouter = childRouter_1; + return childRouter_1 + .configure(function (c) { return viewModel.configureRouter(c, childRouter_1, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]); }) + .then(function () { return component; }); + } + return component; + }); + }; - function _normalizeAbsolutePath(path, hasPushState, absolute) { - if (absolute === void 0) { absolute = false; } - if (!hasPushState && path[0] !== '#') { - path = '#' + path; - } - if (hasPushState && absolute) { - path = path.substring(1, path.length); - } - return path; - } - function _createRootedPath(fragment, baseUrl, hasPushState, absolute) { - if (isAbsoluteUrl.test(fragment)) { - return fragment; - } - var path = ''; - if (baseUrl.length && baseUrl[0] !== '/') { - path += '/'; - } - path += baseUrl; - if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') { - path += '/'; - } - if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') { - path = path.substring(0, path.length - 1); - } - return _normalizeAbsolutePath(path + fragment, hasPushState, absolute); - } - function _resolveUrl(fragment, baseUrl, hasPushState) { - if (isRootedPath.test(fragment)) { - return _normalizeAbsolutePath(fragment, hasPushState); - } - return _createRootedPath(fragment, baseUrl, hasPushState); - } - function _ensureArrayWithSingleRoutePerConfig(config) { - var routeConfigs = []; - if (Array.isArray(config.route)) { - for (var i = 0, ii = config.route.length; i < ii; ++i) { - var current = Object.assign({}, config); - current.route = config.route[i]; - routeConfigs.push(current); - } - } - else { - routeConfigs.push(Object.assign({}, config)); - } - return routeConfigs; - } - var isRootedPath = /^#?\//; - var isAbsoluteUrl = /^([a-z][a-z0-9+\-.]*:)?\/\//i; + /** + * Abstract class that is responsible for loading view / view model from a route config + * The default implementation can be found in `aurelia-templating-router` + */ + var RouteLoader = /** @class */ (function () { + function RouteLoader() { + } + /** + * Load a route config based on its viewmodel / view configuration + */ + // return typing: return typings used to be never + // as it was a throw. Changing it to Promise should not cause any issues + RouteLoader.prototype.loadRoute = function (router, config, navigationInstruction) { + throw new Error('Route loaders must implement "loadRoute(router, config, navigationInstruction)".'); + }; + return RouteLoader; + }()); - /** - * Class used to configure a [[Router]] instance. - * - * @constructor - */ - var RouterConfiguration = /** @class */ (function () { - function RouterConfiguration() { - this.instructions = []; - this.options = {}; - this.pipelineSteps = []; - } - /** - * Adds a step to be run during the [[Router]]'s navigation pipeline. - * - * @param name The name of the pipeline slot to insert the step into. - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPipelineStep = function (name, step) { - if (step === null || step === undefined) { - throw new Error('Pipeline step cannot be null or undefined.'); - } - this.pipelineSteps.push({ name: name, step: step }); - return this; - }; - /** - * Adds a step to be run during the [[Router]]'s authorize pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addAuthorizeStep = function (step) { - return this.addPipelineStep("authorize" /* Authorize */, step); - }; - /** - * Adds a step to be run during the [[Router]]'s preActivate pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPreActivateStep = function (step) { - return this.addPipelineStep("preActivate" /* PreActivate */, step); - }; - /** - * Adds a step to be run during the [[Router]]'s preRender pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPreRenderStep = function (step) { - return this.addPipelineStep("preRender" /* PreRender */, step); - }; - /** - * Adds a step to be run during the [[Router]]'s postRender pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPostRenderStep = function (step) { - return this.addPipelineStep("postRender" /* PostRender */, step); - }; - /** - * Configures a route that will be used if there is no previous location available on navigation cancellation. - * - * @param fragment The URL fragment to use as the navigation destination. - * @chainable - */ - RouterConfiguration.prototype.fallbackRoute = function (fragment) { - this._fallbackRoute = fragment; - return this; - }; - /** - * Maps one or more routes to be registered with the router. - * - * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map. - * @chainable - */ - RouterConfiguration.prototype.map = function (route) { - if (Array.isArray(route)) { - route.forEach(this.map.bind(this)); - return this; - } - return this.mapRoute(route); - }; - /** - * Configures defaults to use for any view ports. - * - * @param viewPortConfig a view port configuration object to use as a - * default, of the form { viewPortName: { moduleId } }. - * @chainable - */ - RouterConfiguration.prototype.useViewPortDefaults = function (viewPortConfig) { - this.viewPortDefaults = viewPortConfig; - return this; - }; - /** - * Maps a single route to be registered with the router. - * - * @param route The [[RouteConfig]] to map. - * @chainable - */ - RouterConfiguration.prototype.mapRoute = function (config) { - this.instructions.push(function (router) { - var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); - var navModel; - for (var i = 0, ii = routeConfigs.length; i < ii; ++i) { - var routeConfig = routeConfigs[i]; - routeConfig.settings = routeConfig.settings || {}; - if (!navModel) { - navModel = router.createNavModel(routeConfig); - } - router.addRoute(routeConfig, navModel); - } - }); - return this; - }; - /** - * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes. - * - * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the - * [[NavigationInstruction]] and selects a moduleId to load. - * @chainable - */ - RouterConfiguration.prototype.mapUnknownRoutes = function (config) { - this.unknownRouteConfig = config; - return this; - }; - /** - * Applies the current configuration to the specified [[Router]]. - * - * @param router The [[Router]] to apply the configuration to. - */ - RouterConfiguration.prototype.exportToRouter = function (router) { - var instructions = this.instructions; - for (var i = 0, ii = instructions.length; i < ii; ++i) { - instructions[i](router); - } - if (this.title) { - router.title = this.title; - } - if (this.titleSeparator) { - router.titleSeparator = this.titleSeparator; - } - if (this.unknownRouteConfig) { - router.handleUnknownRoutes(this.unknownRouteConfig); - } - if (this._fallbackRoute) { - router.fallbackRoute = this._fallbackRoute; - } - if (this.viewPortDefaults) { - router.useViewPortDefaults(this.viewPortDefaults); - } - Object.assign(router.options, this.options); - var pipelineSteps = this.pipelineSteps; - if (pipelineSteps.length) { - if (!router.isRoot) { - throw new Error('Pipeline steps can only be added to the root router'); - } - var pipelineProvider = router.pipelineProvider; - for (var i = 0, ii = pipelineSteps.length; i < ii; ++i) { - var _a = pipelineSteps[i], name_1 = _a.name, step = _a.step; - pipelineProvider.addStep(name_1, step); - } - } - }; - return RouterConfiguration; - }()); + /** + * A pipeline step responsible for loading a route config of a navigation instruction + */ + var LoadRouteStep = /** @class */ (function () { + function LoadRouteStep(routeLoader) { + this.routeLoader = routeLoader; + } + /**@internal */ + LoadRouteStep.inject = function () { return [RouteLoader]; }; + /** + * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline + */ + LoadRouteStep.prototype.run = function (navigationInstruction, next) { + return loadNewRoute(this.routeLoader, navigationInstruction) + .then(next, next.cancel); + }; + return LoadRouteStep; + }()); - /** - * The primary class responsible for handling routing and navigation. - */ - var Router = /** @class */ (function () { - /** - * @param container The [[Container]] to use when child routers. - * @param history The [[History]] implementation to delegate navigation requests to. - */ - function Router(container, history) { - var _this = this; - /** - * The parent router, or null if this instance is not a child router. - */ - this.parent = null; - this.options = {}; - /** - * The defaults used when a viewport lacks specified content - */ - this.viewPortDefaults = {}; - /** - * Extension point to transform the document title before it is built and displayed. - * By default, child routers delegate to the parent router, and the app router - * returns the title unchanged. - */ - this.transformTitle = function (title) { - if (_this.parent) { - return _this.parent.transformTitle(title); - } - return title; - }; - this.container = container; - this.history = history; - this.reset(); - } - /** - * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. - * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. - */ - Router.prototype.reset = function () { - var _this = this; - this.viewPorts = {}; - this.routes = []; - this.baseUrl = ''; - this.isConfigured = false; - this.isNavigating = false; - this.isExplicitNavigation = false; - this.isExplicitNavigationBack = false; - this.isNavigatingFirst = false; - this.isNavigatingNew = false; - this.isNavigatingRefresh = false; - this.isNavigatingForward = false; - this.isNavigatingBack = false; - this.couldDeactivate = false; - this.navigation = []; - this.currentInstruction = null; - this.viewPortDefaults = {}; - this._fallbackOrder = 100; - this._recognizer = new aureliaRouteRecognizer.RouteRecognizer(); - this._childRecognizer = new aureliaRouteRecognizer.RouteRecognizer(); - this._configuredPromise = new Promise(function (resolve) { - _this._resolveConfiguredPromise = resolve; - }); - }; - Object.defineProperty(Router.prototype, "isRoot", { - /** - * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent. - */ - get: function () { - return !this.parent; - }, - enumerable: true, - configurable: true - }); - /** - * Registers a viewPort to be used as a rendering target for activated routes. - * - * @param viewPort The viewPort. - * @param name The name of the viewPort. 'default' if unspecified. - */ - Router.prototype.registerViewPort = function (viewPort, name) { - name = name || 'default'; - this.viewPorts[name] = viewPort; - }; - /** - * Returns a Promise that resolves when the router is configured. - */ - Router.prototype.ensureConfigured = function () { - return this._configuredPromise; - }; - /** - * Configures the router. - * - * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]]. - */ - Router.prototype.configure = function (callbackOrConfig) { - var _this = this; - this.isConfigured = true; - var result = callbackOrConfig; - var config; - if (typeof callbackOrConfig === 'function') { - config = new RouterConfiguration(); - result = callbackOrConfig(config); - } - return Promise - .resolve(result) - .then(function (c) { - if (c && c.exportToRouter) { - config = c; - } - config.exportToRouter(_this); - _this.isConfigured = true; - _this._resolveConfiguredPromise(); - }); - }; - /** - * Navigates to a new location. - * - * @param fragment The URL fragment to use as the navigation destination. - * @param options The navigation options. - */ - Router.prototype.navigate = function (fragment, options) { - if (!this.isConfigured && this.parent) { - return this.parent.navigate(fragment, options); - } - this.isExplicitNavigation = true; - return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options); - }; - /** - * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed - * by [[Router.navigate]]. - * - * @param route The name of the route to use when generating the navigation location. - * @param params The route parameters to be used when populating the route pattern. - * @param options The navigation options. - */ - Router.prototype.navigateToRoute = function (route, params, options) { - var path = this.generate(route, params); - return this.navigate(path, options); - }; - /** - * Navigates back to the most recent location in history. - */ - Router.prototype.navigateBack = function () { - this.isExplicitNavigationBack = true; - this.history.navigateBack(); - }; - /** - * Creates a child router of the current router. - * - * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified. - * @returns {Router} The new child Router. - */ - Router.prototype.createChild = function (container) { - var childRouter = new Router(container || this.container.createChild(), this.history); - childRouter.parent = this; - return childRouter; - }; - /** - * Generates a URL fragment matching the specified route pattern. - * - * @param name The name of the route whose pattern should be used to generate the fragment. - * @param params The route params to be used to populate the route pattern. - * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url. - * @returns {string} A string containing the generated URL fragment. - */ - Router.prototype.generate = function (nameOrRoute, params, options) { - if (params === void 0) { params = {}; } - if (options === void 0) { options = {}; } - // A child recognizer generates routes for potential child routes. Any potential child route is added - // to the childRoute property of params for the childRouter to recognize. When generating routes, we - // use the childRecognizer when childRoute params are available to generate a child router enabled route. - var recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer; - var hasRoute = recognizer.hasRoute(nameOrRoute); - if (!hasRoute) { - if (this.parent) { - return this.parent.generate(nameOrRoute, params, options); - } - throw new Error("A route with name '" + nameOrRoute + "' could not be found. Check that `name: '" + nameOrRoute + "'` was specified in the route's config."); - } - var path = recognizer.generate(nameOrRoute, params); - var rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute); - return options.absolute ? "" + this.history.getAbsoluteRoot() + rootedPath : rootedPath; - }; - /** - * Creates a [[NavModel]] for the specified route config. - * - * @param config The route config. - */ - Router.prototype.createNavModel = function (config) { - var navModel = new NavModel(this, 'href' in config - ? config.href - // potential error when config.route is a string[] ? - : config.route); - navModel.title = config.title; - navModel.order = config.nav; - navModel.href = config.href; - navModel.settings = config.settings; - navModel.config = config; - return navModel; - }; - /** - * Registers a new route with the router. - * - * @param config The [[RouteConfig]]. - * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes. - */ - Router.prototype.addRoute = function (config, navModel) { - if (Array.isArray(config.route)) { - var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); - // the following is wrong. todo: fix this after TS refactoring release - routeConfigs.forEach(this.addRoute.bind(this)); - return; - } - validateRouteConfig(config); - if (!('viewPorts' in config) && !config.navigationStrategy) { - config.viewPorts = { - 'default': { - moduleId: config.moduleId, - view: config.view - } - }; - } - if (!navModel) { - navModel = this.createNavModel(config); - } - this.routes.push(config); - var path = config.route; - if (path.charAt(0) === '/') { - path = path.substr(1); - } - var caseSensitive = config.caseSensitive === true; - var state = this._recognizer.add({ - path: path, - handler: config, - caseSensitive: caseSensitive - }); - if (path) { - var settings = config.settings; - delete config.settings; - var withChild = JSON.parse(JSON.stringify(config)); - config.settings = settings; - withChild.route = path + "/*childRoute"; - withChild.hasChildRouter = true; - this._childRecognizer.add({ - path: withChild.route, - handler: withChild, - caseSensitive: caseSensitive - }); - withChild.navModel = navModel; - withChild.settings = config.settings; - withChild.navigationStrategy = config.navigationStrategy; - } - config.navModel = navModel; - var navigation = this.navigation; - if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) { - if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) { - throw new Error('Invalid route config for "' + config.route + '" : dynamic routes must specify an "href:" to be included in the navigation model.'); - } - if (typeof navModel.order !== 'number') { - navModel.order = ++this._fallbackOrder; - } - navigation.push(navModel); - // this is a potential error / inconsistency between browsers - // - // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort - // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, - // but sorted with respect to all different elements. - // Note: the ECMAscript standard does not guarantee this behaviour, - // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this. - navigation.sort(function (a, b) { return a.order - b.order; }); - } - }; - /** - * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name. - * - * @param name The name of the route to check. - */ - Router.prototype.hasRoute = function (name) { - return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name)); - }; - /** - * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name. - * - * @param name The name of the route to check. - */ - Router.prototype.hasOwnRoute = function (name) { - return this._recognizer.hasRoute(name); - }; - /** - * Register a handler to use when the incoming URL fragment doesn't match any registered routes. - * - * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]]. - */ - Router.prototype.handleUnknownRoutes = function (config) { - var _this = this; - if (!config) { - throw new Error('Invalid unknown route handler'); - } - this.catchAllHandler = function (instruction) { - return _this - ._createRouteConfig(config, instruction) - .then(function (c) { - instruction.config = c; - return instruction; - }); - }; - }; - /** - * Updates the document title using the current navigation instruction. - */ - Router.prototype.updateTitle = function () { - var parentRouter = this.parent; - if (parentRouter) { - return parentRouter.updateTitle(); - } - var currentInstruction = this.currentInstruction; - if (currentInstruction) { - currentInstruction._updateTitle(); - } - return undefined; - }; - /** - * Updates the navigation routes with hrefs relative to the current location. - * Note: This method will likely move to a plugin in a future release. - */ - Router.prototype.refreshNavigation = function () { - var nav = this.navigation; - for (var i = 0, length_1 = nav.length; i < length_1; i++) { - var current = nav[i]; - if (!current.config.href) { - current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState); - } - else { - current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState); - } - } - }; - /** - * Sets the default configuration for the view ports. This specifies how to - * populate a view port for which no module is specified. The default is - * an empty view/view-model pair. - */ - Router.prototype.useViewPortDefaults = function ($viewPortDefaults) { - // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction - var viewPortDefaults = $viewPortDefaults; - for (var viewPortName in viewPortDefaults) { - var viewPortConfig = viewPortDefaults[viewPortName]; - this.viewPortDefaults[viewPortName] = { - moduleId: viewPortConfig.moduleId - }; - } - }; - /**@internal */ - Router.prototype._refreshBaseUrl = function () { - var parentRouter = this.parent; - if (parentRouter) { - this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction); - } - }; - /**@internal */ - Router.prototype._createNavigationInstruction = function (url, parentInstruction) { - if (url === void 0) { url = ''; } - if (parentInstruction === void 0) { parentInstruction = null; } - var fragment = url; - var queryString = ''; - var queryIndex = url.indexOf('?'); - if (queryIndex !== -1) { - fragment = url.substr(0, queryIndex); - queryString = url.substr(queryIndex + 1); - } - var urlRecognizationResults = this._recognizer.recognize(url); - if (!urlRecognizationResults || !urlRecognizationResults.length) { - urlRecognizationResults = this._childRecognizer.recognize(url); - } - var instructionInit = { - fragment: fragment, - queryString: queryString, - config: null, - parentInstruction: parentInstruction, - previousInstruction: this.currentInstruction, - router: this, - options: { - compareQueryParams: this.options.compareQueryParams - } - }; - var result; - if (urlRecognizationResults && urlRecognizationResults.length) { - var first = urlRecognizationResults[0]; - var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: first.params, - queryParams: first.queryParams || urlRecognizationResults.queryParams, - config: first.config || first.handler - })); - if (typeof first.handler === 'function') { - result = evaluateNavigationStrategy(instruction, first.handler, first); - } - else if (first.handler && typeof first.handler.navigationStrategy === 'function') { - result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); - } - else { - result = Promise.resolve(instruction); - } - } - else if (this.catchAllHandler) { - var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: { path: fragment }, - queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, - config: null // config will be created by the catchAllHandler - })); - result = evaluateNavigationStrategy(instruction, this.catchAllHandler); - } - else if (this.parent) { - var router = this._parentCatchAllHandler(this.parent); - if (router) { - var newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction); - var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: { path: fragment }, - queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, - router: router, - parentInstruction: newParentInstruction, - parentCatchHandler: true, - config: null // config will be created by the chained parent catchAllHandler - })); - result = evaluateNavigationStrategy(instruction, router.catchAllHandler); - } - } - if (result && parentInstruction) { - this.baseUrl = generateBaseUrl(this.parent, parentInstruction); - } - return result || Promise.reject(new Error("Route not found: " + url)); - }; - /**@internal */ - Router.prototype._findParentInstructionFromRouter = function (router, instruction) { - if (instruction.router === router) { - instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId - return instruction; - } - else if (instruction.parentInstruction) { - return this._findParentInstructionFromRouter(router, instruction.parentInstruction); - } - return undefined; - }; - /**@internal */ - Router.prototype._parentCatchAllHandler = function (router) { - if (router.catchAllHandler) { - return router; - } - else if (router.parent) { - return this._parentCatchAllHandler(router.parent); - } - return false; - }; - /** - * @internal - */ - Router.prototype._createRouteConfig = function (config, instruction) { - var _this = this; - return Promise - .resolve(config) - .then(function (c) { - if (typeof c === 'string') { - return { moduleId: c }; - } - else if (typeof c === 'function') { - return c(instruction); - } - return c; - }) - // typing here could be either RouteConfig or RedirectConfig - // but temporarily treat both as RouteConfig - // todo: improve typings precision - .then(function (c) { return typeof c === 'string' ? { moduleId: c } : c; }) - .then(function (c) { - c.route = instruction.params.path; - validateRouteConfig(c); - if (!c.navModel) { - c.navModel = _this.createNavModel(c); - } - return c; - }); - }; - return Router; - }()); - /* @internal exported for unit testing */ - var generateBaseUrl = function (router, instruction) { - return "" + (router.baseUrl || '') + (instruction.getBaseUrl() || ''); - }; - /* @internal exported for unit testing */ - var validateRouteConfig = function (config) { - if (typeof config !== 'object') { - throw new Error('Invalid Route Config'); - } - if (typeof config.route !== 'string') { - var name_1 = config.name || '(no name)'; - throw new Error('Invalid Route Config for "' + name_1 + '": You must specify a "route:" pattern.'); - } - if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) { - throw new Error('Invalid Route Config for "' + config.route + '": You must specify a "moduleId:", "redirect:", "navigationStrategy:", or "viewPorts:".'); - } - }; - /* @internal exported for unit testing */ - var evaluateNavigationStrategy = function (instruction, evaluator, context) { - return Promise.resolve(evaluator.call(context, instruction)).then(function () { - if (!('viewPorts' in instruction.config)) { - instruction.config.viewPorts = { - 'default': { - moduleId: instruction.config.moduleId - } - }; - } - return instruction; - }); - }; + /** + * A pipeline step for instructing a piepline to commit changes on a navigation instruction + */ + var CommitChangesStep = /** @class */ (function () { + function CommitChangesStep() { + } + CommitChangesStep.prototype.run = function (navigationInstruction, next) { + return navigationInstruction + ._commitChanges(/*wait to swap?*/ true) + .then(function () { + navigationInstruction._updateTitle(); + return next(); + }); + }; + return CommitChangesStep; + }()); - /**@internal exported for unit testing */ - var createNextFn = function (instruction, steps) { - var index = -1; - var next = function () { - index++; - if (index < steps.length) { - var currentStep = steps[index]; - try { - return currentStep(instruction, next); - } - catch (e) { - return next.reject(e); - } - } - else { - return next.complete(); - } - }; - next.complete = createCompletionHandler(next, "completed" /* Completed */); - next.cancel = createCompletionHandler(next, "canceled" /* Canceled */); - next.reject = createCompletionHandler(next, "rejected" /* Rejected */); - return next; - }; - /**@internal exported for unit testing */ - var createCompletionHandler = function (next, status) { - return function (output) { return Promise - .resolve({ - status: status, - output: output, - completed: status === "completed" /* Completed */ - }); }; - }; + /** + * An optional interface describing the available activation strategies. + * @internal Used internally. + */ + var InternalActivationStrategy; + (function (InternalActivationStrategy) { + /** + * Reuse the existing view model, without invoking Router lifecycle hooks. + */ + InternalActivationStrategy["NoChange"] = "no-change"; + /** + * Reuse the existing view model, invoking Router lifecycle hooks. + */ + InternalActivationStrategy["InvokeLifecycle"] = "invoke-lifecycle"; + /** + * Replace the existing view model, invoking Router lifecycle hooks. + */ + InternalActivationStrategy["Replace"] = "replace"; + })(InternalActivationStrategy || (InternalActivationStrategy = {})); + /** + * The strategy to use when activating modules during navigation. + */ + // kept for compat reason + var activationStrategy = { + noChange: "no-change" /* NoChange */, + invokeLifecycle: "invoke-lifecycle" /* InvokeLifecycle */, + replace: "replace" /* Replace */ + }; - /** - * The class responsible for managing and processing the navigation pipeline. - */ - var Pipeline = /** @class */ (function () { - function Pipeline() { - /** - * The pipeline steps. And steps added via addStep will be converted to a function - * The actualy running functions with correct step contexts of this pipeline - */ - this.steps = []; - } - /** - * Adds a step to the pipeline. - * - * @param step The pipeline step. - */ - Pipeline.prototype.addStep = function (step) { - var run; - if (typeof step === 'function') { - run = step; - } - else if (typeof step.getSteps === 'function') { - // getSteps is to enable support open slots - // where devs can add multiple steps into the same slot name - var steps = step.getSteps(); - for (var i = 0, l = steps.length; i < l; i++) { - this.addStep(steps[i]); - } - return this; - } - else { - run = step.run.bind(step); - } - this.steps.push(run); - return this; - }; - /** - * Runs the pipeline. - * - * @param instruction The navigation instruction to process. - */ - Pipeline.prototype.run = function (instruction) { - var nextFn = createNextFn(instruction, this.steps); - return nextFn(); - }; - return Pipeline; - }()); + /** + * Recursively find list of deactivate-able view models + * and invoke the either 'canDeactivate' or 'deactivate' on each + * @internal exported for unit testing + */ + var processDeactivatable = function (navigationInstruction, callbackName, next, ignoreResult) { + var plan = navigationInstruction.plan; + var infos = findDeactivatable(plan, callbackName); + var i = infos.length; // query from inside out + function inspect(val) { + if (ignoreResult || shouldContinue(val)) { + return iterate(); + } + return next.cancel(val); + } + function iterate() { + if (i--) { + try { + var viewModel = infos[i]; + var result = viewModel[callbackName](navigationInstruction); + return processPotential(result, inspect, next.cancel); + } + catch (error) { + return next.cancel(error); + } + } + navigationInstruction.router.couldDeactivate = true; + return next(); + } + return iterate(); + }; + /** + * Recursively find and returns a list of deactivate-able view models + * @internal exported for unit testing + */ + var findDeactivatable = function (plan, callbackName, list) { + if (list === void 0) { list = []; } + for (var viewPortName in plan) { + var viewPortPlan = plan[viewPortName]; + var prevComponent = viewPortPlan.prevComponent; + if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace) + && prevComponent) { + var viewModel = prevComponent.viewModel; + if (callbackName in viewModel) { + list.push(viewModel); + } + } + if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) { + addPreviousDeactivatable(prevComponent, callbackName, list); + } + else if (viewPortPlan.childNavigationInstruction) { + findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list); + } + } + return list; + }; + /** + * @internal exported for unit testing + */ + var addPreviousDeactivatable = function (component, callbackName, list) { + var childRouter = component.childRouter; + if (childRouter && childRouter.currentInstruction) { + var viewPortInstructions = childRouter.currentInstruction.viewPortInstructions; + for (var viewPortName in viewPortInstructions) { + var viewPortInstruction = viewPortInstructions[viewPortName]; + var prevComponent = viewPortInstruction.component; + var prevViewModel = prevComponent.viewModel; + if (callbackName in prevViewModel) { + list.push(prevViewModel); + } + addPreviousDeactivatable(prevComponent, callbackName, list); + } + } + }; + /** + * @internal exported for unit testing + */ + var processActivatable = function (navigationInstruction, callbackName, next, ignoreResult) { + var infos = findActivatable(navigationInstruction, callbackName); + var length = infos.length; + var i = -1; // query from top down + function inspect(val, router) { + if (ignoreResult || shouldContinue(val, router)) { + return iterate(); + } + return next.cancel(val); + } + function iterate() { + var _a; + i++; + if (i < length) { + try { + var current_1 = infos[i]; + var result = (_a = current_1.viewModel)[callbackName].apply(_a, current_1.lifecycleArgs); + return processPotential(result, function (val) { return inspect(val, current_1.router); }, next.cancel); + } + catch (error) { + return next.cancel(error); + } + } + return next(); + } + return iterate(); + }; + /** + * Find list of activatable view model and add to list (3rd parameter) + * @internal exported for unit testing + */ + var findActivatable = function (navigationInstruction, callbackName, list, router) { + if (list === void 0) { list = []; } + var plan = navigationInstruction.plan; + Object + .keys(plan) + .forEach(function (viewPortName) { + var viewPortPlan = plan[viewPortName]; + var viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName]; + var viewPortComponent = viewPortInstruction.component; + var viewModel = viewPortComponent.viewModel; + if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle + || viewPortPlan.strategy === activationStrategy.replace) + && callbackName in viewModel) { + list.push({ + viewModel: viewModel, + lifecycleArgs: viewPortInstruction.lifecycleArgs, + router: router + }); + } + var childNavInstruction = viewPortPlan.childNavigationInstruction; + if (childNavInstruction) { + findActivatable(childNavInstruction, callbackName, list, viewPortComponent.childRouter || router); + } + }); + return list; + }; + var shouldContinue = function (output, router) { + if (output instanceof Error) { + return false; + } + if (isNavigationCommand(output)) { + if (typeof output.setRouter === 'function') { + output.setRouter(router); + } + return !!output.shouldContinueProcessing; + } + if (output === undefined) { + return true; + } + return output; + }; + /** + * wraps a subscription, allowing unsubscribe calls even if + * the first value comes synchronously + */ + var SafeSubscription = /** @class */ (function () { + function SafeSubscription(subscriptionFunc) { + this._subscribed = true; + this._subscription = subscriptionFunc(this); + if (!this._subscribed) { + this.unsubscribe(); + } + } + Object.defineProperty(SafeSubscription.prototype, "subscribed", { + get: function () { + return this._subscribed; + }, + enumerable: true, + configurable: true + }); + SafeSubscription.prototype.unsubscribe = function () { + if (this._subscribed && this._subscription) { + this._subscription.unsubscribe(); + } + this._subscribed = false; + }; + return SafeSubscription; + }()); + /** + * A function to process return value from `activate`/`canActivate` steps + * Supports observable/promise + * + * For observable, resolve at first next() or on complete() + */ + var processPotential = function (obj, resolve, reject) { + // if promise like + if (obj && typeof obj.then === 'function') { + return Promise.resolve(obj).then(resolve).catch(reject); + } + // if observable + if (obj && typeof obj.subscribe === 'function') { + var obs_1 = obj; + return new SafeSubscription(function (sub) { return obs_1.subscribe({ + next: function () { + if (sub.subscribed) { + sub.unsubscribe(); + resolve(obj); + } + }, + error: function (error) { + if (sub.subscribed) { + sub.unsubscribe(); + reject(error); + } + }, + complete: function () { + if (sub.subscribed) { + sub.unsubscribe(); + resolve(obj); + } + } + }); }); + } + // else just resolve + try { + return resolve(obj); + } + catch (error) { + return reject(error); + } + }; - /** - * Abstract class that is responsible for loading view / view model from a route config - * The default implementation can be found in `aurelia-templating-router` - */ - var RouteLoader = /** @class */ (function () { - function RouteLoader() { - } - /** - * Load a route config based on its viewmodel / view configuration - */ - // return typing: return typings used to be never - // as it was a throw. Changing it to Promise should not cause any issues - RouteLoader.prototype.loadRoute = function (router, config, navigationInstruction) { - throw new Error('Route loaders must implement "loadRoute(router, config, navigationInstruction)".'); - }; - return RouteLoader; - }()); - /** - * A pipeline step responsible for loading a route config of a navigation instruction - */ - var LoadRouteStep = /** @class */ (function () { - function LoadRouteStep(routeLoader) { - this.routeLoader = routeLoader; - } - /**@internal */ - LoadRouteStep.inject = function () { return [RouteLoader]; }; - /** - * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline - */ - LoadRouteStep.prototype.run = function (navigationInstruction, next) { - return loadNewRoute(this.routeLoader, navigationInstruction) - .then(next, next.cancel); - }; - return LoadRouteStep; - }()); - /** - * @internal Exported for unit testing - */ - var loadNewRoute = function (routeLoader, navigationInstruction) { - var toLoad = determineWhatToLoad(navigationInstruction); - var loadPromises = toLoad.map(function (loadingPlan) { return loadRoute(routeLoader, loadingPlan.navigationInstruction, loadingPlan.viewPortPlan); }); - return Promise.all(loadPromises); - }; - /** - * @internal Exported for unit testing - */ - var determineWhatToLoad = function (navigationInstruction, toLoad) { - if (toLoad === void 0) { toLoad = []; } - var plan = navigationInstruction.plan; - for (var viewPortName in plan) { - var viewPortPlan = plan[viewPortName]; - var child_nav_instruction = viewPortPlan.childNavigationInstruction; - if (viewPortPlan.strategy === activationStrategy.replace) { - toLoad.push({ viewPortPlan: viewPortPlan, navigationInstruction: navigationInstruction }); - if (child_nav_instruction) { - determineWhatToLoad(child_nav_instruction, toLoad); - } - } - else { - var viewPortInstruction = navigationInstruction.addViewPortInstruction(viewPortName, viewPortPlan.strategy, viewPortPlan.prevModuleId, viewPortPlan.prevComponent); - if (child_nav_instruction) { - viewPortInstruction.childNavigationInstruction = child_nav_instruction; - determineWhatToLoad(child_nav_instruction, toLoad); - } - } - } - return toLoad; - }; - /** - * @internal Exported for unit testing - */ - var loadRoute = function (routeLoader, navigationInstruction, viewPortPlan) { - var moduleId = viewPortPlan.config ? viewPortPlan.config.moduleId : null; - return loadComponent(routeLoader, navigationInstruction, viewPortPlan.config) - .then(function (component) { - var viewPortInstruction = navigationInstruction.addViewPortInstruction(viewPortPlan.name, viewPortPlan.strategy, moduleId, component); - var childRouter = component.childRouter; - if (childRouter) { - var path = navigationInstruction.getWildcardPath(); - return childRouter - ._createNavigationInstruction(path, navigationInstruction) - .then(function (childInstruction) { - viewPortPlan.childNavigationInstruction = childInstruction; - return _buildNavigationPlan(childInstruction) - .then(function (childPlan) { - if (childPlan instanceof Redirect) { - return Promise.reject(childPlan); - } - childInstruction.plan = childPlan; - viewPortInstruction.childNavigationInstruction = childInstruction; - return loadNewRoute(routeLoader, childInstruction); - }); - }); - } - // ts complains without this, though they are same - return void 0; - }); - }; - /** - * Load a routed-component based on navigation instruction and route config - * @internal exported for unit testing only - */ - var loadComponent = function (routeLoader, navigationInstruction, config) { - var router = navigationInstruction.router; - var lifecycleArgs = navigationInstruction.lifecycleArgs; - return Promise.resolve() - .then(function () { return routeLoader.loadRoute(router, config, navigationInstruction); }) - .then( - /** - * @param component an object carrying information about loaded route - * typically contains information about view model, childContainer, view and router - */ - function (component) { - var viewModel = component.viewModel, childContainer = component.childContainer; - component.router = router; - component.config = config; - if ('configureRouter' in viewModel) { - var childRouter_1 = childContainer.getChildRouter(); - component.childRouter = childRouter_1; - return childRouter_1 - .configure(function (c) { return viewModel.configureRouter(c, childRouter_1, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]); }) - .then(function () { return component; }); - } - return component; - }); - }; + /** + * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route + */ + var CanDeactivatePreviousStep = /** @class */ (function () { + function CanDeactivatePreviousStep() { + } + CanDeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { + return processDeactivatable(navigationInstruction, 'canDeactivate', next); + }; + return CanDeactivatePreviousStep; + }()); + /** + * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route + */ + var CanActivateNextStep = /** @class */ (function () { + function CanActivateNextStep() { + } + CanActivateNextStep.prototype.run = function (navigationInstruction, next) { + return processActivatable(navigationInstruction, 'canActivate', next); + }; + return CanActivateNextStep; + }()); + /** + * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route + */ + var DeactivatePreviousStep = /** @class */ (function () { + function DeactivatePreviousStep() { + } + DeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { + return processDeactivatable(navigationInstruction, 'deactivate', next, true); + }; + return DeactivatePreviousStep; + }()); + /** + * A pipeline step responsible for finding and activating method `activate` on a view model of a route + */ + var ActivateNextStep = /** @class */ (function () { + function ActivateNextStep() { + } + ActivateNextStep.prototype.run = function (navigationInstruction, next) { + return processActivatable(navigationInstruction, 'activate', next, true); + }; + return ActivateNextStep; + }()); - /** - * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution - */ - var PipelineSlot = /** @class */ (function () { - function PipelineSlot(container, name, alias) { - this.steps = []; - this.container = container; - this.slotName = name; - this.slotAlias = alias; - } - PipelineSlot.prototype.getSteps = function () { - var _this = this; - return this.steps.map(function (x) { return _this.container.get(x); }); - }; - return PipelineSlot; - }()); - /** - * Class responsible for creating the navigation pipeline. - */ - var PipelineProvider = /** @class */ (function () { - function PipelineProvider(container) { - this.container = container; - this.steps = [ - BuildNavigationPlanStep, - CanDeactivatePreviousStep, - LoadRouteStep, - this._createPipelineSlot("authorize" /* Authorize */), - CanActivateNextStep, - this._createPipelineSlot("preActivate" /* PreActivate */, 'modelbind'), - // NOTE: app state changes start below - point of no return - DeactivatePreviousStep, - ActivateNextStep, - this._createPipelineSlot("preRender" /* PreRender */, 'precommit'), - CommitChangesStep, - this._createPipelineSlot("postRender" /* PostRender */, 'postcomplete') - ]; - } - /**@internal */ - PipelineProvider.inject = function () { return [aureliaDependencyInjection.Container]; }; - /** - * Create the navigation pipeline. - */ - PipelineProvider.prototype.createPipeline = function (useCanDeactivateStep) { - var _this = this; - if (useCanDeactivateStep === void 0) { useCanDeactivateStep = true; } - var pipeline = new Pipeline(); - this.steps.forEach(function (step) { - if (useCanDeactivateStep || step !== CanDeactivatePreviousStep) { - pipeline.addStep(_this.container.get(step)); - } - }); - return pipeline; - }; - /**@internal */ - PipelineProvider.prototype._findStep = function (name) { - // Steps that are not PipelineSlots are constructor functions, and they will automatically fail. Probably. - return this.steps.find(function (x) { return x.slotName === name || x.slotAlias === name; }); - }; - /** - * Adds a step into the pipeline at a known slot location. - */ - PipelineProvider.prototype.addStep = function (name, step) { - var found = this._findStep(name); - if (found) { - // prevent duplicates - if (!found.steps.includes(step)) { - found.steps.push(step); - } - } - else { - throw new Error("Invalid pipeline slot name: " + name + "."); - } - }; - /** - * Removes a step from a slot in the pipeline - */ - PipelineProvider.prototype.removeStep = function (name, step) { - var slot = this._findStep(name); - if (slot) { - var steps = slot.steps; - steps.splice(steps.indexOf(step), 1); - } - }; - /** - * @internal - * Clears all steps from a slot in the pipeline - */ - PipelineProvider.prototype._clearSteps = function (name) { - if (name === void 0) { name = ''; } - var slot = this._findStep(name); - if (slot) { - slot.steps = []; - } - }; - /** - * Resets all pipeline slots - */ - PipelineProvider.prototype.reset = function () { - this._clearSteps('authorize'); - this._clearSteps('preActivate'); - this._clearSteps('preRender'); - this._clearSteps('postRender'); - }; - /**@internal */ - PipelineProvider.prototype._createPipelineSlot = function (name, alias) { - return new PipelineSlot(this.container, name, alias); - }; - return PipelineProvider; - }()); + /** + * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution + */ + var PipelineSlot = /** @class */ (function () { + function PipelineSlot(container, name, alias) { + this.steps = []; + this.container = container; + this.slotName = name; + this.slotAlias = alias; + } + PipelineSlot.prototype.getSteps = function () { + var _this = this; + return this.steps.map(function (x) { return _this.container.get(x); }); + }; + return PipelineSlot; + }()); + /** + * Class responsible for creating the navigation pipeline. + */ + var PipelineProvider = /** @class */ (function () { + function PipelineProvider(container) { + this.container = container; + this.steps = [ + BuildNavigationPlanStep, + CanDeactivatePreviousStep, + LoadRouteStep, + createPipelineSlot(container, "authorize" /* Authorize */), + CanActivateNextStep, + createPipelineSlot(container, "preActivate" /* PreActivate */, 'modelbind'), + // NOTE: app state changes start below - point of no return + DeactivatePreviousStep, + ActivateNextStep, + createPipelineSlot(container, "preRender" /* PreRender */, 'precommit'), + CommitChangesStep, + createPipelineSlot(container, "postRender" /* PostRender */, 'postcomplete') + ]; + } + /**@internal */ + PipelineProvider.inject = function () { return [aureliaDependencyInjection.Container]; }; + /** + * Create the navigation pipeline. + */ + PipelineProvider.prototype.createPipeline = function (useCanDeactivateStep) { + var _this = this; + if (useCanDeactivateStep === void 0) { useCanDeactivateStep = true; } + var pipeline = new Pipeline(); + this.steps.forEach(function (step) { + if (useCanDeactivateStep || step !== CanDeactivatePreviousStep) { + pipeline.addStep(_this.container.get(step)); + } + }); + return pipeline; + }; + /**@internal */ + PipelineProvider.prototype._findStep = function (name) { + // Steps that are not PipelineSlots are constructor functions, and they will automatically fail. Probably. + return this.steps.find(function (x) { return x.slotName === name || x.slotAlias === name; }); + }; + /** + * Adds a step into the pipeline at a known slot location. + */ + PipelineProvider.prototype.addStep = function (name, step) { + var found = this._findStep(name); + if (found) { + var slotSteps = found.steps; + // prevent duplicates + if (!slotSteps.includes(step)) { + slotSteps.push(step); + } + } + else { + throw new Error("Invalid pipeline slot name: " + name + "."); + } + }; + /** + * Removes a step from a slot in the pipeline + */ + PipelineProvider.prototype.removeStep = function (name, step) { + var slot = this._findStep(name); + if (slot) { + var slotSteps = slot.steps; + slotSteps.splice(slotSteps.indexOf(step), 1); + } + }; + /** + * Clears all steps from a slot in the pipeline + * @internal + */ + PipelineProvider.prototype._clearSteps = function (name) { + if (name === void 0) { name = ''; } + var slot = this._findStep(name); + if (slot) { + slot.steps = []; + } + }; + /** + * Resets all pipeline slots + */ + PipelineProvider.prototype.reset = function () { + this._clearSteps("authorize" /* Authorize */); + this._clearSteps("preActivate" /* PreActivate */); + this._clearSteps("preRender" /* PreRender */); + this._clearSteps("postRender" /* PostRender */); + }; + return PipelineProvider; + }()); + /**@internal */ + var createPipelineSlot = function (container, name, alias) { + return new PipelineSlot(container, name, alias); + }; - var logger = LogManager.getLogger('app-router'); - /** - * The main application router. - */ - var AppRouter = /** @class */ (function (_super) { - __extends(AppRouter, _super); - function AppRouter(container, history, pipelineProvider, events) { - var _this = _super.call(this, container, history) || this; - _this.pipelineProvider = pipelineProvider; - _this.events = events; - return _this; - } - /**@internal */ - AppRouter.inject = function () { return [aureliaDependencyInjection.Container, aureliaHistory.History, PipelineProvider, aureliaEventAggregator.EventAggregator]; }; - /** - * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. - * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. - */ - AppRouter.prototype.reset = function () { - _super.prototype.reset.call(this); - this.maxInstructionCount = 10; - if (!this._queue) { - this._queue = []; - } - else { - this._queue.length = 0; - } - }; - /** - * Loads the specified URL. - * - * @param url The URL fragment to load. - */ - AppRouter.prototype.loadUrl = function (url) { - var _this = this; - return this - ._createNavigationInstruction(url) - .then(function (instruction) { return _this._queueInstruction(instruction); }) - .catch(function (error) { - logger.error(error); - restorePreviousLocation(_this); - }); - }; - /** - * Registers a viewPort to be used as a rendering target for activated routes. - * - * @param viewPort The viewPort. This is typically a element in Aurelia default impl - * @param name The name of the viewPort. 'default' if unspecified. - */ - AppRouter.prototype.registerViewPort = function (viewPort, name) { - var _this = this; - // having strong typing without changing public API - var $viewPort = viewPort; - _super.prototype.registerViewPort.call(this, $viewPort, name); - // beside adding viewport to the registry of this instance - // AppRouter also configure routing/history to start routing functionality - // There are situation where there are more than 1 element at root view - // in that case, still only activate once via the following guard - if (!this.isActive) { - var viewModel_1 = this._findViewModel($viewPort); - if ('configureRouter' in viewModel_1) { - // If there are more than one element at root view - // use this flag to guard against configure method being invoked multiple times - // this flag is set inside method configure - if (!this.isConfigured) { - // replace the real resolve with a noop to guarantee that any action in base class Router - // won't resolve the configurePromise prematurely - var resolveConfiguredPromise_1 = this._resolveConfiguredPromise; - this._resolveConfiguredPromise = function () { }; - return this - .configure(function (config) { - viewModel_1.configureRouter(config, _this); - return config; - }) - .then(function () { - _this.activate(); - resolveConfiguredPromise_1(); - }); - } - } - else { - this.activate(); - } - } - // when a viewport is added dynamically to a root view that is already activated - // just process the navigation instruction - else { - this._dequeueInstruction(); - } - return Promise.resolve(); - }; - /** - * Activates the router. This instructs the router to begin listening for history changes and processing instructions. - * - * @params options The set of options to activate the router with. - */ - AppRouter.prototype.activate = function (options) { - if (this.isActive) { - return; - } - this.isActive = true; - // route handler property is responsible for handling url change - // the interface of aurelia-history isn't clear on this perspective - this.options = Object.assign({ routeHandler: this.loadUrl.bind(this) }, this.options, options); - this.history.activate(this.options); - this._dequeueInstruction(); - }; - /** - * Deactivates the router. - */ - AppRouter.prototype.deactivate = function () { - this.isActive = false; - this.history.deactivate(); - }; - /**@internal */ - AppRouter.prototype._queueInstruction = function (instruction) { - var _this = this; - return new Promise(function (resolve) { - instruction.resolve = resolve; - _this._queue.unshift(instruction); - _this._dequeueInstruction(); - }); - }; - /**@internal */ - AppRouter.prototype._dequeueInstruction = function (instructionCount) { - var _this = this; - if (instructionCount === void 0) { instructionCount = 0; } - return Promise.resolve().then(function () { - if (_this.isNavigating && !instructionCount) { - // ts complains about inconsistent returns without void 0 - return void 0; - } - var instruction = _this._queue.shift(); - _this._queue.length = 0; - if (!instruction) { - // ts complains about inconsistent returns without void 0 - return void 0; - } - _this.isNavigating = true; - var navtracker = _this.history.getState('NavigationTracker'); - if (!navtracker && !_this.currentNavigationTracker) { - _this.isNavigatingFirst = true; - _this.isNavigatingNew = true; - } - else if (!navtracker) { - _this.isNavigatingNew = true; - } - else if (!_this.currentNavigationTracker) { - _this.isNavigatingRefresh = true; - } - else if (_this.currentNavigationTracker < navtracker) { - _this.isNavigatingForward = true; - } - else if (_this.currentNavigationTracker > navtracker) { - _this.isNavigatingBack = true; - } - if (!navtracker) { - navtracker = Date.now(); - _this.history.setState('NavigationTracker', navtracker); - } - _this.currentNavigationTracker = navtracker; - instruction.previousInstruction = _this.currentInstruction; - if (!instructionCount) { - _this.events.publish("router:navigation:processing" /* Processing */, { instruction: instruction }); - } - else if (instructionCount === _this.maxInstructionCount - 1) { - logger.error(instructionCount + 1 + " navigation instructions have been attempted without success. Restoring last known good location."); - restorePreviousLocation(_this); - return _this._dequeueInstruction(instructionCount + 1); - } - else if (instructionCount > _this.maxInstructionCount) { - throw new Error('Maximum navigation attempts exceeded. Giving up.'); - } - var pipeline = _this.pipelineProvider.createPipeline(!_this.couldDeactivate); - return pipeline - .run(instruction) - .then(function (result) { return processResult(instruction, result, instructionCount, _this); }) - .catch(function (error) { - return { output: error instanceof Error ? error : new Error(error) }; - }) - .then(function (result) { return resolveInstruction(instruction, result, !!instructionCount, _this); }); - }); - }; - /**@internal */ - AppRouter.prototype._findViewModel = function (viewPort) { - if (this.container.viewModel) { - return this.container.viewModel; - } - if (viewPort.container) { - var container = viewPort.container; - while (container) { - if (container.viewModel) { - this.container.viewModel = container.viewModel; - return container.viewModel; - } - container = container.parent; - } - } - return undefined; - }; - return AppRouter; - }(Router)); - var processResult = function (instruction, result, instructionCount, router) { - if (!(result && 'completed' in result && 'output' in result)) { - result = result || {}; - result.output = new Error("Expected router pipeline to return a navigation result, but got [" + JSON.stringify(result) + "] instead."); - } - var finalResult = null; - var navigationCommandResult = null; - if (isNavigationCommand(result.output)) { - navigationCommandResult = result.output.navigate(router); - } - else { - finalResult = result; - if (!result.completed) { - if (result.output instanceof Error) { - logger.error(result.output.toString()); - } - restorePreviousLocation(router); - } - } - return Promise.resolve(navigationCommandResult) - .then(function (_) { return router._dequeueInstruction(instructionCount + 1); }) - .then(function (innerResult) { return finalResult || innerResult || result; }); - }; - var resolveInstruction = function (instruction, result, isInnerInstruction, router) { - instruction.resolve(result); - var eventArgs = { instruction: instruction, result: result }; - if (!isInnerInstruction) { - router.isNavigating = false; - router.isExplicitNavigation = false; - router.isExplicitNavigationBack = false; - router.isNavigatingFirst = false; - router.isNavigatingNew = false; - router.isNavigatingRefresh = false; - router.isNavigatingForward = false; - router.isNavigatingBack = false; - router.couldDeactivate = false; - var eventName = void 0; - if (result.output instanceof Error) { - eventName = "router:navigation:error" /* Error */; - } - else if (!result.completed) { - eventName = "router:navigation:canceled" /* Canceled */; - } - else { - var queryString = instruction.queryString ? ('?' + instruction.queryString) : ''; - router.history.previousLocation = instruction.fragment + queryString; - eventName = "router:navigation:success" /* Success */; - } - router.events.publish(eventName, eventArgs); - router.events.publish("router:navigation:complete" /* Complete */, eventArgs); - } - else { - router.events.publish("router:navigation:child:complete" /* ChildComplete */, eventArgs); - } - return result; - }; - var restorePreviousLocation = function (router) { - var previousLocation = router.history.previousLocation; - if (previousLocation) { - router.navigate(router.history.previousLocation, { trigger: false, replace: true }); - } - else if (router.fallbackRoute) { - router.navigate(router.fallbackRoute, { trigger: true, replace: true }); - } - else { - logger.error('Router navigation failed, and no previous location or fallbackRoute could be restored.'); - } - }; + var logger = LogManager.getLogger('app-router'); + /** + * The main application router. + */ + var AppRouter = /** @class */ (function (_super) { + __extends(AppRouter, _super); + function AppRouter(container, history, pipelineProvider, events) { + var _this = _super.call(this, container, history) || this; + _this.pipelineProvider = pipelineProvider; + _this.events = events; + return _this; + } + /**@internal */ + AppRouter.inject = function () { return [aureliaDependencyInjection.Container, aureliaHistory.History, PipelineProvider, aureliaEventAggregator.EventAggregator]; }; + /** + * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. + * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. + */ + AppRouter.prototype.reset = function () { + _super.prototype.reset.call(this); + this.maxInstructionCount = 10; + if (!this._queue) { + this._queue = []; + } + else { + this._queue.length = 0; + } + }; + /** + * Loads the specified URL. + * + * @param url The URL fragment to load. + */ + AppRouter.prototype.loadUrl = function (url) { + var _this = this; + return this + ._createNavigationInstruction(url) + .then(function (instruction) { return _this._queueInstruction(instruction); }) + .catch(function (error) { + logger.error(error); + restorePreviousLocation(_this); + }); + }; + /** + * Registers a viewPort to be used as a rendering target for activated routes. + * + * @param viewPort The viewPort. This is typically a element in Aurelia default impl + * @param name The name of the viewPort. 'default' if unspecified. + */ + AppRouter.prototype.registerViewPort = function (viewPort, name) { + var _this = this; + // having strong typing without changing public API + var $viewPort = viewPort; + _super.prototype.registerViewPort.call(this, $viewPort, name); + // beside adding viewport to the registry of this instance + // AppRouter also configure routing/history to start routing functionality + // There are situation where there are more than 1 element at root view + // in that case, still only activate once via the following guard + if (!this.isActive) { + var viewModel_1 = this._findViewModel($viewPort); + if ('configureRouter' in viewModel_1) { + // If there are more than one element at root view + // use this flag to guard against configure method being invoked multiple times + // this flag is set inside method configure + if (!this.isConfigured) { + // replace the real resolve with a noop to guarantee that any action in base class Router + // won't resolve the configurePromise prematurely + var resolveConfiguredPromise_1 = this._resolveConfiguredPromise; + this._resolveConfiguredPromise = function () { }; + return this + .configure(function (config) { + viewModel_1.configureRouter(config, _this); + return config; + }) + .then(function () { + _this.activate(); + resolveConfiguredPromise_1(); + }); + } + } + else { + this.activate(); + } + } + // when a viewport is added dynamically to a root view that is already activated + // just process the navigation instruction + else { + this._dequeueInstruction(); + } + return Promise.resolve(); + }; + /** + * Activates the router. This instructs the router to begin listening for history changes and processing instructions. + * + * @params options The set of options to activate the router with. + */ + AppRouter.prototype.activate = function (options) { + if (this.isActive) { + return; + } + this.isActive = true; + // route handler property is responsible for handling url change + // the interface of aurelia-history isn't clear on this perspective + this.options = Object.assign({ routeHandler: this.loadUrl.bind(this) }, this.options, options); + this.history.activate(this.options); + this._dequeueInstruction(); + }; + /** + * Deactivates the router. + */ + AppRouter.prototype.deactivate = function () { + this.isActive = false; + this.history.deactivate(); + }; + /**@internal */ + AppRouter.prototype._queueInstruction = function (instruction) { + var _this = this; + return new Promise(function (resolve) { + instruction.resolve = resolve; + _this._queue.unshift(instruction); + _this._dequeueInstruction(); + }); + }; + /**@internal */ + AppRouter.prototype._dequeueInstruction = function (instructionCount) { + var _this = this; + if (instructionCount === void 0) { instructionCount = 0; } + return Promise.resolve().then(function () { + if (_this.isNavigating && !instructionCount) { + // ts complains about inconsistent returns without void 0 + return void 0; + } + var instruction = _this._queue.shift(); + _this._queue.length = 0; + if (!instruction) { + // ts complains about inconsistent returns without void 0 + return void 0; + } + _this.isNavigating = true; + var navtracker = _this.history.getState('NavigationTracker'); + var currentNavTracker = _this.currentNavigationTracker; + if (!navtracker && !currentNavTracker) { + _this.isNavigatingFirst = true; + _this.isNavigatingNew = true; + } + else if (!navtracker) { + _this.isNavigatingNew = true; + } + else if (!currentNavTracker) { + _this.isNavigatingRefresh = true; + } + else if (currentNavTracker < navtracker) { + _this.isNavigatingForward = true; + } + else if (currentNavTracker > navtracker) { + _this.isNavigatingBack = true; + } + if (!navtracker) { + navtracker = Date.now(); + _this.history.setState('NavigationTracker', navtracker); + } + _this.currentNavigationTracker = navtracker; + instruction.previousInstruction = _this.currentInstruction; + var maxInstructionCount = _this.maxInstructionCount; + if (!instructionCount) { + _this.events.publish("router:navigation:processing" /* Processing */, { instruction: instruction }); + } + else if (instructionCount === maxInstructionCount - 1) { + logger.error(instructionCount + 1 + " navigation instructions have been attempted without success. Restoring last known good location."); + restorePreviousLocation(_this); + return _this._dequeueInstruction(instructionCount + 1); + } + else if (instructionCount > maxInstructionCount) { + throw new Error('Maximum navigation attempts exceeded. Giving up.'); + } + var pipeline = _this.pipelineProvider.createPipeline(!_this.couldDeactivate); + return pipeline + .run(instruction) + .then(function (result) { return processResult(instruction, result, instructionCount, _this); }) + .catch(function (error) { + return { output: error instanceof Error ? error : new Error(error) }; + }) + .then(function (result) { return resolveInstruction(instruction, result, !!instructionCount, _this); }); + }); + }; + /**@internal */ + AppRouter.prototype._findViewModel = function (viewPort) { + if (this.container.viewModel) { + return this.container.viewModel; + } + if (viewPort.container) { + var container = viewPort.container; + while (container) { + if (container.viewModel) { + this.container.viewModel = container.viewModel; + return container.viewModel; + } + container = container.parent; + } + } + return undefined; + }; + return AppRouter; + }(Router)); + var processResult = function (instruction, result, instructionCount, router) { + if (!(result && 'completed' in result && 'output' in result)) { + result = result || {}; + result.output = new Error("Expected router pipeline to return a navigation result, but got [" + JSON.stringify(result) + "] instead."); + } + var finalResult = null; + var navigationCommandResult = null; + if (isNavigationCommand(result.output)) { + navigationCommandResult = result.output.navigate(router); + } + else { + finalResult = result; + if (!result.completed) { + if (result.output instanceof Error) { + logger.error(result.output.toString()); + } + restorePreviousLocation(router); + } + } + return Promise.resolve(navigationCommandResult) + .then(function (_) { return router._dequeueInstruction(instructionCount + 1); }) + .then(function (innerResult) { return finalResult || innerResult || result; }); + }; + var resolveInstruction = function (instruction, result, isInnerInstruction, router) { + instruction.resolve(result); + var eventAggregator = router.events; + var eventArgs = { instruction: instruction, result: result }; + if (!isInnerInstruction) { + router.isNavigating = false; + router.isExplicitNavigation = false; + router.isExplicitNavigationBack = false; + router.isNavigatingFirst = false; + router.isNavigatingNew = false; + router.isNavigatingRefresh = false; + router.isNavigatingForward = false; + router.isNavigatingBack = false; + router.couldDeactivate = false; + var eventName = void 0; + if (result.output instanceof Error) { + eventName = "router:navigation:error" /* Error */; + } + else if (!result.completed) { + eventName = "router:navigation:canceled" /* Canceled */; + } + else { + var queryString = instruction.queryString ? ('?' + instruction.queryString) : ''; + router.history.previousLocation = instruction.fragment + queryString; + eventName = "router:navigation:success" /* Success */; + } + eventAggregator.publish(eventName, eventArgs); + eventAggregator.publish("router:navigation:complete" /* Complete */, eventArgs); + } + else { + eventAggregator.publish("router:navigation:child:complete" /* ChildComplete */, eventArgs); + } + return result; + }; + var restorePreviousLocation = function (router) { + var previousLocation = router.history.previousLocation; + if (previousLocation) { + router.navigate(previousLocation, { trigger: false, replace: true }); + } + else if (router.fallbackRoute) { + router.navigate(router.fallbackRoute, { trigger: true, replace: true }); + } + else { + logger.error('Router navigation failed, and no previous location or fallbackRoute could be restored.'); + } + }; - /** - * The status of a Pipeline. - */ - (function (PipelineStatus) { - PipelineStatus["Completed"] = "completed"; - PipelineStatus["Canceled"] = "canceled"; - PipelineStatus["Rejected"] = "rejected"; - PipelineStatus["Running"] = "running"; - })(exports.PipelineStatus || (exports.PipelineStatus = {})); + /** + * The status of a Pipeline. + */ + (function (PipelineStatus) { + PipelineStatus["Completed"] = "completed"; + PipelineStatus["Canceled"] = "canceled"; + PipelineStatus["Rejected"] = "rejected"; + PipelineStatus["Running"] = "running"; + })(exports.PipelineStatus || (exports.PipelineStatus = {})); - /** - * A list of known router events used by the Aurelia router - * to signal the pipeline has come to a certain state - */ - (function (RouterEvent) { - RouterEvent["Processing"] = "router:navigation:processing"; - RouterEvent["Error"] = "router:navigation:error"; - RouterEvent["Canceled"] = "router:navigation:canceled"; - RouterEvent["Complete"] = "router:navigation:complete"; - RouterEvent["Success"] = "router:navigation:success"; - RouterEvent["ChildComplete"] = "router:navigation:child:complete"; - })(exports.RouterEvent || (exports.RouterEvent = {})); + /** + * A list of known router events used by the Aurelia router + * to signal the pipeline has come to a certain state + */ + (function (RouterEvent) { + RouterEvent["Processing"] = "router:navigation:processing"; + RouterEvent["Error"] = "router:navigation:error"; + RouterEvent["Canceled"] = "router:navigation:canceled"; + RouterEvent["Complete"] = "router:navigation:complete"; + RouterEvent["Success"] = "router:navigation:success"; + RouterEvent["ChildComplete"] = "router:navigation:child:complete"; + })(exports.RouterEvent || (exports.RouterEvent = {})); - /** - * Available pipeline slot names to insert interceptor into router pipeline - */ - (function (PipelineSlotName) { - /** - * Authorization slot. Invoked early in the pipeline, - * before `canActivate` hook of incoming route - */ - PipelineSlotName["Authorize"] = "authorize"; - /** - * Pre-activation slot. Invoked early in the pipeline, - * Invoked timing: - * - after Authorization slot - * - after canActivate hook on new view model - * - before deactivate hook on old view model - * - before activate hook on new view model - */ - PipelineSlotName["PreActivate"] = "preActivate"; - /** - * Pre-render slot. Invoked later in the pipeline - * Invokcation timing: - * - after activate hook on new view model - * - before commit step on new navigation instruction - */ - PipelineSlotName["PreRender"] = "preRender"; - /** - * Post-render slot. Invoked last in the pipeline - */ - PipelineSlotName["PostRender"] = "postRender"; - })(exports.PipelineSlotName || (exports.PipelineSlotName = {})); + /** + * Available pipeline slot names to insert interceptor into router pipeline + */ + (function (PipelineSlotName) { + /** + * Authorization slot. Invoked early in the pipeline, + * before `canActivate` hook of incoming route + */ + PipelineSlotName["Authorize"] = "authorize"; + /** + * Pre-activation slot. Invoked early in the pipeline, + * Invoked timing: + * - after Authorization slot + * - after canActivate hook on new view model + * - before deactivate hook on old view model + * - before activate hook on new view model + */ + PipelineSlotName["PreActivate"] = "preActivate"; + /** + * Pre-render slot. Invoked later in the pipeline + * Invokcation timing: + * - after activate hook on new view model + * - before commit step on new navigation instruction + */ + PipelineSlotName["PreRender"] = "preRender"; + /** + * Post-render slot. Invoked last in the pipeline + */ + PipelineSlotName["PostRender"] = "postRender"; + })(exports.PipelineSlotName || (exports.PipelineSlotName = {})); - exports.ActivateNextStep = ActivateNextStep; - exports.AppRouter = AppRouter; - exports.BuildNavigationPlanStep = BuildNavigationPlanStep; - exports.CanActivateNextStep = CanActivateNextStep; - exports.CanDeactivatePreviousStep = CanDeactivatePreviousStep; - exports.CommitChangesStep = CommitChangesStep; - exports.DeactivatePreviousStep = DeactivatePreviousStep; - exports.LoadRouteStep = LoadRouteStep; - exports.NavModel = NavModel; - exports.NavigationInstruction = NavigationInstruction; - exports.Pipeline = Pipeline; - exports.PipelineProvider = PipelineProvider; - exports.Redirect = Redirect; - exports.RedirectToRoute = RedirectToRoute; - exports.RouteLoader = RouteLoader; - exports.Router = Router; - exports.RouterConfiguration = RouterConfiguration; - exports.activationStrategy = activationStrategy; - exports.isNavigationCommand = isNavigationCommand; + exports.ActivateNextStep = ActivateNextStep; + exports.AppRouter = AppRouter; + exports.BuildNavigationPlanStep = BuildNavigationPlanStep; + exports.CanActivateNextStep = CanActivateNextStep; + exports.CanDeactivatePreviousStep = CanDeactivatePreviousStep; + exports.CommitChangesStep = CommitChangesStep; + exports.DeactivatePreviousStep = DeactivatePreviousStep; + exports.LoadRouteStep = LoadRouteStep; + exports.NavModel = NavModel; + exports.NavigationInstruction = NavigationInstruction; + exports.Pipeline = Pipeline; + exports.PipelineProvider = PipelineProvider; + exports.Redirect = Redirect; + exports.RedirectToRoute = RedirectToRoute; + exports.RouteLoader = RouteLoader; + exports.Router = Router; + exports.RouterConfiguration = RouterConfiguration; + exports.activationStrategy = activationStrategy; + exports.isNavigationCommand = isNavigationCommand; - Object.defineProperty(exports, '__esModule', { value: true }); + Object.defineProperty(exports, '__esModule', { value: true }); }); //# sourceMappingURL=aurelia-router.js.map diff --git a/dist/amd/aurelia-router.js.map b/dist/amd/aurelia-router.js.map index f07caa9c..b2d62ca8 100644 --- a/dist/amd/aurelia-router.js.map +++ b/dist/amd/aurelia-router.js.map @@ -1 +1 @@ -{"version":3,"file":"aurelia-router.js","sources":["../../src/navigation-commands.ts","../../src/navigation-plan.ts","../../src/activation.ts","../../src/navigation-instruction.ts","../../src/nav-model.ts","../../src/util.ts","../../src/router-configuration.ts","../../src/router.ts","../../src/next.ts","../../src/pipeline.ts","../../src/route-loading.ts","../../src/pipeline-provider.ts","../../src/app-router.ts","../../src/pipeline-status.ts","../../src/router-event.ts","../../src/pipeline-slot-name.ts"],"sourcesContent":["import { NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface NavigationOptions {\n useAppRouter?: boolean;\n }\n}\n\n/**\n* When a navigation command is encountered, the current navigation\n* will be cancelled and control will be passed to the navigation\n* command so it can determine the correct action.\n*/\nexport interface NavigationCommand {\n navigate: (router: Router) => void;\n /**@internal */\n shouldContinueProcessing?: boolean;\n /**@internal */\n setRouter?: (router: Router) => void;\n}\n\n/**\n* Determines if the provided object is a navigation command.\n* A navigation command is anything with a navigate method.\n*\n* @param obj The object to check.\n*/\nexport function isNavigationCommand(obj: any): obj is NavigationCommand {\n return obj && typeof obj.navigate === 'function';\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect.\n*/\nexport class Redirect implements NavigationCommand {\n\n url: string;\n /**@internal */\n options: NavigationOptions;\n /**@internal */\n shouldContinueProcessing: boolean;\n\n private router: Router;\n\n /**\n * @param url The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n constructor(url: string, options: NavigationOptions = {}) {\n this.url = url;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigate(this.url, this.options);\n }\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect to a named route.\n*/\nexport class RedirectToRoute implements NavigationCommand {\n\n route: string;\n params: any;\n /**@internal */\n options: NavigationOptions;\n\n /**@internal */\n shouldContinueProcessing: boolean;\n\n /**@internal */\n router: Router;\n\n /**\n * @param route The name of the route.\n * @param params The parameters to be sent to the activation method.\n * @param options The options to use for navigation.\n */\n constructor(route: string, params: any = {}, options: NavigationOptions = {}) {\n this.route = route;\n this.params = params;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigateToRoute(this.route, this.params, this.options);\n }\n}\n","import { ActivationStrategy, Next, ViewPortPlan } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\n\n/**\n* The strategy to use when activating modules during navigation.\n*/\nexport const activationStrategy: ActivationStrategy = {\n noChange: 'no-change',\n invokeLifecycle: 'invoke-lifecycle',\n replace: 'replace'\n};\n\n/**\n * Transform a navigation instruction into viewport plan record object,\n * or a redirect request if user viewmodel demands\n */\nexport class BuildNavigationPlanStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return _buildNavigationPlan(navigationInstruction)\n .then(plan => {\n if (plan instanceof Redirect) {\n return next.cancel(plan);\n }\n navigationInstruction.plan = plan;\n return next();\n })\n .catch(next.cancel);\n }\n}\n\nexport function _buildNavigationPlan(\n instruction: NavigationInstruction,\n forceLifecycleMinimum?: boolean\n): Promise | Redirect> {\n let config = instruction.config;\n\n // todo: separate and export for unit tests\n if ('redirect' in config) {\n const router = instruction.router;\n return router\n ._createNavigationInstruction(config.redirect)\n .then(newInstruction => {\n const params: Record = {};\n for (let key in newInstruction.params) {\n // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this }\n let val = newInstruction.params[key];\n if (typeof val === 'string' && val[0] === ':') {\n val = val.slice(1);\n // And if that param is found on the original instruction then use it\n if (val in instruction.params) {\n params[key] = instruction.params[val];\n }\n } else {\n params[key] = newInstruction.params[key];\n }\n }\n let redirectLocation = router.generate(newInstruction.config, params, instruction.options);\n\n // Special handling for child routes\n for (let key in instruction.params) {\n redirectLocation = redirectLocation.replace(`:${key}`, instruction.params[key]);\n }\n\n if (instruction.queryString) {\n redirectLocation += '?' + instruction.queryString;\n }\n\n return Promise.resolve(new Redirect(redirectLocation));\n });\n }\n\n const prev = instruction.previousInstruction;\n const plan: Record = {};\n const defaults = instruction.router.viewPortDefaults;\n\n if (prev) {\n let newParams = hasDifferentParameterValues(prev, instruction);\n let pending: Promise[] = [];\n\n for (let viewPortName in prev.viewPortInstructions) {\n const prevViewPortInstruction = prev.viewPortInstructions[viewPortName];\n let nextViewPortConfig = viewPortName in config.viewPorts ? config.viewPorts[viewPortName] : prevViewPortInstruction;\n if (nextViewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) {\n nextViewPortConfig = defaults[viewPortName];\n }\n\n const viewPortPlan = plan[viewPortName] = {\n name: viewPortName,\n config: nextViewPortConfig,\n prevComponent: prevViewPortInstruction.component,\n prevModuleId: prevViewPortInstruction.moduleId\n } as ViewPortPlan;\n\n if (prevViewPortInstruction.moduleId !== nextViewPortConfig.moduleId) {\n viewPortPlan.strategy = activationStrategy.replace;\n } else if ('determineActivationStrategy' in prevViewPortInstruction.component.viewModel) {\n viewPortPlan.strategy = prevViewPortInstruction.component.viewModel\n .determineActivationStrategy(...instruction.lifecycleArgs);\n } else if (config.activationStrategy) {\n viewPortPlan.strategy = config.activationStrategy;\n } else if (newParams || forceLifecycleMinimum) {\n viewPortPlan.strategy = activationStrategy.invokeLifecycle;\n } else {\n viewPortPlan.strategy = activationStrategy.noChange;\n }\n\n if (viewPortPlan.strategy !== activationStrategy.replace && prevViewPortInstruction.childRouter) {\n const path = instruction.getWildcardPath();\n const task: Promise = prevViewPortInstruction\n .childRouter\n ._createNavigationInstruction(path, instruction)\n .then((childInstruction: any) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(\n childInstruction,\n viewPortPlan.strategy === activationStrategy.invokeLifecycle\n )\n .then(childPlan => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n // for bluebird ?\n return null;\n });\n });\n\n pending.push(task);\n }\n }\n\n return Promise.all(pending).then(() => plan);\n }\n\n for (let viewPortName in config.viewPorts) {\n let viewPortConfig = config.viewPorts[viewPortName];\n if (viewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) {\n viewPortConfig = defaults[viewPortName];\n }\n plan[viewPortName] = {\n name: viewPortName,\n strategy: activationStrategy.replace,\n config: viewPortConfig\n };\n }\n\n return Promise.resolve(plan);\n}\n\nfunction hasDifferentParameterValues(prev: NavigationInstruction, next: NavigationInstruction): boolean {\n let prevParams = prev.params;\n let nextParams = next.params;\n let nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null;\n\n for (let key in nextParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n for (let key in prevParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n if (!next.options.compareQueryParams) {\n return false;\n }\n\n let prevQueryParams = prev.queryParams;\n let nextQueryParams = next.queryParams;\n for (let key in nextQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n for (let key in prevQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n return false;\n}\n","import { Next, ViewPortComponent, ViewPortPlan, ViewPortInstruction, LifecycleArguments } from './interfaces';\nimport { isNavigationCommand } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy } from './navigation-plan';\nimport { Router } from './router';\n\n/**\n * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route\n */\nexport class CanDeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'canDeactivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route\n */\nexport class CanActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'canActivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route\n */\nexport class DeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'deactivate', next, true);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `activate` on a view model of a route\n */\nexport class ActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'activate', next, true);\n }\n}\n\n/**\n * Recursively find list of deactivate-able view models\n * and invoke the either 'canDeactivate' or 'deactivate' on each\n */\nconst processDeactivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canDeactivate' | 'deactivate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let plan: Record = navigationInstruction.plan;\n let infos = findDeactivatable(plan, callbackName);\n let i = infos.length; // query from inside out\n\n function inspect(val: any): Promise {\n if (ignoreResult || shouldContinue(val)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n if (i--) {\n try {\n let viewModel = infos[i];\n let result = viewModel[callbackName](navigationInstruction);\n return processPotential(result, inspect, next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n navigationInstruction.router.couldDeactivate = true;\n\n return next();\n }\n\n return iterate();\n};\n\n/**\n * Recursively find and returns a list of deactivate-able view models\n */\nconst findDeactivatable = (\n plan: Record,\n callbackName: string,\n list: IActivatableInfo[] = []\n): any[] => {\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let prevComponent = viewPortPlan.prevComponent;\n\n if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace)\n && prevComponent\n ) {\n let viewModel = prevComponent.viewModel;\n\n if (callbackName in viewModel) {\n list.push(viewModel);\n }\n }\n\n if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) {\n addPreviousDeactivatable(prevComponent, callbackName, list);\n } else if (viewPortPlan.childNavigationInstruction) {\n findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list);\n }\n }\n\n return list;\n};\n\nconst addPreviousDeactivatable = (\n component: ViewPortComponent,\n callbackName: string,\n list: IActivatableInfo[]\n): void => {\n let childRouter = component.childRouter;\n\n if (childRouter && childRouter.currentInstruction) {\n let viewPortInstructions = childRouter.currentInstruction.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let prevComponent = viewPortInstruction.component;\n let prevViewModel = prevComponent.viewModel;\n\n if (callbackName in prevViewModel) {\n list.push(prevViewModel);\n }\n\n addPreviousDeactivatable(prevComponent, callbackName, list);\n }\n }\n};\n\nconst processActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let infos = findActivatable(navigationInstruction, callbackName);\n let length = infos.length;\n let i = -1; // query from top down\n\n function inspect(val: any, router: Router): Promise {\n if (ignoreResult || shouldContinue(val, router)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n i++;\n\n if (i < length) {\n try {\n let current = infos[i];\n let result = current.viewModel[callbackName](...current.lifecycleArgs);\n return processPotential(result, (val: any) => inspect(val, current.router), next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n return next();\n }\n\n return iterate();\n};\n\ninterface IActivatableInfo {\n viewModel: any;\n lifecycleArgs: LifecycleArguments;\n router: Router;\n}\n\n/**\n * Find list of activatable view model and add to list (3rd parameter)\n */\nconst findActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n list: IActivatableInfo[] = [],\n router?: Router\n): IActivatableInfo[] => {\n let plan: Record = navigationInstruction.plan;\n\n Object\n .keys(plan)\n .forEach((viewPortName) => {\n let viewPortPlan = plan[viewPortName];\n let viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName] as ViewPortInstruction;\n let viewPortComponent = viewPortInstruction.component;\n let viewModel = viewPortComponent.viewModel;\n\n if (\n (viewPortPlan.strategy === activationStrategy.invokeLifecycle\n || viewPortPlan.strategy === activationStrategy.replace\n )\n && callbackName in viewModel\n ) {\n list.push({\n viewModel,\n lifecycleArgs: viewPortInstruction.lifecycleArgs,\n router\n });\n }\n\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (childNavInstruction) {\n findActivatable(\n childNavInstruction,\n callbackName,\n list,\n viewPortComponent.childRouter || router\n );\n }\n });\n\n return list;\n};\n\nconst shouldContinue = (output: T, router?: Router): boolean | T => {\n if (output instanceof Error) {\n return false;\n }\n\n if (isNavigationCommand(output)) {\n if (typeof output.setRouter === 'function') {\n output.setRouter(router);\n }\n\n return !!output.shouldContinueProcessing;\n }\n\n if (output === undefined) {\n return true;\n }\n\n return output;\n};\n\n/**\n * A basic interface for an Observable type\n */\nexport interface IObservable {\n subscribe(sub?: IObservableConfig): ISubscription;\n}\n\nexport interface IObservableConfig {\n next(): void;\n error(err?: any): void;\n complete(): void;\n}\n\n/**\n * A basic interface for a Subscription to an Observable\n */\ninterface ISubscription {\n unsubscribe(): void;\n}\n\ntype SafeSubscriptionFunc = (sub: SafeSubscription) => ISubscription;\n\n/**\n * wraps a subscription, allowing unsubscribe calls even if\n * the first value comes synchronously\n */\nclass SafeSubscription {\n\n private _subscribed: boolean;\n private _subscription: ISubscription;\n\n constructor(subscriptionFunc: SafeSubscriptionFunc) {\n this._subscribed = true;\n this._subscription = subscriptionFunc(this);\n\n if (!this._subscribed) {\n this.unsubscribe();\n }\n }\n\n get subscribed(): boolean {\n return this._subscribed;\n }\n\n unsubscribe(): void {\n if (this._subscribed && this._subscription) {\n this._subscription.unsubscribe();\n }\n\n this._subscribed = false;\n }\n}\n\n/**\n * A function to process return value from `activate`/`canActivate` steps\n * Supports observable/promise\n *\n * For observable, resolve at first next() or on complete()\n */\nconst processPotential = (obj: any, resolve: (val?: any) => any, reject: (err?: any) => any): any => {\n // if promise like\n if (obj && typeof obj.then === 'function') {\n return Promise.resolve(obj).then(resolve).catch(reject);\n }\n\n // if observable\n if (obj && typeof obj.subscribe === 'function') {\n let obs: IObservable = obj;\n return new SafeSubscription(sub => obs.subscribe({\n next() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n },\n error(error) {\n if (sub.subscribed) {\n sub.unsubscribe();\n reject(error);\n }\n },\n complete() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n }\n }));\n }\n\n // else just resolve\n try {\n return resolve(obj);\n } catch (error) {\n return reject(error);\n }\n};\n","import { ViewPortInstruction, RouteConfig, ViewPort, LifecycleArguments, ActivationStrategyType } from './interfaces';\nimport { Router } from './router';\nimport { activationStrategy } from './navigation-plan';\n\n/**\n * Initialization options for a navigation instruction\n */\nexport interface NavigationInstructionInit {\n fragment: string;\n queryString?: string;\n params?: Record;\n queryParams?: Record;\n config: RouteConfig;\n parentInstruction?: NavigationInstruction;\n previousInstruction?: NavigationInstruction;\n router: Router;\n options?: Object;\n plan?: Record;\n}\n\n/**\n * A pipeline step for instructing a piepline to commit changes on a navigation instruction\n */\nexport class CommitChangesStep {\n run(navigationInstruction: NavigationInstruction, next: Function): Promise {\n return navigationInstruction\n ._commitChanges(/*wait to swap?*/true)\n .then(() => {\n navigationInstruction._updateTitle();\n return next();\n });\n }\n}\n\n/**\n* Class used to represent an instruction during a navigation.\n*/\nexport class NavigationInstruction {\n /**\n * The URL fragment.\n */\n fragment: string;\n\n /**\n * The query string.\n */\n queryString: string;\n\n /**\n * Parameters extracted from the route pattern.\n */\n params: any;\n\n /**\n * Parameters extracted from the query string.\n */\n queryParams: any;\n\n /**\n * The route config for the route matching this instruction.\n */\n config: RouteConfig;\n\n /**\n * The parent instruction, if this instruction was created by a child router.\n */\n parentInstruction: NavigationInstruction;\n\n parentCatchHandler: any;\n\n /**\n * The instruction being replaced by this instruction in the current router.\n */\n previousInstruction: NavigationInstruction;\n\n /**\n * viewPort instructions to used activation.\n */\n viewPortInstructions: Record;\n\n /**\n * The router instance.\n */\n router: Router;\n\n /**\n * Current built viewport plan of this nav instruction\n */\n plan: Record = null;\n\n options: Record = {};\n\n /**@internal */\n lifecycleArgs: LifecycleArguments;\n /**@internal */\n resolve?: (val?: any) => void;\n\n constructor(init: NavigationInstructionInit) {\n Object.assign(this, init);\n\n this.params = this.params || {};\n this.viewPortInstructions = {};\n\n let ancestorParams = [];\n let current: NavigationInstruction = this;\n do {\n let currentParams = Object.assign({}, current.params);\n if (current.config && current.config.hasChildRouter) {\n // remove the param for the injected child route segment\n delete currentParams[current.getWildCardName()];\n }\n\n ancestorParams.unshift(currentParams);\n current = current.parentInstruction;\n } while (current);\n\n let allParams = Object.assign({}, this.queryParams, ...ancestorParams);\n this.lifecycleArgs = [allParams, this.config, this];\n }\n\n /**\n * Gets an array containing this instruction and all child instructions for the current navigation.\n */\n getAllInstructions(): Array {\n let instructions: NavigationInstruction[] = [this];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let key in viewPortInstructions) {\n let childInstruction = viewPortInstructions[key].childNavigationInstruction;\n if (childInstruction) {\n instructions.push(...childInstruction.getAllInstructions());\n }\n }\n\n return instructions;\n }\n\n /**\n * Gets an array containing the instruction and all child instructions for the previous navigation.\n * Previous instructions are no longer available after navigation completes.\n */\n getAllPreviousInstructions(): Array {\n return this.getAllInstructions().map(c => c.previousInstruction).filter(c => c);\n }\n\n /**\n * Adds a viewPort instruction. Returns the newly created instruction based on parameters\n */\n addViewPortInstruction(name: string, strategy: ActivationStrategyType, moduleId: string, component: any): /*ViewPortInstruction*/ any {\n const lifecycleArgs = this.lifecycleArgs;\n const config: RouteConfig = Object.assign({}, lifecycleArgs[1], { currentViewPort: name });\n const viewportInstruction = this.viewPortInstructions[name] = {\n name: name,\n strategy: strategy,\n moduleId: moduleId,\n component: component,\n childRouter: component.childRouter,\n lifecycleArgs: [].concat(lifecycleArgs[0], config, lifecycleArgs[2]) as LifecycleArguments\n };\n\n return viewportInstruction;\n }\n\n /**\n * Gets the name of the route pattern's wildcard parameter, if applicable.\n */\n getWildCardName(): string {\n // todo: potential issue, or at least unsafe typings\n let configRoute = this.config.route as string;\n let wildcardIndex = configRoute.lastIndexOf('*');\n return configRoute.substr(wildcardIndex + 1);\n }\n\n /**\n * Gets the path and query string created by filling the route\n * pattern's wildcard parameter with the matching param.\n */\n getWildcardPath(): string {\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n let queryString = this.queryString;\n\n if (queryString) {\n path += '?' + queryString;\n }\n\n return path;\n }\n\n /**\n * Gets the instruction's base URL, accounting for wildcard route parameters.\n */\n getBaseUrl(): string {\n let $encodeURI = encodeURI;\n let fragment = decodeURI(this.fragment);\n\n if (fragment === '') {\n let nonEmptyRoute = this.router.routes.find(route => {\n return route.name === this.config.name &&\n route.route !== '';\n });\n if (nonEmptyRoute) {\n fragment = nonEmptyRoute.route as any;\n }\n }\n\n if (!this.params) {\n return $encodeURI(fragment);\n }\n\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n\n if (!path) {\n return $encodeURI(fragment);\n }\n\n return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path)));\n }\n\n /**@internal */\n _commitChanges(waitToSwap: boolean): Promise {\n let router = this.router;\n router.currentInstruction = this;\n\n const previousInstruction = this.previousInstruction;\n if (previousInstruction) {\n previousInstruction.config.navModel.isActive = false;\n }\n\n this.config.navModel.isActive = true;\n\n router.refreshNavigation();\n\n let loads: Promise[] = [];\n let delaySwaps: ISwapPlan[] = [];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let viewPort = router.viewPorts[viewPortName];\n\n if (!viewPort) {\n throw new Error(`There was no router-view found in the view for ${viewPortInstruction.moduleId}.`);\n }\n\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n if (viewPortInstruction.strategy === activationStrategy.replace) {\n if (child_nav_instruction && child_nav_instruction.parentCatchHandler) {\n loads.push(child_nav_instruction._commitChanges(waitToSwap));\n } else {\n if (waitToSwap) {\n delaySwaps.push({ viewPort, viewPortInstruction });\n }\n loads.push(\n viewPort\n .process(viewPortInstruction, waitToSwap)\n .then(() => child_nav_instruction\n ? child_nav_instruction._commitChanges(waitToSwap)\n : Promise.resolve()\n )\n );\n }\n } else {\n if (child_nav_instruction) {\n loads.push(child_nav_instruction._commitChanges(waitToSwap));\n }\n }\n }\n\n return Promise\n .all(loads)\n .then(() => {\n delaySwaps.forEach(x => x.viewPort.swap(x.viewPortInstruction));\n return null;\n })\n .then(() => prune(this));\n }\n\n /**@internal */\n _updateTitle(): void {\n let router = this.router;\n let title = this._buildTitle(router.titleSeparator);\n if (title) {\n router.history.setTitle(title);\n }\n }\n\n /**@internal */\n _buildTitle(separator: string = ' | '): string {\n let title = '';\n let childTitles = [];\n let navModelTitle = this.config.navModel.title;\n let instructionRouter = this.router;\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n if (navModelTitle) {\n title = instructionRouter.transformTitle(navModelTitle);\n }\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n\n if (child_nav_instruction) {\n let childTitle = child_nav_instruction._buildTitle(separator);\n if (childTitle) {\n childTitles.push(childTitle);\n }\n }\n }\n\n if (childTitles.length) {\n title = childTitles.join(separator) + (title ? separator : '') + title;\n }\n\n if (instructionRouter.title) {\n title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title);\n }\n\n return title;\n }\n}\n\nconst prune = (instruction: NavigationInstruction): void => {\n instruction.previousInstruction = null;\n instruction.plan = null;\n};\n\ninterface ISwapPlan {\n viewPort: ViewPort;\n viewPortInstruction: ViewPortInstruction;\n}\n","import { Router } from './router';\nimport { RouteConfig } from './interfaces';\n\n/**\n* Class for storing and interacting with a route's navigation settings.\n*/\nexport class NavModel {\n\n /**\n * True if this nav item is currently active.\n */\n isActive: boolean = false;\n\n /**\n * The title.\n */\n title: string = null;\n\n /**\n * This nav item's absolute href.\n */\n href: string = null;\n\n /**\n * This nav item's relative href.\n */\n relativeHref: string = null;\n\n /**\n * Data attached to the route at configuration time.\n */\n settings: any = {};\n\n /**\n * The route config.\n */\n config: RouteConfig = null;\n\n /**\n * The router associated with this navigation model.\n */\n router: Router;\n\n order: number | boolean;\n\n constructor(router: Router, relativeHref: string) {\n this.router = router;\n this.relativeHref = relativeHref;\n }\n\n /**\n * Sets the route's title and updates document.title.\n * If the a navigation is in progress, the change will be applied\n * to document.title when the navigation completes.\n *\n * @param title The new title.\n */\n setTitle(title: string): void {\n this.title = title;\n\n if (this.isActive) {\n this.router.updateTitle();\n }\n }\n}\n","import { RouteConfig } from './interfaces';\n\nexport function _normalizeAbsolutePath(path: string, hasPushState: boolean, absolute: boolean = false) {\n if (!hasPushState && path[0] !== '#') {\n path = '#' + path;\n }\n\n if (hasPushState && absolute) {\n path = path.substring(1, path.length);\n }\n\n return path;\n}\n\nexport function _createRootedPath(fragment: string, baseUrl: string, hasPushState: boolean, absolute?: boolean) {\n if (isAbsoluteUrl.test(fragment)) {\n return fragment;\n }\n\n let path = '';\n\n if (baseUrl.length && baseUrl[0] !== '/') {\n path += '/';\n }\n\n path += baseUrl;\n\n if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') {\n path += '/';\n }\n\n if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') {\n path = path.substring(0, path.length - 1);\n }\n\n return _normalizeAbsolutePath(path + fragment, hasPushState, absolute);\n}\n\nexport function _resolveUrl(fragment: string, baseUrl: string, hasPushState?: boolean) {\n if (isRootedPath.test(fragment)) {\n return _normalizeAbsolutePath(fragment, hasPushState);\n }\n\n return _createRootedPath(fragment, baseUrl, hasPushState);\n}\n\nexport function _ensureArrayWithSingleRoutePerConfig(config: RouteConfig) {\n let routeConfigs = [];\n\n if (Array.isArray(config.route)) {\n for (let i = 0, ii = config.route.length; i < ii; ++i) {\n let current = Object.assign({}, config);\n current.route = config.route[i];\n routeConfigs.push(current);\n }\n } else {\n routeConfigs.push(Object.assign({}, config));\n }\n\n return routeConfigs;\n}\n\nconst isRootedPath = /^#?\\//;\nconst isAbsoluteUrl = /^([a-z][a-z0-9+\\-.]*:)?\\/\\//i;\n","import { RouteConfig, PipelineStep, RouteConfigSpecifier } from './interfaces';\nimport { _ensureArrayWithSingleRoutePerConfig } from './util';\nimport { Router } from './router';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * Class used to configure a [[Router]] instance.\n *\n * @constructor\n */\nexport class RouterConfiguration {\n instructions: Array<(router: Router) => void> = [];\n options: {\n [key: string]: any;\n compareQueryParams?: boolean;\n root?: string;\n pushState?: boolean;\n hashChange?: boolean;\n silent?: boolean;\n } = {};\n pipelineSteps: Array<{ name: string, step: Function | PipelineStep }> = [];\n title: string;\n titleSeparator: string;\n unknownRouteConfig: RouteConfigSpecifier;\n viewPortDefaults: Record;\n\n /**@internal */\n _fallbackRoute: string;\n\n /**\n * Adds a step to be run during the [[Router]]'s navigation pipeline.\n *\n * @param name The name of the pipeline slot to insert the step into.\n * @param step The pipeline step.\n * @chainable\n */\n addPipelineStep(name: string, step: Function | PipelineStep): RouterConfiguration {\n if (step === null || step === undefined) {\n throw new Error('Pipeline step cannot be null or undefined.');\n }\n this.pipelineSteps.push({ name, step });\n return this;\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s authorize pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addAuthorizeStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.Authorize, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preActivate pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreActivateStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreActivate, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreRender, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s postRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPostRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PostRender, step);\n }\n\n /**\n * Configures a route that will be used if there is no previous location available on navigation cancellation.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @chainable\n */\n fallbackRoute(fragment: string): RouterConfiguration {\n this._fallbackRoute = fragment;\n return this;\n }\n\n /**\n * Maps one or more routes to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map.\n * @chainable\n */\n map(route: RouteConfig | RouteConfig[]): RouterConfiguration {\n if (Array.isArray(route)) {\n route.forEach(this.map.bind(this));\n return this;\n }\n\n return this.mapRoute(route);\n }\n\n /**\n * Configures defaults to use for any view ports.\n *\n * @param viewPortConfig a view port configuration object to use as a\n * default, of the form { viewPortName: { moduleId } }.\n * @chainable\n */\n useViewPortDefaults(viewPortConfig: Record): RouterConfiguration {\n this.viewPortDefaults = viewPortConfig;\n return this;\n }\n\n /**\n * Maps a single route to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map.\n * @chainable\n */\n mapRoute(config: RouteConfig): RouterConfiguration {\n this.instructions.push(router => {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n\n let navModel;\n for (let i = 0, ii = routeConfigs.length; i < ii; ++i) {\n let routeConfig = routeConfigs[i];\n routeConfig.settings = routeConfig.settings || {};\n if (!navModel) {\n navModel = router.createNavModel(routeConfig);\n }\n\n router.addRoute(routeConfig, navModel);\n }\n });\n\n return this;\n }\n\n /**\n * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes.\n *\n * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the\n * [[NavigationInstruction]] and selects a moduleId to load.\n * @chainable\n */\n mapUnknownRoutes(config: RouteConfigSpecifier): RouterConfiguration {\n this.unknownRouteConfig = config;\n return this;\n }\n\n /**\n * Applies the current configuration to the specified [[Router]].\n *\n * @param router The [[Router]] to apply the configuration to.\n */\n exportToRouter(router: Router): void {\n let instructions = this.instructions;\n for (let i = 0, ii = instructions.length; i < ii; ++i) {\n instructions[i](router);\n }\n\n if (this.title) {\n router.title = this.title;\n }\n\n if (this.titleSeparator) {\n router.titleSeparator = this.titleSeparator;\n }\n\n if (this.unknownRouteConfig) {\n router.handleUnknownRoutes(this.unknownRouteConfig);\n }\n\n if (this._fallbackRoute) {\n router.fallbackRoute = this._fallbackRoute;\n }\n\n if (this.viewPortDefaults) {\n router.useViewPortDefaults(this.viewPortDefaults);\n }\n\n Object.assign(router.options, this.options);\n\n let pipelineSteps = this.pipelineSteps;\n if (pipelineSteps.length) {\n if (!router.isRoot) {\n throw new Error('Pipeline steps can only be added to the root router');\n }\n\n let pipelineProvider = router.pipelineProvider;\n for (let i = 0, ii = pipelineSteps.length; i < ii; ++i) {\n let { name, step } = pipelineSteps[i];\n pipelineProvider.addStep(name, step);\n }\n }\n }\n}\n","import { RouteRecognizer, RouteHandler, ConfigurableRoute, State, RecognizedRoute } from 'aurelia-route-recognizer';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { NavigationInstruction, NavigationInstructionInit } from './navigation-instruction';\nimport { NavModel } from './nav-model';\nimport { RouterConfiguration } from './router-configuration';\nimport {\n _ensureArrayWithSingleRoutePerConfig,\n _normalizeAbsolutePath,\n _createRootedPath,\n _resolveUrl\n} from './util';\nimport { RouteConfig, NavigationResult, RouteConfigSpecifier, ViewPort, ViewPortInstruction } from './interfaces';\nimport { PipelineProvider } from './pipeline-provider';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface History {\n // This is wrong, as it's an implementation detail from aurelia-history-browser\n // but we are poking it in here so probably will need to make it official in `aurelia-history`\n /**\n * A private flag of Aurelia History implementation to indicate if push state should be used\n */\n _hasPushState: boolean;\n\n previousLocation: string;\n }\n}\n\n/**@internal */\ndeclare module 'aurelia-route-recognizer' {\n interface State {\n types: {\n dynamics: DynamicSegment;\n stars: StarSegment;\n };\n }\n\n interface RouteHandler {\n navigationStrategy?: (instruction: NavigationInstruction) => any;\n }\n\n interface RecognizedRoute {\n config?: RouteConfig;\n queryParams?: Record;\n }\n}\n\ntype RouterConfigurationResolution = RouterConfiguration | ((cfg: RouterConfiguration) => void | RouterConfiguration | Promise);\n\n/**\n * The primary class responsible for handling routing and navigation.\n */\nexport class Router {\n\n /**\n * Container associated with this router. Also used to create child container for creating child router.\n */\n container: Container;\n\n /**\n * History instance of Aurelia abstract class for wrapping platform history global object\n */\n history: History;\n\n /**\n * A registry of registered viewport. Will be used to handle process navigation instruction route loading\n * and dom swapping\n */\n viewPorts: Record;\n\n /**\n * List of route configs registered with this router\n */\n routes: RouteConfig[];\n\n /**\n * The [[Router]]'s current base URL, typically based on the [[Router.currentInstruction]].\n */\n baseUrl: string;\n\n /**\n * If defined, used in generation of document title for [[Router]]'s routes.\n */\n title: string | undefined;\n\n /**\n * The separator used in the document title between [[Router]]'s routes.\n */\n titleSeparator: string | undefined;\n\n /**\n * True if the [[Router]] has been configured.\n */\n isConfigured: boolean;\n\n /**\n * True if the [[Router]] is currently processing a navigation.\n */\n isNavigating: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigate function(s).\n */\n isExplicitNavigation: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigateBack function.\n */\n isExplicitNavigationBack: boolean;\n\n /**\n * True if the [[Router]] is navigating into the app for the first time in the browser session.\n */\n isNavigatingFirst: boolean;\n\n /**\n * True if the [[Router]] is navigating to a page instance not in the browser session history.\n */\n isNavigatingNew: boolean;\n\n /**\n * True if the [[Router]] is navigating forward in the browser session history.\n */\n isNavigatingForward: boolean;\n\n /**\n * True if the [[Router]] is navigating back in the browser session history.\n */\n isNavigatingBack: boolean;\n\n /**\n * True if the [[Router]] is navigating due to a browser refresh.\n */\n isNavigatingRefresh: boolean;\n\n /**\n * True if the previous instruction successfully completed the CanDeactivatePreviousStep in the current navigation.\n */\n couldDeactivate: boolean;\n\n /**\n * The currently active navigation tracker.\n */\n currentNavigationTracker: number;\n\n /**\n * The navigation models for routes that specified [[RouteConfig.nav]].\n */\n navigation: NavModel[];\n\n /**\n * The currently active navigation instruction.\n */\n currentInstruction: NavigationInstruction;\n\n /**\n * The parent router, or null if this instance is not a child router.\n */\n parent: Router = null;\n\n options: any = {};\n\n /**\n * The defaults used when a viewport lacks specified content\n */\n viewPortDefaults: Record = {};\n\n /**@internal */\n catchAllHandler: (instruction: NavigationInstruction) => NavigationInstruction | Promise;\n /**@internal */\n fallbackRoute: string;\n /**@internal */\n pipelineProvider: PipelineProvider;\n /**@internal */\n _fallbackOrder: number;\n /**@internal */\n _recognizer: RouteRecognizer;\n /**@internal */\n _childRecognizer: RouteRecognizer;\n /**@internal */\n _configuredPromise: Promise;\n /**@internal */\n _resolveConfiguredPromise: (value?: any) => void;\n\n /**\n * Extension point to transform the document title before it is built and displayed.\n * By default, child routers delegate to the parent router, and the app router\n * returns the title unchanged.\n */\n transformTitle: (title: string) => string = (title: string) => {\n if (this.parent) {\n return this.parent.transformTitle(title);\n }\n return title;\n }\n\n /**\n * @param container The [[Container]] to use when child routers.\n * @param history The [[History]] implementation to delegate navigation requests to.\n */\n constructor(container: Container, history: History) {\n this.container = container;\n this.history = history;\n this.reset();\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset() {\n this.viewPorts = {};\n this.routes = [];\n this.baseUrl = '';\n this.isConfigured = false;\n this.isNavigating = false;\n this.isExplicitNavigation = false;\n this.isExplicitNavigationBack = false;\n this.isNavigatingFirst = false;\n this.isNavigatingNew = false;\n this.isNavigatingRefresh = false;\n this.isNavigatingForward = false;\n this.isNavigatingBack = false;\n this.couldDeactivate = false;\n this.navigation = [];\n this.currentInstruction = null;\n this.viewPortDefaults = {};\n this._fallbackOrder = 100;\n this._recognizer = new RouteRecognizer();\n this._childRecognizer = new RouteRecognizer();\n this._configuredPromise = new Promise(resolve => {\n this._resolveConfiguredPromise = resolve;\n });\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent.\n */\n get isRoot(): boolean {\n return !this.parent;\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort.\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/any, name?: string): void {\n name = name || 'default';\n this.viewPorts[name] = viewPort;\n }\n\n /**\n * Returns a Promise that resolves when the router is configured.\n */\n ensureConfigured(): Promise {\n return this._configuredPromise;\n }\n\n /**\n * Configures the router.\n *\n * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]].\n */\n configure(callbackOrConfig: RouterConfiguration | ((config: RouterConfiguration) => RouterConfiguration)): Promise {\n this.isConfigured = true;\n\n let result: RouterConfigurationResolution = callbackOrConfig as RouterConfiguration;\n let config: RouterConfiguration;\n if (typeof callbackOrConfig === 'function') {\n config = new RouterConfiguration();\n result = callbackOrConfig(config);\n }\n\n return Promise\n .resolve(result)\n .then((c) => {\n if (c && (c as RouterConfiguration).exportToRouter) {\n config = c;\n }\n\n config.exportToRouter(this);\n this.isConfigured = true;\n this._resolveConfiguredPromise();\n });\n }\n\n /**\n * Navigates to a new location.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n navigate(fragment: string, options?: NavigationOptions): boolean {\n if (!this.isConfigured && this.parent) {\n return this.parent.navigate(fragment, options);\n }\n\n this.isExplicitNavigation = true;\n return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options);\n }\n\n /**\n * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed\n * by [[Router.navigate]].\n *\n * @param route The name of the route to use when generating the navigation location.\n * @param params The route parameters to be used when populating the route pattern.\n * @param options The navigation options.\n */\n navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean {\n let path = this.generate(route, params);\n return this.navigate(path, options);\n }\n\n /**\n * Navigates back to the most recent location in history.\n */\n navigateBack(): void {\n this.isExplicitNavigationBack = true;\n this.history.navigateBack();\n }\n\n /**\n * Creates a child router of the current router.\n *\n * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified.\n * @returns {Router} The new child Router.\n */\n createChild(container?: Container): Router {\n let childRouter = new Router(container || this.container.createChild(), this.history);\n childRouter.parent = this;\n return childRouter;\n }\n\n /**\n * Generates a URL fragment matching the specified route pattern.\n *\n * @param name The name of the route whose pattern should be used to generate the fragment.\n * @param params The route params to be used to populate the route pattern.\n * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url.\n * @returns {string} A string containing the generated URL fragment.\n */\n generate(nameOrRoute: string | RouteConfig, params: any = {}, options: any = {}): string {\n // A child recognizer generates routes for potential child routes. Any potential child route is added\n // to the childRoute property of params for the childRouter to recognize. When generating routes, we\n // use the childRecognizer when childRoute params are available to generate a child router enabled route.\n let recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer;\n let hasRoute = recognizer.hasRoute(nameOrRoute as string | RouteHandler);\n if (!hasRoute) {\n if (this.parent) {\n return this.parent.generate(nameOrRoute, params, options);\n }\n throw new Error(`A route with name '${nameOrRoute}' could not be found. Check that \\`name: '${nameOrRoute}'\\` was specified in the route's config.`);\n }\n let path = recognizer.generate(nameOrRoute as string | RouteHandler, params);\n let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute);\n return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath;\n }\n\n /**\n * Creates a [[NavModel]] for the specified route config.\n *\n * @param config The route config.\n */\n createNavModel(config: RouteConfig): NavModel {\n let navModel = new NavModel(\n this,\n 'href' in config\n ? config.href\n // potential error when config.route is a string[] ?\n : config.route as string);\n navModel.title = config.title;\n navModel.order = config.nav;\n navModel.href = config.href;\n navModel.settings = config.settings;\n navModel.config = config;\n\n return navModel;\n }\n\n /**\n * Registers a new route with the router.\n *\n * @param config The [[RouteConfig]].\n * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes.\n */\n addRoute(config: RouteConfig, navModel?: NavModel): void {\n if (Array.isArray(config.route)) {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n // the following is wrong. todo: fix this after TS refactoring release\n routeConfigs.forEach(this.addRoute.bind(this));\n return;\n }\n\n validateRouteConfig(config);\n\n if (!('viewPorts' in config) && !config.navigationStrategy) {\n config.viewPorts = {\n 'default': {\n moduleId: config.moduleId,\n view: config.view\n }\n };\n }\n\n if (!navModel) {\n navModel = this.createNavModel(config);\n }\n\n this.routes.push(config);\n\n let path = config.route;\n if (path.charAt(0) === '/') {\n path = path.substr(1);\n }\n let caseSensitive = config.caseSensitive === true;\n let state: State = this._recognizer.add({\n path: path,\n handler: config as RouteHandler,\n caseSensitive: caseSensitive\n } as ConfigurableRoute);\n\n if (path) {\n let settings = config.settings;\n delete config.settings;\n let withChild = JSON.parse(JSON.stringify(config));\n config.settings = settings;\n withChild.route = `${path}/*childRoute`;\n withChild.hasChildRouter = true;\n this._childRecognizer.add({\n path: withChild.route,\n handler: withChild,\n caseSensitive: caseSensitive\n });\n\n withChild.navModel = navModel;\n withChild.settings = config.settings;\n withChild.navigationStrategy = config.navigationStrategy;\n }\n\n config.navModel = navModel;\n\n let navigation = this.navigation;\n\n if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) {\n if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) {\n throw new Error('Invalid route config for \"' + config.route + '\" : dynamic routes must specify an \"href:\" to be included in the navigation model.');\n }\n\n if (typeof navModel.order !== 'number') {\n navModel.order = ++this._fallbackOrder;\n }\n\n navigation.push(navModel);\n // this is a potential error / inconsistency between browsers\n //\n // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\n // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other,\n // but sorted with respect to all different elements.\n // Note: the ECMAscript standard does not guarantee this behaviour,\n // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.\n navigation.sort((a, b) => a.order - b.order);\n }\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasRoute(name: string): boolean {\n return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name));\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasOwnRoute(name: string): boolean {\n return this._recognizer.hasRoute(name);\n }\n\n /**\n * Register a handler to use when the incoming URL fragment doesn't match any registered routes.\n *\n * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]].\n */\n handleUnknownRoutes(config?: RouteConfigSpecifier): void {\n if (!config) {\n throw new Error('Invalid unknown route handler');\n }\n\n this.catchAllHandler = instruction => {\n return this\n ._createRouteConfig(config, instruction)\n .then(c => {\n instruction.config = c;\n return instruction;\n });\n };\n }\n\n /**\n * Updates the document title using the current navigation instruction.\n */\n updateTitle(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n return parentRouter.updateTitle();\n }\n\n let currentInstruction = this.currentInstruction;\n if (currentInstruction) {\n currentInstruction._updateTitle();\n }\n return undefined;\n }\n\n /**\n * Updates the navigation routes with hrefs relative to the current location.\n * Note: This method will likely move to a plugin in a future release.\n */\n refreshNavigation(): void {\n let nav = this.navigation;\n\n for (let i = 0, length = nav.length; i < length; i++) {\n let current = nav[i];\n if (!current.config.href) {\n current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState);\n } else {\n current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState);\n }\n }\n }\n\n /**\n * Sets the default configuration for the view ports. This specifies how to\n * populate a view port for which no module is specified. The default is\n * an empty view/view-model pair.\n */\n useViewPortDefaults($viewPortDefaults: Record): void {\n // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction\n let viewPortDefaults: Record = $viewPortDefaults;\n for (let viewPortName in viewPortDefaults) {\n let viewPortConfig = viewPortDefaults[viewPortName];\n this.viewPortDefaults[viewPortName] = {\n moduleId: viewPortConfig.moduleId\n };\n }\n }\n\n /**@internal */\n _refreshBaseUrl(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction);\n }\n }\n\n /**@internal */\n _createNavigationInstruction(url: string = '', parentInstruction: NavigationInstruction = null): Promise {\n let fragment = url;\n let queryString = '';\n\n let queryIndex = url.indexOf('?');\n if (queryIndex !== -1) {\n fragment = url.substr(0, queryIndex);\n queryString = url.substr(queryIndex + 1);\n }\n\n let urlRecognizationResults = this._recognizer.recognize(url) as IRouteRecognizationResults;\n if (!urlRecognizationResults || !urlRecognizationResults.length) {\n urlRecognizationResults = this._childRecognizer.recognize(url) as IRouteRecognizationResults;\n }\n\n let instructionInit: NavigationInstructionInit = {\n fragment,\n queryString,\n config: null,\n parentInstruction,\n previousInstruction: this.currentInstruction,\n router: this,\n options: {\n compareQueryParams: this.options.compareQueryParams\n }\n };\n\n let result: Promise;\n\n if (urlRecognizationResults && urlRecognizationResults.length) {\n let first = urlRecognizationResults[0];\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: first.params,\n queryParams: first.queryParams || urlRecognizationResults.queryParams,\n config: first.config || first.handler\n }));\n\n if (typeof first.handler === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler, first);\n } else if (first.handler && typeof first.handler.navigationStrategy === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler);\n } else {\n result = Promise.resolve(instruction);\n }\n } else if (this.catchAllHandler) {\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n config: null // config will be created by the catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, this.catchAllHandler);\n } else if (this.parent) {\n let router = this._parentCatchAllHandler(this.parent);\n\n if (router) {\n let newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction);\n\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n router: router,\n parentInstruction: newParentInstruction,\n parentCatchHandler: true,\n config: null // config will be created by the chained parent catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, router.catchAllHandler);\n }\n }\n\n if (result && parentInstruction) {\n this.baseUrl = generateBaseUrl(this.parent, parentInstruction);\n }\n\n return result || Promise.reject(new Error(`Route not found: ${url}`));\n }\n\n /**@internal */\n _findParentInstructionFromRouter(router: Router, instruction: NavigationInstruction): NavigationInstruction {\n if (instruction.router === router) {\n instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId\n return instruction;\n } else if (instruction.parentInstruction) {\n return this._findParentInstructionFromRouter(router, instruction.parentInstruction);\n }\n return undefined;\n }\n\n /**@internal */\n _parentCatchAllHandler(router: Router): Router | false {\n if (router.catchAllHandler) {\n return router;\n } else if (router.parent) {\n return this._parentCatchAllHandler(router.parent);\n }\n return false;\n }\n\n /**\n * @internal\n */\n _createRouteConfig(config: RouteConfigSpecifier, instruction: NavigationInstruction): Promise {\n return Promise\n .resolve(config)\n .then((c: any) => {\n if (typeof c === 'string') {\n return { moduleId: c } as RouteConfig;\n } else if (typeof c === 'function') {\n return c(instruction);\n }\n\n return c;\n })\n // typing here could be either RouteConfig or RedirectConfig\n // but temporarily treat both as RouteConfig\n // todo: improve typings precision\n .then((c: string | RouteConfig) => typeof c === 'string' ? { moduleId: c } as RouteConfig : c)\n .then((c: RouteConfig) => {\n c.route = instruction.params.path;\n validateRouteConfig(c);\n\n if (!c.navModel) {\n c.navModel = this.createNavModel(c);\n }\n\n return c;\n });\n }\n}\n\n/* @internal exported for unit testing */\nexport const generateBaseUrl = (router: Router, instruction: NavigationInstruction): string => {\n return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`;\n};\n\n/* @internal exported for unit testing */\nexport const validateRouteConfig = (config: RouteConfig): void => {\n if (typeof config !== 'object') {\n throw new Error('Invalid Route Config');\n }\n\n if (typeof config.route !== 'string') {\n let name = config.name || '(no name)';\n throw new Error('Invalid Route Config for \"' + name + '\": You must specify a \"route:\" pattern.');\n }\n\n if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) {\n throw new Error('Invalid Route Config for \"' + config.route + '\": You must specify a \"moduleId:\", \"redirect:\", \"navigationStrategy:\", or \"viewPorts:\".');\n }\n};\n\n/* @internal exported for unit testing */\nexport const evaluateNavigationStrategy = (\n instruction: NavigationInstruction,\n evaluator: Function,\n context?: any\n): Promise => {\n return Promise.resolve(evaluator.call(context, instruction)).then(() => {\n if (!('viewPorts' in instruction.config)) {\n instruction.config.viewPorts = {\n 'default': {\n moduleId: instruction.config.moduleId\n }\n };\n }\n\n return instruction;\n });\n};\n\ninterface IRouteRecognizationResults extends Array {\n queryParams: Record;\n}\n","import { PipelineStatus } from './pipeline-status';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Next, StepRunnerFunction, NextCompletionHandler } from './interfaces';\n\n/**@internal exported for unit testing */\nexport const createNextFn = (instruction: NavigationInstruction, steps: StepRunnerFunction[]): Next => {\n let index = -1;\n const next: Next = function() {\n index++;\n\n if (index < steps.length) {\n let currentStep = steps[index];\n\n try {\n return currentStep(instruction, next);\n } catch (e) {\n return next.reject(e);\n }\n } else {\n return next.complete();\n }\n } as Next;\n\n next.complete = createCompletionHandler(next, PipelineStatus.Completed);\n next.cancel = createCompletionHandler(next, PipelineStatus.Canceled);\n next.reject = createCompletionHandler(next, PipelineStatus.Rejected);\n\n return next;\n};\n\n/**@internal exported for unit testing */\nexport const createCompletionHandler = (next: Next, status: PipelineStatus): NextCompletionHandler => {\n return (output: any) => Promise\n .resolve({\n status,\n output,\n completed: status === PipelineStatus.Completed\n });\n};\n","import { PipelineStep, PipelineResult, Next, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { createNextFn } from './next';\n\n/**\n* The class responsible for managing and processing the navigation pipeline.\n*/\nexport class Pipeline {\n /**\n * The pipeline steps. And steps added via addStep will be converted to a function\n * The actualy running functions with correct step contexts of this pipeline\n */\n steps: StepRunnerFunction[] = [];\n\n /**\n * Adds a step to the pipeline.\n *\n * @param step The pipeline step.\n */\n addStep(step: StepRunnerFunction | PipelineStep | IPipelineSlot): Pipeline {\n let run;\n\n if (typeof step === 'function') {\n run = step;\n } else if (typeof step.getSteps === 'function') {\n // getSteps is to enable support open slots\n // where devs can add multiple steps into the same slot name\n let steps = step.getSteps();\n for (let i = 0, l = steps.length; i < l; i++) {\n this.addStep(steps[i]);\n }\n\n return this;\n } else {\n run = (step as PipelineStep).run.bind(step);\n }\n\n this.steps.push(run);\n\n return this;\n }\n\n /**\n * Runs the pipeline.\n *\n * @param instruction The navigation instruction to process.\n */\n run(instruction: NavigationInstruction): Promise {\n const nextFn = createNextFn(instruction, this.steps);\n return nextFn();\n }\n}\n","import { Next, RouteConfig, ViewPortComponent, ViewPortPlan, ViewPortInstruction } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy, _buildNavigationPlan } from './navigation-plan';\nimport { Router } from './router';\n\n/**\n * Loading plan calculated based on a navigration-instruction and a viewport plan\n */\ninterface ILoadingPlan {\n viewPortPlan: ViewPortPlan;\n navigationInstruction: NavigationInstruction;\n}\n\n/**\n * Abstract class that is responsible for loading view / view model from a route config\n * The default implementation can be found in `aurelia-templating-router`\n */\nexport class RouteLoader {\n /**\n * Load a route config based on its viewmodel / view configuration\n */\n // return typing: return typings used to be never\n // as it was a throw. Changing it to Promise should not cause any issues\n loadRoute(router: Router, config: RouteConfig, navigationInstruction: NavigationInstruction): Promise {\n throw new Error('Route loaders must implement \"loadRoute(router, config, navigationInstruction)\".');\n }\n}\n\n/**\n * A pipeline step responsible for loading a route config of a navigation instruction\n */\nexport class LoadRouteStep {\n /**@internal */\n static inject() { return [RouteLoader]; }\n /**\n * Route loader isntance that will handle loading route config\n * @internal\n */\n routeLoader: RouteLoader;\n\n constructor(routeLoader: RouteLoader) {\n this.routeLoader = routeLoader;\n }\n\n /**\n * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline\n */\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return loadNewRoute(this.routeLoader, navigationInstruction)\n .then(next, next.cancel);\n }\n}\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadNewRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction\n): Promise => {\n let toLoad = determineWhatToLoad(navigationInstruction);\n let loadPromises = toLoad.map((loadingPlan: ILoadingPlan) => loadRoute(\n routeLoader,\n loadingPlan.navigationInstruction,\n loadingPlan.viewPortPlan\n ));\n\n return Promise.all(loadPromises);\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const determineWhatToLoad = (\n navigationInstruction: NavigationInstruction,\n toLoad: ILoadingPlan[] = []\n): ILoadingPlan[] => {\n let plan: Record = navigationInstruction.plan;\n\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let child_nav_instruction = viewPortPlan.childNavigationInstruction;\n\n if (viewPortPlan.strategy === activationStrategy.replace) {\n toLoad.push({ viewPortPlan, navigationInstruction } as ILoadingPlan);\n\n if (child_nav_instruction) {\n determineWhatToLoad(child_nav_instruction, toLoad);\n }\n } else {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction(\n viewPortName,\n viewPortPlan.strategy,\n viewPortPlan.prevModuleId,\n viewPortPlan.prevComponent\n ) as ViewPortInstruction;\n\n if (child_nav_instruction) {\n viewPortInstruction.childNavigationInstruction = child_nav_instruction;\n determineWhatToLoad(child_nav_instruction, toLoad);\n }\n }\n }\n\n return toLoad;\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n viewPortPlan: ViewPortPlan\n): Promise => {\n let moduleId = viewPortPlan.config ? viewPortPlan.config.moduleId : null;\n\n return loadComponent(routeLoader, navigationInstruction, viewPortPlan.config)\n .then((component) => {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction(\n viewPortPlan.name,\n viewPortPlan.strategy,\n moduleId,\n component\n ) as ViewPortInstruction;\n\n let childRouter = component.childRouter;\n if (childRouter) {\n let path = navigationInstruction.getWildcardPath();\n\n return childRouter\n ._createNavigationInstruction(path, navigationInstruction)\n .then((childInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(childInstruction)\n .then((childPlan) => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n viewPortInstruction.childNavigationInstruction = childInstruction;\n\n return loadNewRoute(routeLoader, childInstruction);\n });\n });\n }\n // ts complains without this, though they are same\n return void 0;\n });\n};\n\n/**\n * Load a routed-component based on navigation instruction and route config\n * @internal exported for unit testing only\n */\nexport const loadComponent = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n config: RouteConfig\n): Promise => {\n let router = navigationInstruction.router;\n let lifecycleArgs = navigationInstruction.lifecycleArgs;\n\n return Promise.resolve()\n .then(() => routeLoader.loadRoute(router, config, navigationInstruction))\n .then(\n /**\n * @param component an object carrying information about loaded route\n * typically contains information about view model, childContainer, view and router\n */\n (component: ViewPortComponent) => {\n let { viewModel, childContainer } = component;\n component.router = router;\n component.config = config;\n\n if ('configureRouter' in viewModel) {\n let childRouter = childContainer.getChildRouter();\n component.childRouter = childRouter;\n\n return childRouter\n .configure(c => viewModel.configureRouter(c, childRouter, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]))\n .then(() => component);\n }\n\n return component;\n });\n};\n","import { Container } from 'aurelia-dependency-injection';\nimport { Pipeline } from './pipeline';\nimport { BuildNavigationPlanStep } from './navigation-plan';\nimport { LoadRouteStep } from './route-loading';\nimport { CommitChangesStep } from './navigation-instruction';\nimport {\n CanDeactivatePreviousStep,\n CanActivateNextStep,\n DeactivatePreviousStep,\n ActivateNextStep\n} from './activation';\nimport { PipelineStep, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution\n */\nclass PipelineSlot implements IPipelineSlot {\n\n /**@internal */\n container: Container;\n /**@internal */\n slotName: string;\n /**@internal */\n slotAlias?: string;\n\n steps: (Function | PipelineStep)[] = [];\n\n constructor(container: Container, name: string, alias?: string) {\n this.container = container;\n this.slotName = name;\n this.slotAlias = alias;\n }\n\n getSteps(): (StepRunnerFunction | IPipelineSlot | PipelineStep)[] {\n return this.steps.map(x => this.container.get(x));\n }\n}\n\n/**\n* Class responsible for creating the navigation pipeline.\n*/\nexport class PipelineProvider {\n\n /**@internal */\n static inject() { return [Container]; }\n /**@internal */\n container: Container;\n /**@internal */\n steps: (Function | PipelineSlot)[];\n\n constructor(container: Container) {\n this.container = container;\n this.steps = [\n BuildNavigationPlanStep,\n CanDeactivatePreviousStep, // optional\n LoadRouteStep,\n this._createPipelineSlot(PipelineSlotName.Authorize),\n CanActivateNextStep, // optional\n this._createPipelineSlot(PipelineSlotName.PreActivate, 'modelbind'),\n // NOTE: app state changes start below - point of no return\n DeactivatePreviousStep, // optional\n ActivateNextStep, // optional\n this._createPipelineSlot(PipelineSlotName.PreRender, 'precommit'),\n CommitChangesStep,\n this._createPipelineSlot(PipelineSlotName.PostRender, 'postcomplete')\n ];\n }\n\n /**\n * Create the navigation pipeline.\n */\n createPipeline(useCanDeactivateStep: boolean = true): Pipeline {\n let pipeline = new Pipeline();\n this.steps.forEach(step => {\n if (useCanDeactivateStep || step !== CanDeactivatePreviousStep) {\n pipeline.addStep(this.container.get(step));\n }\n });\n return pipeline;\n }\n\n /**@internal */\n _findStep(name: string): PipelineSlot {\n // Steps that are not PipelineSlots are constructor functions, and they will automatically fail. Probably.\n return this.steps.find(x => (x as PipelineSlot).slotName === name || (x as PipelineSlot).slotAlias === name) as PipelineSlot;\n }\n\n /**\n * Adds a step into the pipeline at a known slot location.\n */\n addStep(name: string, step: PipelineStep | Function): void {\n let found = this._findStep(name);\n if (found) {\n // prevent duplicates\n if (!found.steps.includes(step)) {\n found.steps.push(step);\n }\n } else {\n throw new Error(`Invalid pipeline slot name: ${name}.`);\n }\n }\n\n /**\n * Removes a step from a slot in the pipeline\n */\n removeStep(name: string, step: PipelineStep): void {\n let slot = this._findStep(name);\n if (slot) {\n let steps = slot.steps;\n steps.splice(steps.indexOf(step), 1);\n }\n }\n\n /**\n * @internal\n * Clears all steps from a slot in the pipeline\n */\n _clearSteps(name: string = ''): void {\n let slot = this._findStep(name);\n if (slot) {\n slot.steps = [];\n }\n }\n\n /**\n * Resets all pipeline slots\n */\n reset(): void {\n this._clearSteps('authorize');\n this._clearSteps('preActivate');\n this._clearSteps('preRender');\n this._clearSteps('postRender');\n }\n\n /**@internal */\n _createPipelineSlot(name: string, alias?: string): PipelineSlot {\n return new PipelineSlot(this.container, name, alias);\n }\n}\n","import * as LogManager from 'aurelia-logging';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\nimport { PipelineProvider } from './pipeline-provider';\nimport { isNavigationCommand } from './navigation-commands';\nimport { EventAggregator } from 'aurelia-event-aggregator';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { ViewPort, ConfiguresRouter, PipelineResult } from './interfaces';\nimport { RouterEvent } from './router-event';\n\n/**@internal */\ndeclare module 'aurelia-dependency-injection' {\n interface Container {\n viewModel?: any;\n }\n}\n\nconst logger = LogManager.getLogger('app-router');\n\n/**\n* The main application router.\n*/\nexport class AppRouter extends Router {\n\n /**@internal */\n static inject() { return [Container, History, PipelineProvider, EventAggregator]; }\n\n events: EventAggregator;\n /**@internal */\n maxInstructionCount: number;\n /**@internal */\n _queue: NavigationInstruction[];\n /**@internal */\n isActive: boolean;\n\n constructor(container: Container, history: History, pipelineProvider: PipelineProvider, events: EventAggregator) {\n super(container, history); // Note the super will call reset internally.\n this.pipelineProvider = pipelineProvider;\n this.events = events;\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset(): void {\n super.reset();\n this.maxInstructionCount = 10;\n if (!this._queue) {\n this._queue = [];\n } else {\n this._queue.length = 0;\n }\n }\n\n /**\n * Loads the specified URL.\n *\n * @param url The URL fragment to load.\n */\n loadUrl(url: string): Promise {\n return this\n ._createNavigationInstruction(url)\n .then(instruction => this._queueInstruction(instruction))\n .catch(error => {\n logger.error(error);\n restorePreviousLocation(this);\n });\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort. This is typically a element in Aurelia default impl\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/ any, name?: string): Promise {\n // having strong typing without changing public API\n const $viewPort: ViewPort = viewPort;\n super.registerViewPort($viewPort, name);\n\n // beside adding viewport to the registry of this instance\n // AppRouter also configure routing/history to start routing functionality\n // There are situation where there are more than 1 element at root view\n // in that case, still only activate once via the following guard\n if (!this.isActive) {\n const viewModel = this._findViewModel($viewPort);\n if ('configureRouter' in viewModel) {\n // If there are more than one element at root view\n // use this flag to guard against configure method being invoked multiple times\n // this flag is set inside method configure\n if (!this.isConfigured) {\n // replace the real resolve with a noop to guarantee that any action in base class Router\n // won't resolve the configurePromise prematurely\n const resolveConfiguredPromise = this._resolveConfiguredPromise;\n this._resolveConfiguredPromise = () => {/**/};\n return this\n .configure(config => {\n viewModel.configureRouter(config, this);\n return config;\n })\n .then(() => {\n this.activate();\n resolveConfiguredPromise();\n });\n }\n } else {\n this.activate();\n }\n }\n // when a viewport is added dynamically to a root view that is already activated\n // just process the navigation instruction\n else {\n this._dequeueInstruction();\n }\n\n return Promise.resolve();\n }\n\n /**\n * Activates the router. This instructs the router to begin listening for history changes and processing instructions.\n *\n * @params options The set of options to activate the router with.\n */\n activate(options?: NavigationOptions): void {\n if (this.isActive) {\n return;\n }\n\n this.isActive = true;\n // route handler property is responsible for handling url change\n // the interface of aurelia-history isn't clear on this perspective\n this.options = Object.assign({ routeHandler: this.loadUrl.bind(this) }, this.options, options);\n this.history.activate(this.options);\n this._dequeueInstruction();\n }\n\n /**\n * Deactivates the router.\n */\n deactivate(): void {\n this.isActive = false;\n this.history.deactivate();\n }\n\n /**@internal */\n _queueInstruction(instruction: NavigationInstruction): Promise {\n return new Promise((resolve) => {\n instruction.resolve = resolve;\n this._queue.unshift(instruction);\n this._dequeueInstruction();\n });\n }\n\n /**@internal */\n _dequeueInstruction(instructionCount: number = 0): Promise {\n return Promise.resolve().then(() => {\n if (this.isNavigating && !instructionCount) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n let instruction = this._queue.shift();\n this._queue.length = 0;\n\n if (!instruction) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n this.isNavigating = true;\n\n let navtracker: number = this.history.getState('NavigationTracker');\n if (!navtracker && !this.currentNavigationTracker) {\n this.isNavigatingFirst = true;\n this.isNavigatingNew = true;\n } else if (!navtracker) {\n this.isNavigatingNew = true;\n } else if (!this.currentNavigationTracker) {\n this.isNavigatingRefresh = true;\n } else if (this.currentNavigationTracker < navtracker) {\n this.isNavigatingForward = true;\n } else if (this.currentNavigationTracker > navtracker) {\n this.isNavigatingBack = true;\n } if (!navtracker) {\n navtracker = Date.now();\n this.history.setState('NavigationTracker', navtracker);\n }\n this.currentNavigationTracker = navtracker;\n\n instruction.previousInstruction = this.currentInstruction;\n\n if (!instructionCount) {\n this.events.publish(RouterEvent.Processing, { instruction });\n } else if (instructionCount === this.maxInstructionCount - 1) {\n logger.error(`${instructionCount + 1} navigation instructions have been attempted without success. Restoring last known good location.`);\n restorePreviousLocation(this);\n return this._dequeueInstruction(instructionCount + 1);\n } else if (instructionCount > this.maxInstructionCount) {\n throw new Error('Maximum navigation attempts exceeded. Giving up.');\n }\n\n let pipeline = this.pipelineProvider.createPipeline(!this.couldDeactivate);\n\n return pipeline\n .run(instruction)\n .then(result => processResult(instruction, result, instructionCount, this))\n .catch(error => {\n return { output: error instanceof Error ? error : new Error(error) } as PipelineResult;\n })\n .then(result => resolveInstruction(instruction, result, !!instructionCount, this));\n });\n }\n\n /**@internal */\n _findViewModel(viewPort: ViewPort): ConfiguresRouter | undefined {\n if (this.container.viewModel) {\n return this.container.viewModel;\n }\n\n if (viewPort.container) {\n let container = viewPort.container;\n\n while (container) {\n if (container.viewModel) {\n this.container.viewModel = container.viewModel;\n return container.viewModel;\n }\n\n container = container.parent;\n }\n }\n\n return undefined;\n }\n}\n\nconst processResult = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n instructionCount: number,\n router: AppRouter\n): Promise => {\n if (!(result && 'completed' in result && 'output' in result)) {\n result = result || {} as PipelineResult;\n result.output = new Error(`Expected router pipeline to return a navigation result, but got [${JSON.stringify(result)}] instead.`);\n }\n\n let finalResult: PipelineResult = null;\n let navigationCommandResult = null;\n if (isNavigationCommand(result.output)) {\n navigationCommandResult = result.output.navigate(router);\n } else {\n finalResult = result;\n\n if (!result.completed) {\n if (result.output instanceof Error) {\n logger.error(result.output.toString());\n }\n\n restorePreviousLocation(router);\n }\n }\n\n return Promise.resolve(navigationCommandResult)\n .then(_ => router._dequeueInstruction(instructionCount + 1))\n .then(innerResult => finalResult || innerResult || result);\n};\n\nconst resolveInstruction = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n isInnerInstruction: boolean,\n router: AppRouter\n): PipelineResult => {\n instruction.resolve(result);\n\n let eventArgs = { instruction, result };\n if (!isInnerInstruction) {\n router.isNavigating = false;\n router.isExplicitNavigation = false;\n router.isExplicitNavigationBack = false;\n router.isNavigatingFirst = false;\n router.isNavigatingNew = false;\n router.isNavigatingRefresh = false;\n router.isNavigatingForward = false;\n router.isNavigatingBack = false;\n router.couldDeactivate = false;\n\n let eventName: string;\n\n if (result.output instanceof Error) {\n eventName = RouterEvent.Error;\n } else if (!result.completed) {\n eventName = RouterEvent.Canceled;\n } else {\n let queryString = instruction.queryString ? ('?' + instruction.queryString) : '';\n router.history.previousLocation = instruction.fragment + queryString;\n eventName = RouterEvent.Success;\n }\n\n router.events.publish(eventName, eventArgs);\n router.events.publish(RouterEvent.Complete, eventArgs);\n } else {\n router.events.publish(RouterEvent.ChildComplete, eventArgs);\n }\n\n return result;\n};\n\nconst restorePreviousLocation = (router: AppRouter): void => {\n let previousLocation = router.history.previousLocation;\n if (previousLocation) {\n router.navigate(router.history.previousLocation, { trigger: false, replace: true });\n } else if (router.fallbackRoute) {\n router.navigate(router.fallbackRoute, { trigger: true, replace: true });\n } else {\n logger.error('Router navigation failed, and no previous location or fallbackRoute could be restored.');\n }\n};\n","/**\n* The status of a Pipeline.\n*/\nexport const enum PipelineStatus {\n Completed = 'completed',\n Canceled = 'canceled',\n Rejected = 'rejected',\n Running = 'running'\n}\n","/**\n * A list of known router events used by the Aurelia router\n * to signal the pipeline has come to a certain state\n */\n// const enum is preserved in tsconfig\nexport const enum RouterEvent {\n Processing = 'router:navigation:processing',\n Error = 'router:navigation:error',\n Canceled = 'router:navigation:canceled',\n Complete = 'router:navigation:complete',\n Success = 'router:navigation:success',\n ChildComplete = 'router:navigation:child:complete'\n}\n","/**\n * Available pipeline slot names to insert interceptor into router pipeline\n */\n// const enum is preserved in tsconfig\nexport const enum PipelineSlotName {\n /**\n * Authorization slot. Invoked early in the pipeline,\n * before `canActivate` hook of incoming route\n */\n Authorize = 'authorize',\n /**\n * Pre-activation slot. Invoked early in the pipeline,\n * Invoked timing:\n * - after Authorization slot\n * - after canActivate hook on new view model\n * - before deactivate hook on old view model\n * - before activate hook on new view model\n */\n PreActivate = 'preActivate',\n /**\n * Pre-render slot. Invoked later in the pipeline\n * Invokcation timing:\n * - after activate hook on new view model\n * - before commit step on new navigation instruction\n */\n PreRender = 'preRender',\n /**\n * Post-render slot. Invoked last in the pipeline\n */\n PostRender = 'postRender'\n}\n"],"names":["RouteRecognizer","Container","LogManager.getLogger","tslib_1.__extends","History","EventAggregator","PipelineStatus","RouterEvent","PipelineSlotName"],"mappings":";;EAuBA;;;;;;AAMA,WAAgB,mBAAmB,CAAC,GAAQ;MAC1C,OAAO,GAAG,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,UAAU,CAAC;EACnD,CAAC;EAED;;;AAGA;;;;;MAcE,kBAAY,GAAW,EAAE,OAA+B;UAA/B,wBAAA,EAAA,YAA+B;UACtD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;UACf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;UACxE,IAAI,CAAC,wBAAwB,GAAG,KAAK,CAAC;OACvC;;;;;;MAOD,4BAAS,GAAT,UAAU,MAAc;UACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;OACtB;;;;;;MAOD,2BAAQ,GAAR,UAAS,SAAiB;UACxB,IAAI,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,SAAS,IAAI,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC;UAC1F,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;OACnD;MACH,eAAC;EAAD,CAAC,IAAA;EAED;;;AAGA;;;;;;MAkBE,yBAAY,KAAa,EAAE,MAAgB,EAAE,OAA+B;UAAjD,uBAAA,EAAA,WAAgB;UAAE,wBAAA,EAAA,YAA+B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C,OAAO,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;OACrF;WAAM,IAAI,MAAM,CAAC,aAAa,EAAE;UAC/B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;OACzE;WAAM;UACL,MAAM,CAAC,KAAK,CAAC,wFAAwF,CAAC,CAAC;OACxG;EACH,CAAC,CAAC;;EChUF;;;AAGA,EAAA,WAAkB,cAAc;MAC9B,yCAAuB,CAAA;MACvB,uCAAqB,CAAA;MACrB,uCAAqB,CAAA;MACrB,qCAAmB,CAAA;EACrB,CAAC,EALiBC,sBAAc,KAAdA,sBAAc,QAK/B;;ECRD;;;;AAIA,EACA,WAAkB,WAAW;MAC3B,0DAA2C,CAAA;MAC3C,gDAAiC,CAAA;MACjC,sDAAuC,CAAA;MACvC,sDAAuC,CAAA;MACvC,oDAAqC,CAAA;MACrC,iEAAkD,CAAA;EACpD,CAAC,EAPiBC,mBAAW,KAAXA,mBAAW,QAO5B;;ECZD;;;AAGA,EACA,WAAkB,gBAAgB;;;;;MAKhC,2CAAuB,CAAA;;;;;;;;;MASvB,+CAA2B,CAAA;;;;;;;MAO3B,2CAAuB,CAAA;;;;MAIvB,6CAAyB,CAAA;EAC3B,CAAC,EA1BiBC,wBAAgB,KAAhBA,wBAAgB,QA0BjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"aurelia-router.js","sources":["../../src/navigation-instruction.ts","../../src/nav-model.ts","../../src/util.ts","../../src/router-configuration.ts","../../src/router.ts","../../src/next.ts","../../src/pipeline.ts","../../src/navigation-commands.ts","../../src/navigation-plan.ts","../../src/step-build-navigation-plan.ts","../../src/utilities-route-loading.ts","../../src/route-loader.ts","../../src/step-load-route.ts","../../src/step-commit-changes.ts","../../src/activation-strategy.ts","../../src/utilities-activation.ts","../../src/step-activation.ts","../../src/pipeline-provider.ts","../../src/app-router.ts","../../src/pipeline-status.ts","../../src/router-event.ts","../../src/pipeline-slot-name.ts"],"sourcesContent":["import { ViewPortInstruction, RouteConfig, ViewPort, LifecycleArguments, ViewPortComponent } from './interfaces';\nimport { Router } from './router';\nimport { ActivationStrategyType, InternalActivationStrategy } from './activation-strategy';\n\n/**\n * Initialization options for a navigation instruction\n */\nexport interface NavigationInstructionInit {\n fragment: string;\n queryString?: string;\n params?: Record;\n queryParams?: Record;\n config: RouteConfig;\n parentInstruction?: NavigationInstruction;\n previousInstruction?: NavigationInstruction;\n router: Router;\n options?: Object;\n plan?: Record;\n}\n\nexport interface ViewPortInstructionInit {\n name: string;\n strategy: ActivationStrategyType;\n moduleId: string;\n component: ViewPortComponent;\n}\n\n/**\n * Class used to represent an instruction during a navigation.\n */\nexport class NavigationInstruction {\n /**\n * The URL fragment.\n */\n fragment: string;\n\n /**\n * The query string.\n */\n queryString: string;\n\n /**\n * Parameters extracted from the route pattern.\n */\n params: any;\n\n /**\n * Parameters extracted from the query string.\n */\n queryParams: any;\n\n /**\n * The route config for the route matching this instruction.\n */\n config: RouteConfig;\n\n /**\n * The parent instruction, if this instruction was created by a child router.\n */\n parentInstruction: NavigationInstruction;\n\n parentCatchHandler: any;\n\n /**\n * The instruction being replaced by this instruction in the current router.\n */\n previousInstruction: NavigationInstruction;\n\n /**\n * viewPort instructions to used activation.\n */\n viewPortInstructions: Record;\n\n /**\n * The router instance.\n */\n router: Router;\n\n /**\n * Current built viewport plan of this nav instruction\n */\n plan: Record = null;\n\n options: Record = {};\n\n /**@internal */\n lifecycleArgs: LifecycleArguments;\n /**@internal */\n resolve?: (val?: any) => void;\n\n constructor(init: NavigationInstructionInit) {\n Object.assign(this, init);\n\n this.params = this.params || {};\n this.viewPortInstructions = {};\n\n let ancestorParams = [];\n let current: NavigationInstruction = this;\n do {\n let currentParams = Object.assign({}, current.params);\n if (current.config && current.config.hasChildRouter) {\n // remove the param for the injected child route segment\n delete currentParams[current.getWildCardName()];\n }\n\n ancestorParams.unshift(currentParams);\n current = current.parentInstruction;\n } while (current);\n\n let allParams = Object.assign({}, this.queryParams, ...ancestorParams);\n this.lifecycleArgs = [allParams, this.config, this];\n }\n\n /**\n * Gets an array containing this instruction and all child instructions for the current navigation.\n */\n getAllInstructions(): Array {\n let instructions: NavigationInstruction[] = [this];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let key in viewPortInstructions) {\n let childInstruction = viewPortInstructions[key].childNavigationInstruction;\n if (childInstruction) {\n instructions.push(...childInstruction.getAllInstructions());\n }\n }\n\n return instructions;\n }\n\n /**\n * Gets an array containing the instruction and all child instructions for the previous navigation.\n * Previous instructions are no longer available after navigation completes.\n */\n getAllPreviousInstructions(): Array {\n return this.getAllInstructions().map(c => c.previousInstruction).filter(c => c);\n }\n\n /**\n * Adds a viewPort instruction. Returns the newly created instruction based on parameters\n */\n addViewPortInstruction(initOptions: ViewPortInstructionInit): /*ViewPortInstruction*/ any;\n addViewPortInstruction(viewPortName: string, strategy: ActivationStrategyType, moduleId: string, component: any): /*ViewPortInstruction*/ any;\n addViewPortInstruction(\n nameOrInitOptions: string | ViewPortInstructionInit,\n strategy?: ActivationStrategyType,\n moduleId?: string,\n component?: any\n ): /*ViewPortInstruction*/ any {\n\n let viewPortInstruction: ViewPortInstruction;\n let viewPortName = typeof nameOrInitOptions === 'string' ? nameOrInitOptions : nameOrInitOptions.name;\n const lifecycleArgs = this.lifecycleArgs;\n const config: RouteConfig = Object.assign({}, lifecycleArgs[1], { currentViewPort: viewPortName });\n\n if (typeof nameOrInitOptions === 'string') {\n viewPortInstruction = {\n name: nameOrInitOptions,\n strategy: strategy,\n moduleId: moduleId,\n component: component,\n childRouter: component.childRouter,\n lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] as LifecycleArguments\n };\n } else {\n viewPortInstruction = {\n name: viewPortName,\n strategy: nameOrInitOptions.strategy,\n component: nameOrInitOptions.component,\n moduleId: nameOrInitOptions.moduleId,\n childRouter: nameOrInitOptions.component.childRouter,\n lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] as LifecycleArguments\n };\n }\n\n return this.viewPortInstructions[viewPortName] = viewPortInstruction;\n }\n\n /**\n * Gets the name of the route pattern's wildcard parameter, if applicable.\n */\n getWildCardName(): string {\n // todo: potential issue, or at least unsafe typings\n let configRoute = this.config.route as string;\n let wildcardIndex = configRoute.lastIndexOf('*');\n return configRoute.substr(wildcardIndex + 1);\n }\n\n /**\n * Gets the path and query string created by filling the route\n * pattern's wildcard parameter with the matching param.\n */\n getWildcardPath(): string {\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n let queryString = this.queryString;\n\n if (queryString) {\n path += '?' + queryString;\n }\n\n return path;\n }\n\n /**\n * Gets the instruction's base URL, accounting for wildcard route parameters.\n */\n getBaseUrl(): string {\n let $encodeURI = encodeURI;\n let fragment = decodeURI(this.fragment);\n\n if (fragment === '') {\n let nonEmptyRoute = this.router.routes.find(route => {\n return route.name === this.config.name &&\n route.route !== '';\n });\n if (nonEmptyRoute) {\n fragment = nonEmptyRoute.route as any;\n }\n }\n\n if (!this.params) {\n return $encodeURI(fragment);\n }\n\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n\n if (!path) {\n return $encodeURI(fragment);\n }\n\n return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path)));\n }\n\n /**\n * Finalize a viewport instruction\n * @internal\n */\n _commitChanges(waitToSwap: boolean): Promise {\n let router = this.router;\n router.currentInstruction = this;\n\n const previousInstruction = this.previousInstruction;\n if (previousInstruction) {\n previousInstruction.config.navModel.isActive = false;\n }\n\n this.config.navModel.isActive = true;\n\n router.refreshNavigation();\n\n let loads: Promise[] = [];\n let delaySwaps: ISwapPlan[] = [];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let viewPort = router.viewPorts[viewPortName];\n\n if (!viewPort) {\n throw new Error(`There was no router-view found in the view for ${viewPortInstruction.moduleId}.`);\n }\n\n let childNavInstruction = viewPortInstruction.childNavigationInstruction;\n if (viewPortInstruction.strategy === InternalActivationStrategy.Replace) {\n if (childNavInstruction && childNavInstruction.parentCatchHandler) {\n loads.push(childNavInstruction._commitChanges(waitToSwap));\n } else {\n if (waitToSwap) {\n delaySwaps.push({ viewPort, viewPortInstruction });\n }\n loads.push(\n viewPort\n .process(viewPortInstruction, waitToSwap)\n .then(() => childNavInstruction\n ? childNavInstruction._commitChanges(waitToSwap)\n : Promise.resolve()\n )\n );\n }\n } else {\n if (childNavInstruction) {\n loads.push(childNavInstruction._commitChanges(waitToSwap));\n }\n }\n }\n\n return Promise\n .all(loads)\n .then(() => {\n delaySwaps.forEach(x => x.viewPort.swap(x.viewPortInstruction));\n return null;\n })\n .then(() => prune(this));\n }\n\n /**@internal */\n _updateTitle(): void {\n let router = this.router;\n let title = this._buildTitle(router.titleSeparator);\n if (title) {\n router.history.setTitle(title);\n }\n }\n\n /**@internal */\n _buildTitle(separator: string = ' | '): string {\n let title = '';\n let childTitles = [];\n let navModelTitle = this.config.navModel.title;\n let instructionRouter = this.router;\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n if (navModelTitle) {\n title = instructionRouter.transformTitle(navModelTitle);\n }\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n\n if (child_nav_instruction) {\n let childTitle = child_nav_instruction._buildTitle(separator);\n if (childTitle) {\n childTitles.push(childTitle);\n }\n }\n }\n\n if (childTitles.length) {\n title = childTitles.join(separator) + (title ? separator : '') + title;\n }\n\n if (instructionRouter.title) {\n title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title);\n }\n\n return title;\n }\n}\n\nconst prune = (instruction: NavigationInstruction): void => {\n instruction.previousInstruction = null;\n instruction.plan = null;\n};\n\ninterface ISwapPlan {\n viewPort: ViewPort;\n viewPortInstruction: ViewPortInstruction;\n}\n","import { Router } from './router';\nimport { RouteConfig } from './interfaces';\n\n/**\n* Class for storing and interacting with a route's navigation settings.\n*/\nexport class NavModel {\n\n /**\n * True if this nav item is currently active.\n */\n isActive: boolean = false;\n\n /**\n * The title.\n */\n title: string = null;\n\n /**\n * This nav item's absolute href.\n */\n href: string = null;\n\n /**\n * This nav item's relative href.\n */\n relativeHref: string = null;\n\n /**\n * Data attached to the route at configuration time.\n */\n settings: any = {};\n\n /**\n * The route config.\n */\n config: RouteConfig = null;\n\n /**\n * The router associated with this navigation model.\n */\n router: Router;\n\n order: number | boolean;\n\n constructor(router: Router, relativeHref: string) {\n this.router = router;\n this.relativeHref = relativeHref;\n }\n\n /**\n * Sets the route's title and updates document.title.\n * If the a navigation is in progress, the change will be applied\n * to document.title when the navigation completes.\n *\n * @param title The new title.\n */\n setTitle(title: string): void {\n this.title = title;\n\n if (this.isActive) {\n this.router.updateTitle();\n }\n }\n}\n","import { RouteConfig } from './interfaces';\n\nexport function _normalizeAbsolutePath(path: string, hasPushState: boolean, absolute: boolean = false) {\n if (!hasPushState && path[0] !== '#') {\n path = '#' + path;\n }\n\n if (hasPushState && absolute) {\n path = path.substring(1, path.length);\n }\n\n return path;\n}\n\nexport function _createRootedPath(fragment: string, baseUrl: string, hasPushState: boolean, absolute?: boolean) {\n if (isAbsoluteUrl.test(fragment)) {\n return fragment;\n }\n\n let path = '';\n\n if (baseUrl.length && baseUrl[0] !== '/') {\n path += '/';\n }\n\n path += baseUrl;\n\n if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') {\n path += '/';\n }\n\n if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') {\n path = path.substring(0, path.length - 1);\n }\n\n return _normalizeAbsolutePath(path + fragment, hasPushState, absolute);\n}\n\nexport function _resolveUrl(fragment: string, baseUrl: string, hasPushState?: boolean) {\n if (isRootedPath.test(fragment)) {\n return _normalizeAbsolutePath(fragment, hasPushState);\n }\n\n return _createRootedPath(fragment, baseUrl, hasPushState);\n}\n\nexport function _ensureArrayWithSingleRoutePerConfig(config: RouteConfig) {\n let routeConfigs = [];\n\n if (Array.isArray(config.route)) {\n for (let i = 0, ii = config.route.length; i < ii; ++i) {\n let current = Object.assign({}, config);\n current.route = config.route[i];\n routeConfigs.push(current);\n }\n } else {\n routeConfigs.push(Object.assign({}, config));\n }\n\n return routeConfigs;\n}\n\nconst isRootedPath = /^#?\\//;\nconst isAbsoluteUrl = /^([a-z][a-z0-9+\\-.]*:)?\\/\\//i;\n","import { RouteConfig, PipelineStep, RouteConfigSpecifier } from './interfaces';\nimport { _ensureArrayWithSingleRoutePerConfig } from './util';\nimport { Router } from './router';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * Class used to configure a [[Router]] instance.\n *\n * @constructor\n */\nexport class RouterConfiguration {\n instructions: Array<(router: Router) => void> = [];\n options: {\n [key: string]: any;\n compareQueryParams?: boolean;\n root?: string;\n pushState?: boolean;\n hashChange?: boolean;\n silent?: boolean;\n } = {};\n pipelineSteps: Array<{ name: string, step: Function | PipelineStep }> = [];\n title: string;\n titleSeparator: string;\n unknownRouteConfig: RouteConfigSpecifier;\n viewPortDefaults: Record;\n\n /**@internal */\n _fallbackRoute: string;\n\n /**\n * Adds a step to be run during the [[Router]]'s navigation pipeline.\n *\n * @param name The name of the pipeline slot to insert the step into.\n * @param step The pipeline step.\n * @chainable\n */\n addPipelineStep(name: string, step: Function | PipelineStep): RouterConfiguration {\n if (step === null || step === undefined) {\n throw new Error('Pipeline step cannot be null or undefined.');\n }\n this.pipelineSteps.push({ name, step });\n return this;\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s authorize pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addAuthorizeStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.Authorize, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preActivate pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreActivateStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreActivate, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreRender, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s postRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPostRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PostRender, step);\n }\n\n /**\n * Configures a route that will be used if there is no previous location available on navigation cancellation.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @chainable\n */\n fallbackRoute(fragment: string): RouterConfiguration {\n this._fallbackRoute = fragment;\n return this;\n }\n\n /**\n * Maps one or more routes to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map.\n * @chainable\n */\n map(route: RouteConfig | RouteConfig[]): RouterConfiguration {\n if (Array.isArray(route)) {\n route.forEach(r => this.map(r));\n return this;\n }\n\n return this.mapRoute(route);\n }\n\n /**\n * Configures defaults to use for any view ports.\n *\n * @param viewPortConfig a view port configuration object to use as a\n * default, of the form { viewPortName: { moduleId } }.\n * @chainable\n */\n useViewPortDefaults(viewPortConfig: Record): RouterConfiguration {\n this.viewPortDefaults = viewPortConfig;\n return this;\n }\n\n /**\n * Maps a single route to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map.\n * @chainable\n */\n mapRoute(config: RouteConfig): RouterConfiguration {\n this.instructions.push(router => {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n\n let navModel;\n for (let i = 0, ii = routeConfigs.length; i < ii; ++i) {\n let routeConfig = routeConfigs[i];\n routeConfig.settings = routeConfig.settings || {};\n if (!navModel) {\n navModel = router.createNavModel(routeConfig);\n }\n\n router.addRoute(routeConfig, navModel);\n }\n });\n\n return this;\n }\n\n /**\n * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes.\n *\n * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the\n * [[NavigationInstruction]] and selects a moduleId to load.\n * @chainable\n */\n mapUnknownRoutes(config: RouteConfigSpecifier): RouterConfiguration {\n this.unknownRouteConfig = config;\n return this;\n }\n\n /**\n * Applies the current configuration to the specified [[Router]].\n *\n * @param router The [[Router]] to apply the configuration to.\n */\n exportToRouter(router: Router): void {\n let instructions = this.instructions;\n for (let i = 0, ii = instructions.length; i < ii; ++i) {\n instructions[i](router);\n }\n\n let { title, titleSeparator, unknownRouteConfig, _fallbackRoute, viewPortDefaults } = this;\n\n if (title) {\n router.title = title;\n }\n\n if (titleSeparator) {\n router.titleSeparator = titleSeparator;\n }\n\n if (unknownRouteConfig) {\n router.handleUnknownRoutes(unknownRouteConfig);\n }\n\n if (_fallbackRoute) {\n router.fallbackRoute = _fallbackRoute;\n }\n\n if (viewPortDefaults) {\n router.useViewPortDefaults(viewPortDefaults);\n }\n\n Object.assign(router.options, this.options);\n\n let pipelineSteps = this.pipelineSteps;\n let pipelineStepCount = pipelineSteps.length;\n if (pipelineStepCount) {\n if (!router.isRoot) {\n throw new Error('Pipeline steps can only be added to the root router');\n }\n\n let pipelineProvider = router.pipelineProvider;\n for (let i = 0, ii = pipelineStepCount; i < ii; ++i) {\n let { name, step } = pipelineSteps[i];\n pipelineProvider.addStep(name, step);\n }\n }\n }\n}\n","import { RouteRecognizer, RouteHandler, ConfigurableRoute, State, RecognizedRoute } from 'aurelia-route-recognizer';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { NavigationInstruction, NavigationInstructionInit } from './navigation-instruction';\nimport { NavModel } from './nav-model';\nimport { RouterConfiguration } from './router-configuration';\nimport {\n _ensureArrayWithSingleRoutePerConfig,\n _normalizeAbsolutePath,\n _createRootedPath,\n _resolveUrl\n} from './util';\nimport { RouteConfig, RouteConfigSpecifier, ViewPortInstruction } from './interfaces';\nimport { PipelineProvider } from './pipeline-provider';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface History {\n // This is wrong, as it's an implementation detail from aurelia-history-browser\n // but we are poking it in here so probably will need to make it official in `aurelia-history`\n /**\n * A private flag of Aurelia History implementation to indicate if push state should be used\n */\n _hasPushState: boolean;\n\n previousLocation: string;\n }\n}\n\n/**@internal */\ndeclare module 'aurelia-route-recognizer' {\n interface State {\n types: {\n dynamics: DynamicSegment;\n stars: StarSegment;\n };\n }\n\n interface RouteHandler {\n navigationStrategy?: (instruction: NavigationInstruction) => any;\n }\n\n interface RecognizedRoute {\n config?: RouteConfig;\n queryParams?: Record;\n }\n}\n\ntype RouterConfigurationResolution = RouterConfiguration | ((cfg: RouterConfiguration) => void | RouterConfiguration | Promise);\n\n/**\n * The primary class responsible for handling routing and navigation.\n */\nexport class Router {\n\n /**\n * Container associated with this router. Also used to create child container for creating child router.\n */\n container: Container;\n\n /**\n * History instance of Aurelia abstract class for wrapping platform history global object\n */\n history: History;\n\n /**\n * A registry of registered viewport. Will be used to handle process navigation instruction route loading\n * and dom swapping\n */\n viewPorts: Record;\n\n /**\n * List of route configs registered with this router\n */\n routes: RouteConfig[];\n\n /**\n * The [[Router]]'s current base URL, typically based on the [[Router.currentInstruction]].\n */\n baseUrl: string;\n\n /**\n * If defined, used in generation of document title for [[Router]]'s routes.\n */\n title: string | undefined;\n\n /**\n * The separator used in the document title between [[Router]]'s routes.\n */\n titleSeparator: string | undefined;\n\n /**\n * True if the [[Router]] has been configured.\n */\n isConfigured: boolean;\n\n /**\n * True if the [[Router]] is currently processing a navigation.\n */\n isNavigating: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigate function(s).\n */\n isExplicitNavigation: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigateBack function.\n */\n isExplicitNavigationBack: boolean;\n\n /**\n * True if the [[Router]] is navigating into the app for the first time in the browser session.\n */\n isNavigatingFirst: boolean;\n\n /**\n * True if the [[Router]] is navigating to a page instance not in the browser session history.\n */\n isNavigatingNew: boolean;\n\n /**\n * True if the [[Router]] is navigating forward in the browser session history.\n */\n isNavigatingForward: boolean;\n\n /**\n * True if the [[Router]] is navigating back in the browser session history.\n */\n isNavigatingBack: boolean;\n\n /**\n * True if the [[Router]] is navigating due to a browser refresh.\n */\n isNavigatingRefresh: boolean;\n\n /**\n * True if the previous instruction successfully completed the CanDeactivatePreviousStep in the current navigation.\n */\n couldDeactivate: boolean;\n\n /**\n * The currently active navigation tracker.\n */\n currentNavigationTracker: number;\n\n /**\n * The navigation models for routes that specified [[RouteConfig.nav]].\n */\n navigation: NavModel[];\n\n /**\n * The currently active navigation instruction.\n */\n currentInstruction: NavigationInstruction;\n\n /**\n * The parent router, or null if this instance is not a child router.\n */\n parent: Router = null;\n\n options: any = {};\n\n /**\n * The defaults used when a viewport lacks specified content\n */\n viewPortDefaults: Record = {};\n\n /**@internal */\n catchAllHandler: (instruction: NavigationInstruction) => NavigationInstruction | Promise;\n /**@internal */\n fallbackRoute: string;\n /**@internal */\n pipelineProvider: PipelineProvider;\n /**@internal */\n _fallbackOrder: number;\n /**@internal */\n _recognizer: RouteRecognizer;\n /**@internal */\n _childRecognizer: RouteRecognizer;\n /**@internal */\n _configuredPromise: Promise;\n /**@internal */\n _resolveConfiguredPromise: (value?: any) => void;\n\n /**\n * Extension point to transform the document title before it is built and displayed.\n * By default, child routers delegate to the parent router, and the app router\n * returns the title unchanged.\n */\n transformTitle: (title: string) => string = (title: string) => {\n if (this.parent) {\n return this.parent.transformTitle(title);\n }\n return title;\n }\n\n /**\n * @param container The [[Container]] to use when child routers.\n * @param history The [[History]] implementation to delegate navigation requests to.\n */\n constructor(container: Container, history: History) {\n this.container = container;\n this.history = history;\n this.reset();\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset() {\n this.viewPorts = {};\n this.routes = [];\n this.baseUrl = '';\n this.isConfigured = false;\n this.isNavigating = false;\n this.isExplicitNavigation = false;\n this.isExplicitNavigationBack = false;\n this.isNavigatingFirst = false;\n this.isNavigatingNew = false;\n this.isNavigatingRefresh = false;\n this.isNavigatingForward = false;\n this.isNavigatingBack = false;\n this.couldDeactivate = false;\n this.navigation = [];\n this.currentInstruction = null;\n this.viewPortDefaults = {};\n this._fallbackOrder = 100;\n this._recognizer = new RouteRecognizer();\n this._childRecognizer = new RouteRecognizer();\n this._configuredPromise = new Promise(resolve => {\n this._resolveConfiguredPromise = resolve;\n });\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent.\n */\n get isRoot(): boolean {\n return !this.parent;\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort.\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/any, name?: string): void {\n name = name || 'default';\n this.viewPorts[name] = viewPort;\n }\n\n /**\n * Returns a Promise that resolves when the router is configured.\n */\n ensureConfigured(): Promise {\n return this._configuredPromise;\n }\n\n /**\n * Configures the router.\n *\n * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]].\n */\n configure(callbackOrConfig: RouterConfiguration | ((config: RouterConfiguration) => RouterConfiguration)): Promise {\n this.isConfigured = true;\n\n let result: RouterConfigurationResolution = callbackOrConfig as RouterConfiguration;\n let config: RouterConfiguration;\n if (typeof callbackOrConfig === 'function') {\n config = new RouterConfiguration();\n result = callbackOrConfig(config);\n }\n\n return Promise\n .resolve(result)\n .then((c) => {\n if (c && (c as RouterConfiguration).exportToRouter) {\n config = c;\n }\n\n config.exportToRouter(this);\n this.isConfigured = true;\n this._resolveConfiguredPromise();\n });\n }\n\n /**\n * Navigates to a new location.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n navigate(fragment: string, options?: NavigationOptions): boolean {\n if (!this.isConfigured && this.parent) {\n return this.parent.navigate(fragment, options);\n }\n\n this.isExplicitNavigation = true;\n return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options);\n }\n\n /**\n * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed\n * by [[Router.navigate]].\n *\n * @param route The name of the route to use when generating the navigation location.\n * @param params The route parameters to be used when populating the route pattern.\n * @param options The navigation options.\n */\n navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean {\n let path = this.generate(route, params);\n return this.navigate(path, options);\n }\n\n /**\n * Navigates back to the most recent location in history.\n */\n navigateBack(): void {\n this.isExplicitNavigationBack = true;\n this.history.navigateBack();\n }\n\n /**\n * Creates a child router of the current router.\n *\n * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified.\n * @returns {Router} The new child Router.\n */\n createChild(container?: Container): Router {\n let childRouter = new Router(container || this.container.createChild(), this.history);\n childRouter.parent = this;\n return childRouter;\n }\n\n /**\n * Generates a URL fragment matching the specified route pattern.\n *\n * @param name The name of the route whose pattern should be used to generate the fragment.\n * @param params The route params to be used to populate the route pattern.\n * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url.\n * @returns {string} A string containing the generated URL fragment.\n */\n generate(nameOrRoute: string | RouteConfig, params: any = {}, options: any = {}): string {\n // A child recognizer generates routes for potential child routes. Any potential child route is added\n // to the childRoute property of params for the childRouter to recognize. When generating routes, we\n // use the childRecognizer when childRoute params are available to generate a child router enabled route.\n let recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer;\n let hasRoute = recognizer.hasRoute(nameOrRoute as string | RouteHandler);\n if (!hasRoute) {\n if (this.parent) {\n return this.parent.generate(nameOrRoute, params, options);\n }\n throw new Error(`A route with name '${nameOrRoute}' could not be found. Check that \\`name: '${nameOrRoute}'\\` was specified in the route's config.`);\n }\n let path = recognizer.generate(nameOrRoute as string | RouteHandler, params);\n let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute);\n return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath;\n }\n\n /**\n * Creates a [[NavModel]] for the specified route config.\n *\n * @param config The route config.\n */\n createNavModel(config: RouteConfig): NavModel {\n let navModel = new NavModel(\n this,\n 'href' in config\n ? config.href\n // potential error when config.route is a string[] ?\n : config.route as string);\n navModel.title = config.title;\n navModel.order = config.nav;\n navModel.href = config.href;\n navModel.settings = config.settings;\n navModel.config = config;\n\n return navModel;\n }\n\n /**\n * Registers a new route with the router.\n *\n * @param config The [[RouteConfig]].\n * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes.\n */\n addRoute(config: RouteConfig, navModel?: NavModel): void {\n if (Array.isArray(config.route)) {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n // the following is wrong. todo: fix this after TS refactoring release\n routeConfigs.forEach(this.addRoute.bind(this));\n return;\n }\n\n validateRouteConfig(config);\n\n if (!('viewPorts' in config) && !config.navigationStrategy) {\n config.viewPorts = {\n 'default': {\n moduleId: config.moduleId,\n view: config.view\n }\n };\n }\n\n if (!navModel) {\n navModel = this.createNavModel(config);\n }\n\n this.routes.push(config);\n\n let path = config.route;\n if (path.charAt(0) === '/') {\n path = path.substr(1);\n }\n let caseSensitive = config.caseSensitive === true;\n let state: State = this._recognizer.add({\n path: path,\n handler: config as RouteHandler,\n caseSensitive: caseSensitive\n } as ConfigurableRoute);\n\n if (path) {\n let settings = config.settings;\n delete config.settings;\n let withChild = JSON.parse(JSON.stringify(config));\n config.settings = settings;\n withChild.route = `${path}/*childRoute`;\n withChild.hasChildRouter = true;\n this._childRecognizer.add({\n path: withChild.route,\n handler: withChild,\n caseSensitive: caseSensitive\n });\n\n withChild.navModel = navModel;\n withChild.settings = config.settings;\n withChild.navigationStrategy = config.navigationStrategy;\n }\n\n config.navModel = navModel;\n\n let navigation = this.navigation;\n\n if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) {\n if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) {\n throw new Error('Invalid route config for \"' + config.route + '\" : dynamic routes must specify an \"href:\" to be included in the navigation model.');\n }\n\n if (typeof navModel.order !== 'number') {\n navModel.order = ++this._fallbackOrder;\n }\n\n navigation.push(navModel);\n // this is a potential error / inconsistency between browsers\n //\n // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\n // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other,\n // but sorted with respect to all different elements.\n // Note: the ECMAscript standard does not guarantee this behaviour,\n // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.\n navigation.sort((a, b) => a.order - b.order);\n }\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasRoute(name: string): boolean {\n return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name));\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasOwnRoute(name: string): boolean {\n return this._recognizer.hasRoute(name);\n }\n\n /**\n * Register a handler to use when the incoming URL fragment doesn't match any registered routes.\n *\n * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]].\n */\n handleUnknownRoutes(config?: RouteConfigSpecifier): void {\n if (!config) {\n throw new Error('Invalid unknown route handler');\n }\n\n this.catchAllHandler = instruction => {\n return this\n ._createRouteConfig(config, instruction)\n .then(c => {\n instruction.config = c;\n return instruction;\n });\n };\n }\n\n /**\n * Updates the document title using the current navigation instruction.\n */\n updateTitle(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n return parentRouter.updateTitle();\n }\n\n let currentInstruction = this.currentInstruction;\n if (currentInstruction) {\n currentInstruction._updateTitle();\n }\n return undefined;\n }\n\n /**\n * Updates the navigation routes with hrefs relative to the current location.\n * Note: This method will likely move to a plugin in a future release.\n */\n refreshNavigation(): void {\n let nav = this.navigation;\n\n for (let i = 0, length = nav.length; i < length; i++) {\n let current = nav[i];\n if (!current.config.href) {\n current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState);\n } else {\n current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState);\n }\n }\n }\n\n /**\n * Sets the default configuration for the view ports. This specifies how to\n * populate a view port for which no module is specified. The default is\n * an empty view/view-model pair.\n */\n useViewPortDefaults($viewPortDefaults: Record): void {\n // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction\n let viewPortDefaults: Record = $viewPortDefaults;\n for (let viewPortName in viewPortDefaults) {\n let viewPortConfig = viewPortDefaults[viewPortName];\n this.viewPortDefaults[viewPortName] = {\n moduleId: viewPortConfig.moduleId\n };\n }\n }\n\n /**@internal */\n _refreshBaseUrl(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction);\n }\n }\n\n /**@internal */\n _createNavigationInstruction(url: string = '', parentInstruction: NavigationInstruction = null): Promise {\n let fragment = url;\n let queryString = '';\n\n let queryIndex = url.indexOf('?');\n if (queryIndex !== -1) {\n fragment = url.substr(0, queryIndex);\n queryString = url.substr(queryIndex + 1);\n }\n\n let urlRecognizationResults = this._recognizer.recognize(url) as IRouteRecognizationResults;\n if (!urlRecognizationResults || !urlRecognizationResults.length) {\n urlRecognizationResults = this._childRecognizer.recognize(url) as IRouteRecognizationResults;\n }\n\n let instructionInit: NavigationInstructionInit = {\n fragment,\n queryString,\n config: null,\n parentInstruction,\n previousInstruction: this.currentInstruction,\n router: this,\n options: {\n compareQueryParams: this.options.compareQueryParams\n }\n };\n\n let result: Promise;\n\n if (urlRecognizationResults && urlRecognizationResults.length) {\n let first = urlRecognizationResults[0];\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: first.params,\n queryParams: first.queryParams || urlRecognizationResults.queryParams,\n config: first.config || first.handler\n }));\n\n if (typeof first.handler === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler, first);\n } else if (first.handler && typeof first.handler.navigationStrategy === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler);\n } else {\n result = Promise.resolve(instruction);\n }\n } else if (this.catchAllHandler) {\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n config: null // config will be created by the catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, this.catchAllHandler);\n } else if (this.parent) {\n let router = this._parentCatchAllHandler(this.parent);\n\n if (router) {\n let newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction);\n\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n router: router,\n parentInstruction: newParentInstruction,\n parentCatchHandler: true,\n config: null // config will be created by the chained parent catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, router.catchAllHandler);\n }\n }\n\n if (result && parentInstruction) {\n this.baseUrl = generateBaseUrl(this.parent, parentInstruction);\n }\n\n return result || Promise.reject(new Error(`Route not found: ${url}`));\n }\n\n /**@internal */\n _findParentInstructionFromRouter(router: Router, instruction: NavigationInstruction): NavigationInstruction {\n if (instruction.router === router) {\n instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId\n return instruction;\n } else if (instruction.parentInstruction) {\n return this._findParentInstructionFromRouter(router, instruction.parentInstruction);\n }\n return undefined;\n }\n\n /**@internal */\n _parentCatchAllHandler(router: Router): Router | false {\n if (router.catchAllHandler) {\n return router;\n } else if (router.parent) {\n return this._parentCatchAllHandler(router.parent);\n }\n return false;\n }\n\n /**\n * @internal\n */\n _createRouteConfig(config: RouteConfigSpecifier, instruction: NavigationInstruction): Promise {\n return Promise\n .resolve(config)\n .then((c: any) => {\n if (typeof c === 'string') {\n return { moduleId: c } as RouteConfig;\n } else if (typeof c === 'function') {\n return c(instruction);\n }\n\n return c;\n })\n // typing here could be either RouteConfig or RedirectConfig\n // but temporarily treat both as RouteConfig\n // todo: improve typings precision\n .then((c: string | RouteConfig) => typeof c === 'string' ? { moduleId: c } as RouteConfig : c)\n .then((c: RouteConfig) => {\n c.route = instruction.params.path;\n validateRouteConfig(c);\n\n if (!c.navModel) {\n c.navModel = this.createNavModel(c);\n }\n\n return c;\n });\n }\n}\n\n/* @internal exported for unit testing */\nexport const generateBaseUrl = (router: Router, instruction: NavigationInstruction): string => {\n return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`;\n};\n\n/* @internal exported for unit testing */\nexport const validateRouteConfig = (config: RouteConfig): void => {\n if (typeof config !== 'object') {\n throw new Error('Invalid Route Config');\n }\n\n if (typeof config.route !== 'string') {\n let name = config.name || '(no name)';\n throw new Error('Invalid Route Config for \"' + name + '\": You must specify a \"route:\" pattern.');\n }\n\n if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) {\n throw new Error('Invalid Route Config for \"' + config.route + '\": You must specify a \"moduleId:\", \"redirect:\", \"navigationStrategy:\", or \"viewPorts:\".');\n }\n};\n\n/* @internal exported for unit testing */\nexport const evaluateNavigationStrategy = (\n instruction: NavigationInstruction,\n evaluator: Function,\n context?: any\n): Promise => {\n return Promise\n .resolve(evaluator.call(context, instruction))\n .then(() => {\n if (!('viewPorts' in instruction.config)) {\n instruction.config.viewPorts = {\n 'default': {\n moduleId: instruction.config.moduleId\n }\n };\n }\n\n return instruction;\n });\n};\n\ninterface IRouteRecognizationResults extends Array {\n queryParams: Record;\n}\n","import { PipelineStatus } from './pipeline-status';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Next, StepRunnerFunction, NextCompletionHandler } from './interfaces';\n\n/**@internal exported for unit testing */\nexport const createNextFn = (instruction: NavigationInstruction, steps: StepRunnerFunction[]): Next => {\n let index = -1;\n const next: Next = function() {\n index++;\n\n if (index < steps.length) {\n let currentStep = steps[index];\n\n try {\n return currentStep(instruction, next);\n } catch (e) {\n return next.reject(e);\n }\n } else {\n return next.complete();\n }\n } as Next;\n\n next.complete = createCompletionHandler(next, PipelineStatus.Completed);\n next.cancel = createCompletionHandler(next, PipelineStatus.Canceled);\n next.reject = createCompletionHandler(next, PipelineStatus.Rejected);\n\n return next;\n};\n\n/**@internal exported for unit testing */\nexport const createCompletionHandler = (next: Next, status: PipelineStatus): NextCompletionHandler => {\n return (output: any) => Promise\n .resolve({\n status,\n output,\n completed: status === PipelineStatus.Completed\n });\n};\n","import { PipelineStep, PipelineResult, Next, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { createNextFn } from './next';\n\n/**\n * The class responsible for managing and processing the navigation pipeline.\n */\nexport class Pipeline {\n /**\n * The pipeline steps. And steps added via addStep will be converted to a function\n * The actualy running functions with correct step contexts of this pipeline\n */\n steps: StepRunnerFunction[] = [];\n\n /**\n * Adds a step to the pipeline.\n *\n * @param step The pipeline step.\n */\n addStep(step: StepRunnerFunction | PipelineStep | IPipelineSlot): Pipeline {\n let run;\n\n if (typeof step === 'function') {\n run = step;\n } else if (typeof step.getSteps === 'function') {\n // getSteps is to enable support open slots\n // where devs can add multiple steps into the same slot name\n let steps = step.getSteps();\n for (let i = 0, l = steps.length; i < l; i++) {\n this.addStep(steps[i]);\n }\n\n return this;\n } else {\n run = (step as PipelineStep).run.bind(step);\n }\n\n this.steps.push(run);\n\n return this;\n }\n\n /**\n * Runs the pipeline.\n *\n * @param instruction The navigation instruction to process.\n */\n run(instruction: NavigationInstruction): Promise {\n const nextFn = createNextFn(instruction, this.steps);\n return nextFn();\n }\n}\n","import { NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface NavigationOptions {\n useAppRouter?: boolean;\n }\n}\n\n/**\n* When a navigation command is encountered, the current navigation\n* will be cancelled and control will be passed to the navigation\n* command so it can determine the correct action.\n*/\nexport interface NavigationCommand {\n navigate: (router: Router) => void;\n /**@internal */\n shouldContinueProcessing?: boolean;\n /**@internal */\n setRouter?: (router: Router) => void;\n}\n\n/**\n* Determines if the provided object is a navigation command.\n* A navigation command is anything with a navigate method.\n*\n* @param obj The object to check.\n*/\nexport function isNavigationCommand(obj: any): obj is NavigationCommand {\n return obj && typeof obj.navigate === 'function';\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect.\n*/\nexport class Redirect implements NavigationCommand {\n\n url: string;\n /**@internal */\n options: NavigationOptions;\n /**@internal */\n shouldContinueProcessing: boolean;\n\n private router: Router;\n\n /**\n * @param url The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n constructor(url: string, options: NavigationOptions = {}) {\n this.url = url;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigate(this.url, this.options);\n }\n}\n\n/**\n * Used during the activation lifecycle to cause a redirect to a named route.\n */\nexport class RedirectToRoute implements NavigationCommand {\n\n route: string;\n params: any;\n /**@internal */\n options: NavigationOptions;\n\n /**@internal */\n shouldContinueProcessing: boolean;\n\n /**@internal */\n router: Router;\n\n /**\n * @param route The name of the route.\n * @param params The parameters to be sent to the activation method.\n * @param options The options to use for navigation.\n */\n constructor(route: string, params: any = {}, options: NavigationOptions = {}) {\n this.route = route;\n this.params = params;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigateToRoute(this.route, this.params, this.options);\n }\n}\n","import { ViewPortPlan, ViewPortInstruction, RouteConfig, ViewPort } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { InternalActivationStrategy, ActivationStrategyType } from './activation-strategy';\n\ntype ViewPortPlansRecord = Record;\n\n/**\n * @internal exported for unit testing\n */\nexport function _buildNavigationPlan(\n instruction: NavigationInstruction,\n forceLifecycleMinimum?: boolean\n): Promise {\n let config = instruction.config;\n\n if ('redirect' in config) {\n return buildRedirectPlan(instruction);\n }\n\n const prevInstruction = instruction.previousInstruction;\n const defaultViewPortConfigs = instruction.router.viewPortDefaults;\n\n if (prevInstruction) {\n return buildTransitionPlans(instruction, prevInstruction, defaultViewPortConfigs, forceLifecycleMinimum);\n }\n\n // first navigation, only need to prepare a few information for each viewport plan\n const viewPortPlans: ViewPortPlansRecord = {};\n let viewPortConfigs = config.viewPorts;\n for (let viewPortName in viewPortConfigs) {\n let viewPortConfig = viewPortConfigs[viewPortName];\n if (viewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) {\n viewPortConfig = defaultViewPortConfigs[viewPortName];\n }\n viewPortPlans[viewPortName] = {\n name: viewPortName,\n strategy: InternalActivationStrategy.Replace,\n config: viewPortConfig\n };\n }\n\n return Promise.resolve(viewPortPlans);\n}\n\n/**\n * Build redirect plan based on config of a navigation instruction\n * @internal exported for unit testing\n */\nexport const buildRedirectPlan = (instruction: NavigationInstruction) => {\n const config = instruction.config;\n const router = instruction.router;\n return router\n ._createNavigationInstruction(config.redirect)\n .then(redirectInstruction => {\n\n const params: Record = {};\n const originalInstructionParams = instruction.params;\n const redirectInstructionParams = redirectInstruction.params;\n\n for (let key in redirectInstructionParams) {\n // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this }\n let val = redirectInstructionParams[key];\n if (typeof val === 'string' && val[0] === ':') {\n val = val.slice(1);\n // And if that param is found on the original instruction then use it\n if (val in originalInstructionParams) {\n params[key] = originalInstructionParams[val];\n }\n } else {\n params[key] = redirectInstructionParams[key];\n }\n }\n let redirectLocation = router.generate(redirectInstruction.config, params, instruction.options);\n\n // Special handling for child routes\n for (let key in originalInstructionParams) {\n redirectLocation = redirectLocation.replace(`:${key}`, originalInstructionParams[key]);\n }\n\n let queryString = instruction.queryString;\n if (queryString) {\n redirectLocation += '?' + queryString;\n }\n\n return Promise.resolve(new Redirect(redirectLocation));\n });\n};\n\n/**\n * @param viewPortPlans the Plan record that holds information about built plans\n * @internal exported for unit testing\n */\nexport const buildTransitionPlans = (\n currentInstruction: NavigationInstruction,\n previousInstruction: NavigationInstruction,\n defaultViewPortConfigs: Record,\n forceLifecycleMinimum?: boolean\n): Promise => {\n\n let viewPortPlans: ViewPortPlansRecord = {};\n let newInstructionConfig = currentInstruction.config;\n let hasNewParams = hasDifferentParameterValues(previousInstruction, currentInstruction);\n let pending: Promise[] = [];\n let previousViewPortInstructions = previousInstruction.viewPortInstructions as Record;\n\n for (let viewPortName in previousViewPortInstructions) {\n\n const prevViewPortInstruction = previousViewPortInstructions[viewPortName];\n const prevViewPortComponent = prevViewPortInstruction.component;\n const newInstructionViewPortConfigs = newInstructionConfig.viewPorts as Record;\n\n // if this is invoked on a viewport without any changes, based on new url,\n // newViewPortConfig will be the existing viewport instruction\n let nextViewPortConfig = viewPortName in newInstructionViewPortConfigs\n ? newInstructionViewPortConfigs[viewPortName]\n : prevViewPortInstruction;\n\n if (nextViewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) {\n nextViewPortConfig = defaultViewPortConfigs[viewPortName];\n }\n\n const viewPortActivationStrategy = determineActivationStrategy(\n currentInstruction,\n prevViewPortInstruction,\n nextViewPortConfig,\n hasNewParams,\n forceLifecycleMinimum\n );\n const viewPortPlan = viewPortPlans[viewPortName] = {\n name: viewPortName,\n // ViewPortInstruction can quack like a RouteConfig\n config: nextViewPortConfig as RouteConfig,\n prevComponent: prevViewPortComponent,\n prevModuleId: prevViewPortInstruction.moduleId,\n strategy: viewPortActivationStrategy\n } as ViewPortPlan;\n\n // recursively build nav plans for all existing child routers/viewports of this viewport\n // this is possible because existing child viewports and routers already have necessary information\n // to process the wildcard path from parent instruction\n if (viewPortActivationStrategy !== InternalActivationStrategy.Replace && prevViewPortInstruction.childRouter) {\n const path = currentInstruction.getWildcardPath();\n const task: Promise = prevViewPortInstruction\n .childRouter\n ._createNavigationInstruction(path, currentInstruction)\n .then((childInstruction: NavigationInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(\n childInstruction,\n // is it safe to assume viewPortPlan has not been changed from previous assignment?\n // if so, can just use local variable viewPortPlanStrategy\n // there could be user code modifying viewport plan during _createNavigationInstruction?\n viewPortPlan.strategy === InternalActivationStrategy.InvokeLifecycle\n )\n .then(childPlan => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n // for bluebird ?\n return null;\n });\n });\n\n pending.push(task);\n }\n }\n\n return Promise.all(pending).then(() => viewPortPlans);\n};\n\n/**\n * @param newViewPortConfig if this is invoked on a viewport without any changes, based on new url, newViewPortConfig will be the existing viewport instruction\n * @internal exported for unit testing\n */\nexport const determineActivationStrategy = (\n currentNavInstruction: NavigationInstruction,\n prevViewPortInstruction: ViewPortInstruction,\n newViewPortConfig: RouteConfig | ViewPortInstruction,\n // indicates whether there is difference between old and new url params\n hasNewParams: boolean,\n forceLifecycleMinimum?: boolean\n): ActivationStrategyType => {\n\n let newInstructionConfig = currentNavInstruction.config;\n let prevViewPortViewModel = prevViewPortInstruction.component.viewModel;\n let viewPortPlanStrategy: ActivationStrategyType;\n\n if (prevViewPortInstruction.moduleId !== newViewPortConfig.moduleId) {\n viewPortPlanStrategy = InternalActivationStrategy.Replace;\n } else if ('determineActivationStrategy' in prevViewPortViewModel) {\n viewPortPlanStrategy = prevViewPortViewModel.determineActivationStrategy(...currentNavInstruction.lifecycleArgs);\n } else if (newInstructionConfig.activationStrategy) {\n viewPortPlanStrategy = newInstructionConfig.activationStrategy;\n } else if (hasNewParams || forceLifecycleMinimum) {\n viewPortPlanStrategy = InternalActivationStrategy.InvokeLifecycle;\n } else {\n viewPortPlanStrategy = InternalActivationStrategy.NoChange;\n }\n return viewPortPlanStrategy;\n};\n\n/**@internal exported for unit testing */\nexport const hasDifferentParameterValues = (prev: NavigationInstruction, next: NavigationInstruction): boolean => {\n let prevParams = prev.params;\n let nextParams = next.params;\n let nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null;\n\n for (let key in nextParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n for (let key in prevParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n if (!next.options.compareQueryParams) {\n return false;\n }\n\n let prevQueryParams = prev.queryParams;\n let nextQueryParams = next.queryParams;\n for (let key in nextQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n for (let key in prevQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n return false;\n};\n","import { Next } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { _buildNavigationPlan } from './navigation-plan';\n\n/**\n * Transform a navigation instruction into viewport plan record object,\n * or a redirect request if user viewmodel demands\n */\nexport class BuildNavigationPlanStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return _buildNavigationPlan(navigationInstruction)\n .then(plan => {\n if (plan instanceof Redirect) {\n return next.cancel(plan);\n }\n navigationInstruction.plan = plan;\n return next();\n })\n .catch(next.cancel);\n }\n}\n","import { RouteConfig, ViewPortComponent, ViewPortPlan, ViewPortInstruction } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { _buildNavigationPlan } from './navigation-plan';\nimport { InternalActivationStrategy } from './activation-strategy';\nimport { RouteLoader } from './route-loader';\n\n/**\n * Loading plan calculated based on a navigration-instruction and a viewport plan\n */\ninterface ILoadingPlan {\n viewPortPlan: ViewPortPlan;\n navigationInstruction: NavigationInstruction;\n}\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadNewRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction\n): Promise => {\n let loadingPlans = determineLoadingPlans(navigationInstruction);\n let loadPromises = loadingPlans.map((loadingPlan: ILoadingPlan) => loadRoute(\n routeLoader,\n loadingPlan.navigationInstruction,\n loadingPlan.viewPortPlan\n ));\n\n return Promise.all(loadPromises);\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const determineLoadingPlans = (\n navigationInstruction: NavigationInstruction,\n loadingPlans: ILoadingPlan[] = []\n): ILoadingPlan[] => {\n let viewPortPlans: Record = navigationInstruction.plan;\n\n for (let viewPortName in viewPortPlans) {\n let viewPortPlan = viewPortPlans[viewPortName];\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (viewPortPlan.strategy === InternalActivationStrategy.Replace) {\n loadingPlans.push({ viewPortPlan, navigationInstruction } as ILoadingPlan);\n\n if (childNavInstruction) {\n determineLoadingPlans(childNavInstruction, loadingPlans);\n }\n } else {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction({\n name: viewPortName,\n strategy: viewPortPlan.strategy,\n moduleId: viewPortPlan.prevModuleId,\n component: viewPortPlan.prevComponent\n }) as ViewPortInstruction;\n\n if (childNavInstruction) {\n viewPortInstruction.childNavigationInstruction = childNavInstruction;\n determineLoadingPlans(childNavInstruction, loadingPlans);\n }\n }\n }\n\n return loadingPlans;\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n viewPortPlan: ViewPortPlan\n): Promise => {\n let planConfig = viewPortPlan.config;\n let moduleId = planConfig ? planConfig.moduleId : null;\n\n return loadComponent(routeLoader, navigationInstruction, planConfig)\n .then((component) => {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction({\n name: viewPortPlan.name,\n strategy: viewPortPlan.strategy,\n moduleId: moduleId,\n component: component\n }) as ViewPortInstruction;\n\n let childRouter = component.childRouter;\n if (childRouter) {\n let path = navigationInstruction.getWildcardPath();\n\n return childRouter\n ._createNavigationInstruction(path, navigationInstruction)\n .then((childInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(childInstruction)\n .then((childPlan) => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n viewPortInstruction.childNavigationInstruction = childInstruction;\n\n return loadNewRoute(routeLoader, childInstruction);\n });\n });\n }\n // ts complains without this, though they are same\n return void 0;\n });\n};\n\n/**\n * Load a routed-component based on navigation instruction and route config\n * @internal exported for unit testing only\n */\nexport const loadComponent = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n config: RouteConfig\n): Promise => {\n let router = navigationInstruction.router;\n let lifecycleArgs = navigationInstruction.lifecycleArgs;\n\n return Promise.resolve()\n .then(() => routeLoader.loadRoute(router, config, navigationInstruction))\n .then(\n /**\n * @param component an object carrying information about loaded route\n * typically contains information about view model, childContainer, view and router\n */\n (component: ViewPortComponent) => {\n let { viewModel, childContainer } = component;\n component.router = router;\n component.config = config;\n\n if ('configureRouter' in viewModel) {\n let childRouter = childContainer.getChildRouter();\n component.childRouter = childRouter;\n\n return childRouter\n .configure(c => viewModel.configureRouter(c, childRouter, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]))\n .then(() => component);\n }\n\n return component;\n }\n );\n};\n","import { RouteConfig } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Router } from './router';\n\n/**\n * Abstract class that is responsible for loading view / view model from a route config\n * The default implementation can be found in `aurelia-templating-router`\n */\nexport class RouteLoader {\n /**\n * Load a route config based on its viewmodel / view configuration\n */\n // return typing: return typings used to be never\n // as it was a throw. Changing it to Promise should not cause any issues\n loadRoute(router: Router, config: RouteConfig, navigationInstruction: NavigationInstruction): Promise {\n throw new Error('Route loaders must implement \"loadRoute(router, config, navigationInstruction)\".');\n }\n}\n","import { Next } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { loadNewRoute } from './utilities-route-loading';\nimport { RouteLoader } from './route-loader';\n/**\n * A pipeline step responsible for loading a route config of a navigation instruction\n */\nexport class LoadRouteStep {\n /**@internal */\n static inject() { return [RouteLoader]; }\n /**\n * Route loader isntance that will handle loading route config\n * @internal\n */\n routeLoader: RouteLoader;\n constructor(routeLoader: RouteLoader) {\n this.routeLoader = routeLoader;\n }\n /**\n * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline\n */\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return loadNewRoute(this.routeLoader, navigationInstruction)\n .then(next, next.cancel);\n }\n}\n","import { NavigationInstruction } from './navigation-instruction';\n\n/**\n * A pipeline step for instructing a piepline to commit changes on a navigation instruction\n */\nexport class CommitChangesStep {\n run(navigationInstruction: NavigationInstruction, next: Function): Promise {\n return navigationInstruction\n ._commitChanges(/*wait to swap?*/ true)\n .then(() => {\n navigationInstruction._updateTitle();\n return next();\n });\n }\n}\n","/**\n * An optional interface describing the available activation strategies.\n * @internal Used internally.\n */\nexport const enum InternalActivationStrategy {\n /**\n * Reuse the existing view model, without invoking Router lifecycle hooks.\n */\n NoChange = 'no-change',\n /**\n * Reuse the existing view model, invoking Router lifecycle hooks.\n */\n InvokeLifecycle = 'invoke-lifecycle',\n /**\n * Replace the existing view model, invoking Router lifecycle hooks.\n */\n Replace = 'replace'\n}\n\n/**\n * The strategy to use when activating modules during navigation.\n */\n// kept for compat reason\nexport const activationStrategy: ActivationStrategy = {\n noChange: InternalActivationStrategy.NoChange,\n invokeLifecycle: InternalActivationStrategy.InvokeLifecycle,\n replace: InternalActivationStrategy.Replace\n};\n\n/**\n * An optional interface describing the available activation strategies.\n */\nexport interface ActivationStrategy {\n /**\n * Reuse the existing view model, without invoking Router lifecycle hooks.\n */\n noChange: 'no-change';\n /**\n * Reuse the existing view model, invoking Router lifecycle hooks.\n */\n invokeLifecycle: 'invoke-lifecycle';\n /**\n * Replace the existing view model, invoking Router lifecycle hooks.\n */\n replace: 'replace';\n}\n\n/**\n * Enum like type for activation strategy built-in values\n */\nexport type ActivationStrategyType = ActivationStrategy[keyof ActivationStrategy];\n","import { Next, ViewPortComponent, ViewPortPlan, ViewPortInstruction, LifecycleArguments } from './interfaces';\nimport { isNavigationCommand } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy } from './activation-strategy';\nimport { Router } from './router';\n\n/**\n * Recursively find list of deactivate-able view models\n * and invoke the either 'canDeactivate' or 'deactivate' on each\n * @internal exported for unit testing\n */\nexport const processDeactivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canDeactivate' | 'deactivate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let plan: Record = navigationInstruction.plan;\n let infos = findDeactivatable(plan, callbackName);\n let i = infos.length; // query from inside out\n\n function inspect(val: any): Promise {\n if (ignoreResult || shouldContinue(val)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n if (i--) {\n try {\n let viewModel = infos[i];\n let result = viewModel[callbackName](navigationInstruction);\n return processPotential(result, inspect, next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n navigationInstruction.router.couldDeactivate = true;\n\n return next();\n }\n\n return iterate();\n};\n\n/**\n * Recursively find and returns a list of deactivate-able view models\n * @internal exported for unit testing\n */\nexport const findDeactivatable = (\n plan: Record,\n callbackName: string,\n list: IActivatableInfo[] = []\n): any[] => {\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let prevComponent = viewPortPlan.prevComponent;\n\n if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace)\n && prevComponent\n ) {\n let viewModel = prevComponent.viewModel;\n\n if (callbackName in viewModel) {\n list.push(viewModel);\n }\n }\n\n if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) {\n addPreviousDeactivatable(prevComponent, callbackName, list);\n } else if (viewPortPlan.childNavigationInstruction) {\n findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list);\n }\n }\n\n return list;\n};\n\n/**\n * @internal exported for unit testing\n */\nexport const addPreviousDeactivatable = (\n component: ViewPortComponent,\n callbackName: string,\n list: IActivatableInfo[]\n): void => {\n let childRouter = component.childRouter;\n\n if (childRouter && childRouter.currentInstruction) {\n let viewPortInstructions = childRouter.currentInstruction.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let prevComponent = viewPortInstruction.component;\n let prevViewModel = prevComponent.viewModel;\n\n if (callbackName in prevViewModel) {\n list.push(prevViewModel);\n }\n\n addPreviousDeactivatable(prevComponent, callbackName, list);\n }\n }\n};\n\n/**\n * @internal exported for unit testing\n */\nexport const processActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let infos = findActivatable(navigationInstruction, callbackName);\n let length = infos.length;\n let i = -1; // query from top down\n\n function inspect(val: any, router: Router): Promise {\n if (ignoreResult || shouldContinue(val, router)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n i++;\n\n if (i < length) {\n try {\n let current = infos[i];\n let result = current.viewModel[callbackName](...current.lifecycleArgs);\n return processPotential(result, (val: any) => inspect(val, current.router), next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n return next();\n }\n\n return iterate();\n};\n\ninterface IActivatableInfo {\n viewModel: any;\n lifecycleArgs: LifecycleArguments;\n router: Router;\n}\n\n/**\n * Find list of activatable view model and add to list (3rd parameter)\n * @internal exported for unit testing\n */\nexport const findActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n list: IActivatableInfo[] = [],\n router?: Router\n): IActivatableInfo[] => {\n let plan: Record = navigationInstruction.plan;\n\n Object\n .keys(plan)\n .forEach((viewPortName) => {\n let viewPortPlan = plan[viewPortName];\n let viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName] as ViewPortInstruction;\n let viewPortComponent = viewPortInstruction.component;\n let viewModel = viewPortComponent.viewModel;\n\n if (\n (viewPortPlan.strategy === activationStrategy.invokeLifecycle\n || viewPortPlan.strategy === activationStrategy.replace\n )\n && callbackName in viewModel\n ) {\n list.push({\n viewModel,\n lifecycleArgs: viewPortInstruction.lifecycleArgs,\n router\n });\n }\n\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (childNavInstruction) {\n findActivatable(\n childNavInstruction,\n callbackName,\n list,\n viewPortComponent.childRouter || router\n );\n }\n });\n\n return list;\n};\n\nconst shouldContinue = (output: T, router?: Router): boolean | T => {\n if (output instanceof Error) {\n return false;\n }\n\n if (isNavigationCommand(output)) {\n if (typeof output.setRouter === 'function') {\n output.setRouter(router);\n }\n\n return !!output.shouldContinueProcessing;\n }\n\n if (output === undefined) {\n return true;\n }\n\n return output;\n};\n\n/**\n * A basic interface for an Observable type\n */\nexport interface IObservable {\n subscribe(sub?: IObservableConfig): ISubscription;\n}\n\nexport interface IObservableConfig {\n next(): void;\n error(err?: any): void;\n complete(): void;\n}\n\n/**\n * A basic interface for a Subscription to an Observable\n */\ninterface ISubscription {\n unsubscribe(): void;\n}\n\ntype SafeSubscriptionFunc = (sub: SafeSubscription) => ISubscription;\n\n/**\n * wraps a subscription, allowing unsubscribe calls even if\n * the first value comes synchronously\n */\nclass SafeSubscription {\n\n private _subscribed: boolean;\n private _subscription: ISubscription;\n\n constructor(subscriptionFunc: SafeSubscriptionFunc) {\n this._subscribed = true;\n this._subscription = subscriptionFunc(this);\n\n if (!this._subscribed) {\n this.unsubscribe();\n }\n }\n\n get subscribed(): boolean {\n return this._subscribed;\n }\n\n unsubscribe(): void {\n if (this._subscribed && this._subscription) {\n this._subscription.unsubscribe();\n }\n\n this._subscribed = false;\n }\n}\n\n/**\n * A function to process return value from `activate`/`canActivate` steps\n * Supports observable/promise\n *\n * For observable, resolve at first next() or on complete()\n */\nconst processPotential = (obj: any, resolve: (val?: any) => any, reject: (err?: any) => any): any => {\n // if promise like\n if (obj && typeof obj.then === 'function') {\n return Promise.resolve(obj).then(resolve).catch(reject);\n }\n\n // if observable\n if (obj && typeof obj.subscribe === 'function') {\n let obs: IObservable = obj;\n return new SafeSubscription(sub => obs.subscribe({\n next() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n },\n error(error) {\n if (sub.subscribed) {\n sub.unsubscribe();\n reject(error);\n }\n },\n complete() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n }\n }));\n }\n\n // else just resolve\n try {\n return resolve(obj);\n } catch (error) {\n return reject(error);\n }\n};\n","import { Next } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { processDeactivatable, processActivatable } from './utilities-activation';\n\n/**\n * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route\n */\nexport class CanDeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'canDeactivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route\n */\nexport class CanActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'canActivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route\n */\nexport class DeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'deactivate', next, true);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `activate` on a view model of a route\n */\nexport class ActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'activate', next, true);\n }\n}\n","import { Container } from 'aurelia-dependency-injection';\nimport { Pipeline } from './pipeline';\nimport { BuildNavigationPlanStep } from './step-build-navigation-plan';\nimport { LoadRouteStep } from './step-load-route';\nimport { CommitChangesStep } from './step-commit-changes';\nimport { CanDeactivatePreviousStep, CanActivateNextStep, DeactivatePreviousStep, ActivateNextStep } from './step-activation';\nimport { PipelineStep, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution\n */\nclass PipelineSlot implements IPipelineSlot {\n\n /**@internal */\n container: Container;\n /**@internal */\n slotName: string;\n /**@internal */\n slotAlias?: string;\n\n steps: (Function | PipelineStep)[] = [];\n\n constructor(container: Container, name: string, alias?: string) {\n this.container = container;\n this.slotName = name;\n this.slotAlias = alias;\n }\n\n getSteps(): (StepRunnerFunction | IPipelineSlot | PipelineStep)[] {\n return this.steps.map(x => this.container.get(x));\n }\n}\n\n/**\n * Class responsible for creating the navigation pipeline.\n */\nexport class PipelineProvider {\n\n /**@internal */\n static inject() { return [Container]; }\n /**@internal */\n container: Container;\n /**@internal */\n steps: (Function | PipelineSlot)[];\n\n constructor(container: Container) {\n this.container = container;\n this.steps = [\n BuildNavigationPlanStep,\n CanDeactivatePreviousStep, // optional\n LoadRouteStep,\n createPipelineSlot(container, PipelineSlotName.Authorize),\n CanActivateNextStep, // optional\n createPipelineSlot(container, PipelineSlotName.PreActivate, 'modelbind'),\n // NOTE: app state changes start below - point of no return\n DeactivatePreviousStep, // optional\n ActivateNextStep, // optional\n createPipelineSlot(container, PipelineSlotName.PreRender, 'precommit'),\n CommitChangesStep,\n createPipelineSlot(container, PipelineSlotName.PostRender, 'postcomplete')\n ];\n }\n\n /**\n * Create the navigation pipeline.\n */\n createPipeline(useCanDeactivateStep: boolean = true): Pipeline {\n let pipeline = new Pipeline();\n this.steps.forEach(step => {\n if (useCanDeactivateStep || step !== CanDeactivatePreviousStep) {\n pipeline.addStep(this.container.get(step));\n }\n });\n return pipeline;\n }\n\n /**@internal */\n _findStep(name: string): PipelineSlot {\n // Steps that are not PipelineSlots are constructor functions, and they will automatically fail. Probably.\n return this.steps.find(x => (x as PipelineSlot).slotName === name || (x as PipelineSlot).slotAlias === name) as PipelineSlot;\n }\n\n /**\n * Adds a step into the pipeline at a known slot location.\n */\n addStep(name: string, step: PipelineStep | Function): void {\n let found = this._findStep(name);\n if (found) {\n let slotSteps = found.steps;\n // prevent duplicates\n if (!slotSteps.includes(step)) {\n slotSteps.push(step);\n }\n } else {\n throw new Error(`Invalid pipeline slot name: ${name}.`);\n }\n }\n\n /**\n * Removes a step from a slot in the pipeline\n */\n removeStep(name: string, step: PipelineStep): void {\n let slot = this._findStep(name);\n if (slot) {\n let slotSteps = slot.steps;\n slotSteps.splice(slotSteps.indexOf(step), 1);\n }\n }\n\n /**\n * Clears all steps from a slot in the pipeline\n * @internal\n */\n _clearSteps(name: string = ''): void {\n let slot = this._findStep(name);\n if (slot) {\n slot.steps = [];\n }\n }\n\n /**\n * Resets all pipeline slots\n */\n reset(): void {\n this._clearSteps(PipelineSlotName.Authorize);\n this._clearSteps(PipelineSlotName.PreActivate);\n this._clearSteps(PipelineSlotName.PreRender);\n this._clearSteps(PipelineSlotName.PostRender);\n }\n}\n\n/**@internal */\nconst createPipelineSlot = (container: Container, name: PipelineSlotName, alias?: string): PipelineSlot => {\n return new PipelineSlot(container, name, alias);\n};\n","import * as LogManager from 'aurelia-logging';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\nimport { PipelineProvider } from './pipeline-provider';\nimport { isNavigationCommand } from './navigation-commands';\nimport { EventAggregator } from 'aurelia-event-aggregator';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { ViewPort, ConfiguresRouter, PipelineResult } from './interfaces';\nimport { RouterEvent } from './router-event';\n\n/**@internal */\ndeclare module 'aurelia-dependency-injection' {\n interface Container {\n viewModel?: any;\n }\n}\n\nconst logger = LogManager.getLogger('app-router');\n\n/**\n * The main application router.\n */\nexport class AppRouter extends Router {\n\n /**@internal */\n static inject() { return [Container, History, PipelineProvider, EventAggregator]; }\n\n events: EventAggregator;\n /**@internal */\n maxInstructionCount: number;\n /**@internal */\n _queue: NavigationInstruction[];\n /**@internal */\n isActive: boolean;\n\n constructor(container: Container, history: History, pipelineProvider: PipelineProvider, events: EventAggregator) {\n super(container, history); // Note the super will call reset internally.\n this.pipelineProvider = pipelineProvider;\n this.events = events;\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset(): void {\n super.reset();\n this.maxInstructionCount = 10;\n if (!this._queue) {\n this._queue = [];\n } else {\n this._queue.length = 0;\n }\n }\n\n /**\n * Loads the specified URL.\n *\n * @param url The URL fragment to load.\n */\n loadUrl(url: string): Promise {\n return this\n ._createNavigationInstruction(url)\n .then(instruction => this._queueInstruction(instruction))\n .catch(error => {\n logger.error(error);\n restorePreviousLocation(this);\n });\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort. This is typically a element in Aurelia default impl\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/ any, name?: string): Promise {\n // having strong typing without changing public API\n const $viewPort: ViewPort = viewPort;\n super.registerViewPort($viewPort, name);\n\n // beside adding viewport to the registry of this instance\n // AppRouter also configure routing/history to start routing functionality\n // There are situation where there are more than 1 element at root view\n // in that case, still only activate once via the following guard\n if (!this.isActive) {\n const viewModel = this._findViewModel($viewPort);\n if ('configureRouter' in viewModel) {\n // If there are more than one element at root view\n // use this flag to guard against configure method being invoked multiple times\n // this flag is set inside method configure\n if (!this.isConfigured) {\n // replace the real resolve with a noop to guarantee that any action in base class Router\n // won't resolve the configurePromise prematurely\n const resolveConfiguredPromise = this._resolveConfiguredPromise;\n this._resolveConfiguredPromise = () => {/**/};\n return this\n .configure(config => {\n viewModel.configureRouter(config, this);\n return config;\n })\n .then(() => {\n this.activate();\n resolveConfiguredPromise();\n });\n }\n } else {\n this.activate();\n }\n }\n // when a viewport is added dynamically to a root view that is already activated\n // just process the navigation instruction\n else {\n this._dequeueInstruction();\n }\n\n return Promise.resolve();\n }\n\n /**\n * Activates the router. This instructs the router to begin listening for history changes and processing instructions.\n *\n * @params options The set of options to activate the router with.\n */\n activate(options?: NavigationOptions): void {\n if (this.isActive) {\n return;\n }\n\n this.isActive = true;\n // route handler property is responsible for handling url change\n // the interface of aurelia-history isn't clear on this perspective\n this.options = Object.assign({ routeHandler: this.loadUrl.bind(this) }, this.options, options);\n this.history.activate(this.options);\n this._dequeueInstruction();\n }\n\n /**\n * Deactivates the router.\n */\n deactivate(): void {\n this.isActive = false;\n this.history.deactivate();\n }\n\n /**@internal */\n _queueInstruction(instruction: NavigationInstruction): Promise {\n return new Promise((resolve) => {\n instruction.resolve = resolve;\n this._queue.unshift(instruction);\n this._dequeueInstruction();\n });\n }\n\n /**@internal */\n _dequeueInstruction(instructionCount: number = 0): Promise {\n return Promise.resolve().then(() => {\n if (this.isNavigating && !instructionCount) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n let instruction = this._queue.shift();\n this._queue.length = 0;\n\n if (!instruction) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n this.isNavigating = true;\n\n let navtracker: number = this.history.getState('NavigationTracker');\n let currentNavTracker = this.currentNavigationTracker;\n\n if (!navtracker && !currentNavTracker) {\n this.isNavigatingFirst = true;\n this.isNavigatingNew = true;\n } else if (!navtracker) {\n this.isNavigatingNew = true;\n } else if (!currentNavTracker) {\n this.isNavigatingRefresh = true;\n } else if (currentNavTracker < navtracker) {\n this.isNavigatingForward = true;\n } else if (currentNavTracker > navtracker) {\n this.isNavigatingBack = true;\n } if (!navtracker) {\n navtracker = Date.now();\n this.history.setState('NavigationTracker', navtracker);\n }\n this.currentNavigationTracker = navtracker;\n\n instruction.previousInstruction = this.currentInstruction;\n\n let maxInstructionCount = this.maxInstructionCount;\n\n if (!instructionCount) {\n this.events.publish(RouterEvent.Processing, { instruction });\n } else if (instructionCount === maxInstructionCount - 1) {\n logger.error(`${instructionCount + 1} navigation instructions have been attempted without success. Restoring last known good location.`);\n restorePreviousLocation(this);\n return this._dequeueInstruction(instructionCount + 1);\n } else if (instructionCount > maxInstructionCount) {\n throw new Error('Maximum navigation attempts exceeded. Giving up.');\n }\n\n let pipeline = this.pipelineProvider.createPipeline(!this.couldDeactivate);\n\n return pipeline\n .run(instruction)\n .then(result => processResult(instruction, result, instructionCount, this))\n .catch(error => {\n return { output: error instanceof Error ? error : new Error(error) } as PipelineResult;\n })\n .then(result => resolveInstruction(instruction, result, !!instructionCount, this));\n });\n }\n\n /**@internal */\n _findViewModel(viewPort: ViewPort): ConfiguresRouter | undefined {\n if (this.container.viewModel) {\n return this.container.viewModel;\n }\n\n if (viewPort.container) {\n let container = viewPort.container;\n\n while (container) {\n if (container.viewModel) {\n this.container.viewModel = container.viewModel;\n return container.viewModel;\n }\n\n container = container.parent;\n }\n }\n\n return undefined;\n }\n}\n\nconst processResult = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n instructionCount: number,\n router: AppRouter\n): Promise => {\n if (!(result && 'completed' in result && 'output' in result)) {\n result = result || {} as PipelineResult;\n result.output = new Error(`Expected router pipeline to return a navigation result, but got [${JSON.stringify(result)}] instead.`);\n }\n\n let finalResult: PipelineResult = null;\n let navigationCommandResult = null;\n if (isNavigationCommand(result.output)) {\n navigationCommandResult = result.output.navigate(router);\n } else {\n finalResult = result;\n\n if (!result.completed) {\n if (result.output instanceof Error) {\n logger.error(result.output.toString());\n }\n\n restorePreviousLocation(router);\n }\n }\n\n return Promise.resolve(navigationCommandResult)\n .then(_ => router._dequeueInstruction(instructionCount + 1))\n .then(innerResult => finalResult || innerResult || result);\n};\n\nconst resolveInstruction = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n isInnerInstruction: boolean,\n router: AppRouter\n): PipelineResult => {\n instruction.resolve(result);\n\n let eventAggregator = router.events;\n let eventArgs = { instruction, result };\n if (!isInnerInstruction) {\n router.isNavigating = false;\n router.isExplicitNavigation = false;\n router.isExplicitNavigationBack = false;\n router.isNavigatingFirst = false;\n router.isNavigatingNew = false;\n router.isNavigatingRefresh = false;\n router.isNavigatingForward = false;\n router.isNavigatingBack = false;\n router.couldDeactivate = false;\n\n let eventName: string;\n\n if (result.output instanceof Error) {\n eventName = RouterEvent.Error;\n } else if (!result.completed) {\n eventName = RouterEvent.Canceled;\n } else {\n let queryString = instruction.queryString ? ('?' + instruction.queryString) : '';\n router.history.previousLocation = instruction.fragment + queryString;\n eventName = RouterEvent.Success;\n }\n\n eventAggregator.publish(eventName, eventArgs);\n eventAggregator.publish(RouterEvent.Complete, eventArgs);\n } else {\n eventAggregator.publish(RouterEvent.ChildComplete, eventArgs);\n }\n\n return result;\n};\n\nconst restorePreviousLocation = (router: AppRouter): void => {\n let previousLocation = router.history.previousLocation;\n if (previousLocation) {\n router.navigate(previousLocation, { trigger: false, replace: true });\n } else if (router.fallbackRoute) {\n router.navigate(router.fallbackRoute, { trigger: true, replace: true });\n } else {\n logger.error('Router navigation failed, and no previous location or fallbackRoute could be restored.');\n }\n};\n","/**\n* The status of a Pipeline.\n*/\nexport const enum PipelineStatus {\n Completed = 'completed',\n Canceled = 'canceled',\n Rejected = 'rejected',\n Running = 'running'\n}\n","/**\n * A list of known router events used by the Aurelia router\n * to signal the pipeline has come to a certain state\n */\n// const enum is preserved in tsconfig\nexport const enum RouterEvent {\n Processing = 'router:navigation:processing',\n Error = 'router:navigation:error',\n Canceled = 'router:navigation:canceled',\n Complete = 'router:navigation:complete',\n Success = 'router:navigation:success',\n ChildComplete = 'router:navigation:child:complete'\n}\n","/**\n * Available pipeline slot names to insert interceptor into router pipeline\n */\n// const enum is preserved in tsconfig\nexport const enum PipelineSlotName {\n /**\n * Authorization slot. Invoked early in the pipeline,\n * before `canActivate` hook of incoming route\n */\n Authorize = 'authorize',\n /**\n * Pre-activation slot. Invoked early in the pipeline,\n * Invoked timing:\n * - after Authorization slot\n * - after canActivate hook on new view model\n * - before deactivate hook on old view model\n * - before activate hook on new view model\n */\n PreActivate = 'preActivate',\n /**\n * Pre-render slot. Invoked later in the pipeline\n * Invokcation timing:\n * - after activate hook on new view model\n * - before commit step on new navigation instruction\n */\n PreRender = 'preRender',\n /**\n * Post-render slot. Invoked last in the pipeline\n */\n PostRender = 'postRender'\n}\n"],"names":["RouteRecognizer","Container","LogManager.getLogger","tslib_1.__extends","History","EventAggregator","PipelineStatus","RouterEvent","PipelineSlotName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2BA;;;AAGA;QA4DE,+BAAY,IAA+B;;;;YAT3C,SAAI,GAAwC,IAAI,CAAC;YAEjD,YAAO,GAAwB,EAAE,CAAC;YAQhC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAE1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;YAChC,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;YAE/B,IAAI,cAAc,GAAG,EAAE,CAAC;YACxB,IAAI,OAAO,GAA0B,IAAI,CAAC;YAC1C,GAAG;gBACD,IAAI,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;gBACtD,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE;;oBAEnD,OAAO,aAAa,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;iBACjD;gBAED,cAAc,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;gBACtC,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC;aACrC,QAAQ,OAAO,EAAE;YAElB,IAAI,SAAS,GAA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AAC,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;SACzE;aAAM;YACL,MAAM,CAAC,KAAK,CAAC,wFAAwF,CAAC,CAAC;SACxG;IACH,CAAC,CAAC;;ICrUF;;;AAGA,IAAA,WAAkB,cAAc;QAC9B,yCAAuB,CAAA;QACvB,uCAAqB,CAAA;QACrB,uCAAqB,CAAA;QACrB,qCAAmB,CAAA;IACrB,CAAC,EALiBC,sBAAc,KAAdA,sBAAc,QAK/B;;ICRD;;;;AAIA,IACA,WAAkB,WAAW;QAC3B,0DAA2C,CAAA;QAC3C,gDAAiC,CAAA;QACjC,sDAAuC,CAAA;QACvC,sDAAuC,CAAA;QACvC,oDAAqC,CAAA;QACrC,iEAAkD,CAAA;IACpD,CAAC,EAPiBC,mBAAW,KAAXA,mBAAW,QAO5B;;ICZD;;;AAGA,IACA,WAAkB,gBAAgB;;;;;QAKhC,2CAAuB,CAAA;;;;;;;;;QASvB,+CAA2B,CAAA;;;;;;;QAO3B,2CAAuB,CAAA;;;;QAIvB,6CAAyB,CAAA;IAC3B,CAAC,EA1BiBC,wBAAgB,KAAhBA,wBAAgB,QA0BjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/aurelia-router.d.ts b/dist/aurelia-router.d.ts index bb80e863..4b192ce4 100644 --- a/dist/aurelia-router.d.ts +++ b/dist/aurelia-router.d.ts @@ -69,54 +69,54 @@ export declare class RouterConfiguration { unknownRouteConfig: RouteConfigSpecifier; viewPortDefaults: Record; /** - * Adds a step to be run during the [[Router]]'s navigation pipeline. - * - * @param name The name of the pipeline slot to insert the step into. - * @param step The pipeline step. - * @chainable - */ + * Adds a step to be run during the [[Router]]'s navigation pipeline. + * + * @param name The name of the pipeline slot to insert the step into. + * @param step The pipeline step. + * @chainable + */ addPipelineStep(name: string, step: Function | PipelineStep): RouterConfiguration; /** - * Adds a step to be run during the [[Router]]'s authorize pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ + * Adds a step to be run during the [[Router]]'s authorize pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ addAuthorizeStep(step: Function | PipelineStep): RouterConfiguration; /** - * Adds a step to be run during the [[Router]]'s preActivate pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ + * Adds a step to be run during the [[Router]]'s preActivate pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ addPreActivateStep(step: Function | PipelineStep): RouterConfiguration; /** - * Adds a step to be run during the [[Router]]'s preRender pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ + * Adds a step to be run during the [[Router]]'s preRender pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ addPreRenderStep(step: Function | PipelineStep): RouterConfiguration; /** - * Adds a step to be run during the [[Router]]'s postRender pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ + * Adds a step to be run during the [[Router]]'s postRender pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ addPostRenderStep(step: Function | PipelineStep): RouterConfiguration; /** - * Configures a route that will be used if there is no previous location available on navigation cancellation. - * - * @param fragment The URL fragment to use as the navigation destination. - * @chainable - */ + * Configures a route that will be used if there is no previous location available on navigation cancellation. + * + * @param fragment The URL fragment to use as the navigation destination. + * @chainable + */ fallbackRoute(fragment: string): RouterConfiguration; /** - * Maps one or more routes to be registered with the router. - * - * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map. - * @chainable - */ + * Maps one or more routes to be registered with the router. + * + * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map. + * @chainable + */ map(route: RouteConfig | RouteConfig[]): RouterConfiguration; /** * Configures defaults to use for any view ports. @@ -130,25 +130,25 @@ export declare class RouterConfiguration { moduleId: string; }>): RouterConfiguration; /** - * Maps a single route to be registered with the router. - * - * @param route The [[RouteConfig]] to map. - * @chainable - */ + * Maps a single route to be registered with the router. + * + * @param route The [[RouteConfig]] to map. + * @chainable + */ mapRoute(config: RouteConfig): RouterConfiguration; /** - * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes. - * - * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the - * [[NavigationInstruction]] and selects a moduleId to load. - * @chainable - */ + * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes. + * + * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the + * [[NavigationInstruction]] and selects a moduleId to load. + * @chainable + */ mapUnknownRoutes(config: RouteConfigSpecifier): RouterConfiguration; /** - * Applies the current configuration to the specified [[Router]]. - * - * @param router The [[Router]] to apply the configuration to. - */ + * Applies the current configuration to the specified [[Router]]. + * + * @param router The [[Router]] to apply the configuration to. + */ exportToRouter(router: Router): void; } /** @@ -185,122 +185,122 @@ export declare class Router { */ titleSeparator: string | undefined; /** - * True if the [[Router]] has been configured. - */ + * True if the [[Router]] has been configured. + */ isConfigured: boolean; /** - * True if the [[Router]] is currently processing a navigation. - */ + * True if the [[Router]] is currently processing a navigation. + */ isNavigating: boolean; /** - * True if the [[Router]] is navigating due to explicit call to navigate function(s). - */ + * True if the [[Router]] is navigating due to explicit call to navigate function(s). + */ isExplicitNavigation: boolean; /** - * True if the [[Router]] is navigating due to explicit call to navigateBack function. - */ + * True if the [[Router]] is navigating due to explicit call to navigateBack function. + */ isExplicitNavigationBack: boolean; /** - * True if the [[Router]] is navigating into the app for the first time in the browser session. - */ + * True if the [[Router]] is navigating into the app for the first time in the browser session. + */ isNavigatingFirst: boolean; /** - * True if the [[Router]] is navigating to a page instance not in the browser session history. - */ + * True if the [[Router]] is navigating to a page instance not in the browser session history. + */ isNavigatingNew: boolean; /** - * True if the [[Router]] is navigating forward in the browser session history. - */ + * True if the [[Router]] is navigating forward in the browser session history. + */ isNavigatingForward: boolean; /** - * True if the [[Router]] is navigating back in the browser session history. - */ + * True if the [[Router]] is navigating back in the browser session history. + */ isNavigatingBack: boolean; /** - * True if the [[Router]] is navigating due to a browser refresh. - */ + * True if the [[Router]] is navigating due to a browser refresh. + */ isNavigatingRefresh: boolean; /** - * True if the previous instruction successfully completed the CanDeactivatePreviousStep in the current navigation. - */ + * True if the previous instruction successfully completed the CanDeactivatePreviousStep in the current navigation. + */ couldDeactivate: boolean; /** - * The currently active navigation tracker. - */ + * The currently active navigation tracker. + */ currentNavigationTracker: number; /** - * The navigation models for routes that specified [[RouteConfig.nav]]. - */ + * The navigation models for routes that specified [[RouteConfig.nav]]. + */ navigation: NavModel[]; /** - * The currently active navigation instruction. - */ + * The currently active navigation instruction. + */ currentInstruction: NavigationInstruction; /** - * The parent router, or null if this instance is not a child router. - */ + * The parent router, or null if this instance is not a child router. + */ parent: Router; options: any; /** - * The defaults used when a viewport lacks specified content - */ + * The defaults used when a viewport lacks specified content + */ viewPortDefaults: Record; /** - * Extension point to transform the document title before it is built and displayed. - * By default, child routers delegate to the parent router, and the app router - * returns the title unchanged. - */ + * Extension point to transform the document title before it is built and displayed. + * By default, child routers delegate to the parent router, and the app router + * returns the title unchanged. + */ transformTitle: (title: string) => string; /** - * @param container The [[Container]] to use when child routers. - * @param history The [[History]] implementation to delegate navigation requests to. - */ + * @param container The [[Container]] to use when child routers. + * @param history The [[History]] implementation to delegate navigation requests to. + */ constructor(container: Container, history: History); /** - * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. - * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. - */ + * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. + * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. + */ reset(): void; /** - * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent. - */ + * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent. + */ readonly isRoot: boolean; /** - * Registers a viewPort to be used as a rendering target for activated routes. - * - * @param viewPort The viewPort. - * @param name The name of the viewPort. 'default' if unspecified. - */ + * Registers a viewPort to be used as a rendering target for activated routes. + * + * @param viewPort The viewPort. + * @param name The name of the viewPort. 'default' if unspecified. + */ registerViewPort(viewPort: any, name?: string): void; /** - * Returns a Promise that resolves when the router is configured. - */ + * Returns a Promise that resolves when the router is configured. + */ ensureConfigured(): Promise; /** - * Configures the router. - * - * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]]. - */ + * Configures the router. + * + * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]]. + */ configure(callbackOrConfig: RouterConfiguration | ((config: RouterConfiguration) => RouterConfiguration)): Promise; /** - * Navigates to a new location. - * - * @param fragment The URL fragment to use as the navigation destination. - * @param options The navigation options. - */ + * Navigates to a new location. + * + * @param fragment The URL fragment to use as the navigation destination. + * @param options The navigation options. + */ navigate(fragment: string, options?: NavigationOptions): boolean; /** - * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed - * by [[Router.navigate]]. - * - * @param route The name of the route to use when generating the navigation location. - * @param params The route parameters to be used when populating the route pattern. - * @param options The navigation options. - */ + * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed + * by [[Router.navigate]]. + * + * @param route The name of the route to use when generating the navigation location. + * @param params The route parameters to be used when populating the route pattern. + * @param options The navigation options. + */ navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean; /** - * Navigates back to the most recent location in history. - */ + * Navigates back to the most recent location in history. + */ navigateBack(): void; /** * Creates a child router of the current router. @@ -310,53 +310,53 @@ export declare class Router { */ createChild(container?: Container): Router; /** - * Generates a URL fragment matching the specified route pattern. - * - * @param name The name of the route whose pattern should be used to generate the fragment. - * @param params The route params to be used to populate the route pattern. - * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url. - * @returns {string} A string containing the generated URL fragment. - */ + * Generates a URL fragment matching the specified route pattern. + * + * @param name The name of the route whose pattern should be used to generate the fragment. + * @param params The route params to be used to populate the route pattern. + * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url. + * @returns {string} A string containing the generated URL fragment. + */ generate(nameOrRoute: string | RouteConfig, params?: any, options?: any): string; /** - * Creates a [[NavModel]] for the specified route config. - * - * @param config The route config. - */ + * Creates a [[NavModel]] for the specified route config. + * + * @param config The route config. + */ createNavModel(config: RouteConfig): NavModel; /** - * Registers a new route with the router. - * - * @param config The [[RouteConfig]]. - * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes. - */ + * Registers a new route with the router. + * + * @param config The [[RouteConfig]]. + * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes. + */ addRoute(config: RouteConfig, navModel?: NavModel): void; /** - * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name. - * - * @param name The name of the route to check. - */ + * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name. + * + * @param name The name of the route to check. + */ hasRoute(name: string): boolean; /** - * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name. - * - * @param name The name of the route to check. - */ + * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name. + * + * @param name The name of the route to check. + */ hasOwnRoute(name: string): boolean; /** - * Register a handler to use when the incoming URL fragment doesn't match any registered routes. - * - * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]]. - */ + * Register a handler to use when the incoming URL fragment doesn't match any registered routes. + * + * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]]. + */ handleUnknownRoutes(config?: RouteConfigSpecifier): void; /** - * Updates the document title using the current navigation instruction. - */ + * Updates the document title using the current navigation instruction. + */ updateTitle(): void; /** - * Updates the navigation routes with hrefs relative to the current location. - * Note: This method will likely move to a plugin in a future release. - */ + * Updates the navigation routes with hrefs relative to the current location. + * Note: This method will likely move to a plugin in a future release. + */ refreshNavigation(): void; /** * Sets the default configuration for the view ports. This specifies how to @@ -365,6 +365,31 @@ export declare class Router { */ useViewPortDefaults($viewPortDefaults: Record): void; } +/** + * The strategy to use when activating modules during navigation. + */ +export declare const activationStrategy: ActivationStrategy; +/** + * An optional interface describing the available activation strategies. + */ +export interface ActivationStrategy { + /** + * Reuse the existing view model, without invoking Router lifecycle hooks. + */ + noChange: 'no-change'; + /** + * Reuse the existing view model, invoking Router lifecycle hooks. + */ + invokeLifecycle: 'invoke-lifecycle'; + /** + * Replace the existing view model, invoking Router lifecycle hooks. + */ + replace: 'replace'; +} +/** + * Enum like type for activation strategy built-in values + */ +export declare type ActivationStrategyType = ActivationStrategy[keyof ActivationStrategy]; /** * Initialization options for a navigation instruction */ @@ -380,52 +405,52 @@ export interface NavigationInstructionInit { options?: Object; plan?: Record; } -/** - * A pipeline step for instructing a piepline to commit changes on a navigation instruction - */ -export declare class CommitChangesStep { - run(navigationInstruction: NavigationInstruction, next: Function): Promise; +export interface ViewPortInstructionInit { + name: string; + strategy: ActivationStrategyType; + moduleId: string; + component: ViewPortComponent; } /** -* Class used to represent an instruction during a navigation. -*/ + * Class used to represent an instruction during a navigation. + */ export declare class NavigationInstruction { /** - * The URL fragment. - */ + * The URL fragment. + */ fragment: string; /** - * The query string. - */ + * The query string. + */ queryString: string; /** - * Parameters extracted from the route pattern. - */ + * Parameters extracted from the route pattern. + */ params: any; /** - * Parameters extracted from the query string. - */ + * Parameters extracted from the query string. + */ queryParams: any; /** - * The route config for the route matching this instruction. - */ + * The route config for the route matching this instruction. + */ config: RouteConfig; /** - * The parent instruction, if this instruction was created by a child router. - */ + * The parent instruction, if this instruction was created by a child router. + */ parentInstruction: NavigationInstruction; parentCatchHandler: any; /** - * The instruction being replaced by this instruction in the current router. - */ + * The instruction being replaced by this instruction in the current router. + */ previousInstruction: NavigationInstruction; /** - * viewPort instructions to used activation. - */ + * viewPort instructions to used activation. + */ viewPortInstructions: Record; /** - * The router instance. - */ + * The router instance. + */ router: Router; /** * Current built viewport plan of this nav instruction @@ -434,30 +459,31 @@ export declare class NavigationInstruction { options: Record; constructor(init: NavigationInstructionInit); /** - * Gets an array containing this instruction and all child instructions for the current navigation. - */ + * Gets an array containing this instruction and all child instructions for the current navigation. + */ getAllInstructions(): Array; /** - * Gets an array containing the instruction and all child instructions for the previous navigation. - * Previous instructions are no longer available after navigation completes. - */ + * Gets an array containing the instruction and all child instructions for the previous navigation. + * Previous instructions are no longer available after navigation completes. + */ getAllPreviousInstructions(): Array; /** - * Adds a viewPort instruction. Returns the newly created instruction based on parameters - */ - addViewPortInstruction(name: string, strategy: ActivationStrategyType, moduleId: string, component: any): any; + * Adds a viewPort instruction. Returns the newly created instruction based on parameters + */ + addViewPortInstruction(initOptions: ViewPortInstructionInit): any; + addViewPortInstruction(viewPortName: string, strategy: ActivationStrategyType, moduleId: string, component: any): any; /** - * Gets the name of the route pattern's wildcard parameter, if applicable. - */ + * Gets the name of the route pattern's wildcard parameter, if applicable. + */ getWildCardName(): string; /** - * Gets the path and query string created by filling the route - * pattern's wildcard parameter with the matching param. - */ + * Gets the path and query string created by filling the route + * pattern's wildcard parameter with the matching param. + */ getWildcardPath(): string; /** - * Gets the instruction's base URL, accounting for wildcard route parameters. - */ + * Gets the instruction's base URL, accounting for wildcard route parameters. + */ getBaseUrl(): string; } /** @@ -487,21 +513,21 @@ export declare class Redirect implements NavigationCommand { */ constructor(url: string, options?: NavigationOptions); /** - * Called by the activation system to set the child router. - * - * @param router The router. - */ + * Called by the activation system to set the child router. + * + * @param router The router. + */ setRouter(router: Router): void; /** - * Called by the navigation pipeline to navigate. - * - * @param appRouter The router to be redirected. - */ + * Called by the navigation pipeline to navigate. + * + * @param appRouter The router to be redirected. + */ navigate(appRouter: Router): void; } /** -* Used during the activation lifecycle to cause a redirect to a named route. -*/ + * Used during the activation lifecycle to cause a redirect to a named route. + */ export declare class RedirectToRoute implements NavigationCommand { route: string; params: any; @@ -512,42 +538,18 @@ export declare class RedirectToRoute implements NavigationCommand { */ constructor(route: string, params?: any, options?: NavigationOptions); /** - * Called by the activation system to set the child router. - * - * @param router The router. - */ + * Called by the activation system to set the child router. + * + * @param router The router. + */ setRouter(router: Router): void; /** - * Called by the navigation pipeline to navigate. - * - * @param appRouter The router to be redirected. - */ + * Called by the navigation pipeline to navigate. + * + * @param appRouter The router to be redirected. + */ navigate(appRouter: Router): void; } -/** - * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route - */ -export declare class CanDeactivatePreviousStep { - run(navigationInstruction: NavigationInstruction, next: Next): Promise; -} -/** - * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route - */ -export declare class CanActivateNextStep { - run(navigationInstruction: NavigationInstruction, next: Next): Promise; -} -/** - * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route - */ -export declare class DeactivatePreviousStep { - run(navigationInstruction: NavigationInstruction, next: Next): Promise; -} -/** - * A pipeline step responsible for finding and activating method `activate` on a view model of a route - */ -export declare class ActivateNextStep { - run(navigationInstruction: NavigationInstruction, next: Next): Promise; -} /** * A basic interface for an Observable type */ @@ -598,77 +600,77 @@ export declare type RouteOrRedirectConfig = RouteConfig | RedirectConfig; */ export declare type RouteConfigSpecifier = string | RouteOrRedirectConfig | ((instruction: NavigationInstruction) => string | RouteOrRedirectConfig | Promise); /** -* A configuration object that describes a route. -*/ + * A configuration object that describes a route. + */ export interface RouteConfig { /** - * The route pattern to match against incoming URL fragments, or an array of patterns. - */ + * The route pattern to match against incoming URL fragments, or an array of patterns. + */ route: string | string[]; /** - * A unique name for the route that may be used to identify the route when generating URL fragments. - * Required when this route should support URL generation, such as with [[Router.generate]] or - * the route-href custom attribute. - */ + * A unique name for the route that may be used to identify the route when generating URL fragments. + * Required when this route should support URL generation, such as with [[Router.generate]] or + * the route-href custom attribute. + */ name?: string; /** - * The moduleId of the view model that should be activated for this route. - */ + * The moduleId of the view model that should be activated for this route. + */ moduleId?: string; /** - * A URL fragment to redirect to when this route is matched. - */ + * A URL fragment to redirect to when this route is matched. + */ redirect?: string; /** - * A function that can be used to dynamically select the module or modules to activate. - * The function is passed the current [[NavigationInstruction]], and should configure - * instruction.config with the desired moduleId, viewPorts, or redirect. - */ + * A function that can be used to dynamically select the module or modules to activate. + * The function is passed the current [[NavigationInstruction]], and should configure + * instruction.config with the desired moduleId, viewPorts, or redirect. + */ navigationStrategy?: (instruction: NavigationInstruction) => Promise | void; /** - * The view ports to target when activating this route. If unspecified, the target moduleId is loaded - * into the default viewPort (the viewPort with name 'default'). The viewPorts object should have keys - * whose property names correspond to names used by elements. The values should be objects - * specifying the moduleId to load into that viewPort. The values may optionally include properties related to layout: - * `layoutView`, `layoutViewModel` and `layoutModel`. - */ + * The view ports to target when activating this route. If unspecified, the target moduleId is loaded + * into the default viewPort (the viewPort with name 'default'). The viewPorts object should have keys + * whose property names correspond to names used by elements. The values should be objects + * specifying the moduleId to load into that viewPort. The values may optionally include properties related to layout: + * `layoutView`, `layoutViewModel` and `layoutModel`. + */ viewPorts?: any; /** - * When specified, this route will be included in the [[Router.navigation]] nav model. Useful for - * dynamically generating menus or other navigation elements. When a number is specified, that value - * will be used as a sort order. - */ + * When specified, this route will be included in the [[Router.navigation]] nav model. Useful for + * dynamically generating menus or other navigation elements. When a number is specified, that value + * will be used as a sort order. + */ nav?: boolean | number; /** - * The URL fragment to use in nav models. If unspecified, the [[RouteConfig.route]] will be used. - * However, if the [[RouteConfig.route]] contains dynamic segments, this property must be specified. - */ + * The URL fragment to use in nav models. If unspecified, the [[RouteConfig.route]] will be used. + * However, if the [[RouteConfig.route]] contains dynamic segments, this property must be specified. + */ href?: string; /** - * Indicates that when route generation is done for this route, it should just take the literal value of the href property. - */ + * Indicates that when route generation is done for this route, it should just take the literal value of the href property. + */ generationUsesHref?: boolean; /** - * The document title to set when this route is active. - */ + * The document title to set when this route is active. + */ title?: string; /** - * Arbitrary data to attach to the route. This can be used to attached custom data needed by components - * like pipeline steps and activated modules. - */ + * Arbitrary data to attach to the route. This can be used to attached custom data needed by components + * like pipeline steps and activated modules. + */ settings?: any; /** - * The navigation model for storing and interacting with the route's navigation settings. - */ + * The navigation model for storing and interacting with the route's navigation settings. + */ navModel?: NavModel; /** - * When true is specified, this route will be case sensitive. - */ + * When true is specified, this route will be case sensitive. + */ caseSensitive?: boolean; /** - * Add to specify an activation strategy if it is always the same and you do not want that - * to be in your view-model code. Available values are 'replace' and 'invoke-lifecycle'. - */ + * Add to specify an activation strategy if it is always the same and you do not want that + * to be in your view-model code. Available values are 'replace' and 'invoke-lifecycle'. + */ activationStrategy?: ActivationStrategyType; /** * specifies the file name of a layout view to use. @@ -685,91 +687,70 @@ export interface RouteConfig { [x: string]: any; } /** -* An optional interface describing the canActivate convention. -*/ + * An optional interface describing the canActivate convention. + */ export interface RoutableComponentCanActivate { /** - * Implement this hook if you want to control whether or not your view-model can be navigated to. - * Return a boolean value, a promise for a boolean value, or a navigation command. - */ + * Implement this hook if you want to control whether or not your view-model can be navigated to. + * Return a boolean value, a promise for a boolean value, or a navigation command. + */ canActivate(params: any, routeConfig: RouteConfig, navigationInstruction: NavigationInstruction): boolean | Promise | PromiseLike | NavigationCommand | Promise | PromiseLike; } /** -* An optional interface describing the activate convention. -*/ + * An optional interface describing the activate convention. + */ export interface RoutableComponentActivate { /** - * Implement this hook if you want to perform custom logic just before your view-model is displayed. - * You can optionally return a promise to tell the router to wait to bind and attach the view until - * after you finish your work. - */ + * Implement this hook if you want to perform custom logic just before your view-model is displayed. + * You can optionally return a promise to tell the router to wait to bind and attach the view until + * after you finish your work. + */ activate(params: any, routeConfig: RouteConfig, navigationInstruction: NavigationInstruction): Promise | PromiseLike | IObservable | void; } /** -* An optional interface describing the canDeactivate convention. -*/ + * An optional interface describing the canDeactivate convention. + */ export interface RoutableComponentCanDeactivate { /** - * Implement this hook if you want to control whether or not the router can navigate away from your - * view-model when moving to a new route. Return a boolean value, a promise for a boolean value, - * or a navigation command. - */ + * Implement this hook if you want to control whether or not the router can navigate away from your + * view-model when moving to a new route. Return a boolean value, a promise for a boolean value, + * or a navigation command. + */ canDeactivate: () => boolean | Promise | PromiseLike | NavigationCommand; } /** -* An optional interface describing the deactivate convention. -*/ + * An optional interface describing the deactivate convention. + */ export interface RoutableComponentDeactivate { /** - * Implement this hook if you want to perform custom logic when your view-model is being - * navigated away from. You can optionally return a promise to tell the router to wait until - * after you finish your work. - */ + * Implement this hook if you want to perform custom logic when your view-model is being + * navigated away from. You can optionally return a promise to tell the router to wait until + * after you finish your work. + */ deactivate: () => Promise | PromiseLike | IObservable | void; } /** -* An optional interface describing the determineActivationStrategy convention. -*/ + * An optional interface describing the determineActivationStrategy convention. + */ export interface RoutableComponentDetermineActivationStrategy { /** - * Implement this hook if you want to give hints to the router about the activation strategy, when reusing - * a view model for different routes. Available values are 'replace' and 'invoke-lifecycle'. - */ + * Implement this hook if you want to give hints to the router about the activation strategy, when reusing + * a view model for different routes. Available values are 'replace' and 'invoke-lifecycle'. + */ determineActivationStrategy(params: any, routeConfig: RouteConfig, navigationInstruction: NavigationInstruction): ActivationStrategyType; } /** -* An optional interface describing the router configuration convention. -*/ + * An optional interface describing the router configuration convention. + */ export interface ConfiguresRouter { /** - * Implement this hook if you want to configure a router. - */ + * Implement this hook if you want to configure a router. + */ configureRouter(config: RouterConfiguration, router: Router): Promise | PromiseLike | void; } /** -* An optional interface describing the available activation strategies. -*/ -export interface ActivationStrategy { - /** - * Reuse the existing view model, without invoking Router lifecycle hooks. - */ - noChange: 'no-change'; - /** - * Reuse the existing view model, invoking Router lifecycle hooks. - */ - invokeLifecycle: 'invoke-lifecycle'; - /** - * Replace the existing view model, invoking Router lifecycle hooks. - */ - replace: 'replace'; -} -/** - * Enum like type for activation strategy built-in values + * A step to be run during processing of the pipeline. */ -export declare type ActivationStrategyType = ActivationStrategy[keyof ActivationStrategy]; -/** -* A step to be run during processing of the pipeline. -*/ export interface PipelineStep { /** * Execute the pipeline step. The step should invoke next(), next.complete(), @@ -786,35 +767,49 @@ export interface PipelineStep { export interface IPipelineSlot { } /** -* The result of a pipeline run. -*/ + * The result of a pipeline run. + */ export interface PipelineResult { status: string; instruction: NavigationInstruction; output: any; completed: boolean; } +/** + * The component responsible for routing + */ +export interface ViewPortComponent { + viewModel: any; + childContainer?: Container; + router: Router; + config?: RouteConfig; + childRouter?: Router; + /** + * This is for backward compat, when moving from any to a more strongly typed interface + */ + [key: string]: any; +} export declare type NavigationResult = boolean | Promise; /** -* A callback to indicate when pipeline processing should advance to the next step -* or be aborted. -*/ + * A callback to indicate when pipeline processing should advance to the next step + * or be aborted. + */ export interface Next { /** - * Indicates the successful completion of the pipeline step. - */ + * Indicates the successful completion of the pipeline step. + */ (): Promise; /** - * Indicates the successful completion of the entire pipeline. - */ + * Indicates the successful completion of the entire pipeline. + */ complete: NextCompletionHandler; /** - * Indicates that the pipeline should cancel processing. - */ + * Indicates that the pipeline should cancel processing. + */ cancel: NextCompletionHandler; /** - * Indicates that pipeline processing has failed and should be stopped. - */ + * Indicates that pipeline processing has failed and should be stopped. + */ reject: NextCompletionHandler; } /** @@ -831,39 +826,39 @@ export interface NextCompletionResult { export declare type NextCompletionHandler = (output?: T) => Promise>; export declare type StepRunnerFunction = (this: TThis, instruction: NavigationInstruction, next: Next) => any; /** -* The class responsible for managing and processing the navigation pipeline. -*/ + * The class responsible for managing and processing the navigation pipeline. + */ export declare class Pipeline { /** - * The pipeline steps. And steps added via addStep will be converted to a function - * The actualy running functions with correct step contexts of this pipeline - */ + * The pipeline steps. And steps added via addStep will be converted to a function + * The actualy running functions with correct step contexts of this pipeline + */ steps: StepRunnerFunction[]; /** - * Adds a step to the pipeline. - * - * @param step The pipeline step. - */ + * Adds a step to the pipeline. + * + * @param step The pipeline step. + */ addStep(step: StepRunnerFunction | PipelineStep | IPipelineSlot): Pipeline; /** - * Runs the pipeline. - * - * @param instruction The navigation instruction to process. - */ + * Runs the pipeline. + * + * @param instruction The navigation instruction to process. + */ run(instruction: NavigationInstruction): Promise; } /** -* Class responsible for creating the navigation pipeline. -*/ + * Class responsible for creating the navigation pipeline. + */ export declare class PipelineProvider { constructor(container: Container); /** - * Create the navigation pipeline. - */ + * Create the navigation pipeline. + */ createPipeline(useCanDeactivateStep?: boolean): Pipeline; /** - * Adds a step into the pipeline at a known slot location. - */ + * Adds a step into the pipeline at a known slot location. + */ addStep(name: string, step: PipelineStep | Function): void; /** * Removes a step from a slot in the pipeline @@ -875,44 +870,70 @@ export declare class PipelineProvider { reset(): void; } /** -* The main application router. -*/ + * The main application router. + */ export declare class AppRouter extends Router { events: EventAggregator; constructor(container: Container, history: History, pipelineProvider: PipelineProvider, events: EventAggregator); /** - * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. - * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. - */ + * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. + * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. + */ reset(): void; /** - * Loads the specified URL. - * - * @param url The URL fragment to load. - */ + * Loads the specified URL. + * + * @param url The URL fragment to load. + */ loadUrl(url: string): Promise; /** - * Registers a viewPort to be used as a rendering target for activated routes. - * - * @param viewPort The viewPort. This is typically a element in Aurelia default impl - * @param name The name of the viewPort. 'default' if unspecified. - */ + * Registers a viewPort to be used as a rendering target for activated routes. + * + * @param viewPort The viewPort. This is typically a element in Aurelia default impl + * @param name The name of the viewPort. 'default' if unspecified. + */ registerViewPort(viewPort: any, name?: string): Promise; /** - * Activates the router. This instructs the router to begin listening for history changes and processing instructions. - * - * @params options The set of options to activate the router with. - */ + * Activates the router. This instructs the router to begin listening for history changes and processing instructions. + * + * @params options The set of options to activate the router with. + */ activate(options?: NavigationOptions): void; /** - * Deactivates the router. - */ + * Deactivates the router. + */ deactivate(): void; } /** -* The strategy to use when activating modules during navigation. -*/ -export declare const activationStrategy: ActivationStrategy; + * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route + */ +export declare class CanDeactivatePreviousStep { + run(navigationInstruction: NavigationInstruction, next: Next): Promise; +} +/** + * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route + */ +export declare class CanActivateNextStep { + run(navigationInstruction: NavigationInstruction, next: Next): Promise; +} +/** + * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route + */ +export declare class DeactivatePreviousStep { + run(navigationInstruction: NavigationInstruction, next: Next): Promise; +} +/** + * A pipeline step responsible for finding and activating method `activate` on a view model of a route + */ +export declare class ActivateNextStep { + run(navigationInstruction: NavigationInstruction, next: Next): Promise; +} +/** + * A pipeline step for instructing a piepline to commit changes on a navigation instruction + */ +export declare class CommitChangesStep { + run(navigationInstruction: NavigationInstruction, next: Function): Promise; +} /** * Transform a navigation instruction into viewport plan record object, * or a redirect request if user viewmodel demands @@ -920,6 +941,26 @@ export declare const activationStrategy: ActivationStrategy; export declare class BuildNavigationPlanStep { run(navigationInstruction: NavigationInstruction, next: Next): Promise; } +/** + * Abstract class that is responsible for loading view / view model from a route config + * The default implementation can be found in `aurelia-templating-router` + */ +export declare class RouteLoader { + /** + * Load a route config based on its viewmodel / view configuration + */ + loadRoute(router: Router, config: RouteConfig, navigationInstruction: NavigationInstruction): Promise; +} +/** + * A pipeline step responsible for loading a route config of a navigation instruction + */ +export declare class LoadRouteStep { + constructor(routeLoader: RouteLoader); + /** + * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline + */ + run(navigationInstruction: NavigationInstruction, next: Next): Promise; +} /** * A list of known router events used by the Aurelia router * to signal the pipeline has come to a certain state @@ -961,24 +1002,4 @@ export declare const enum PipelineSlotName { * Post-render slot. Invoked last in the pipeline */ PostRender = "postRender" -} -/** - * Abstract class that is responsible for loading view / view model from a route config - * The default implementation can be found in `aurelia-templating-router` - */ -export declare class RouteLoader { - /** - * Load a route config based on its viewmodel / view configuration - */ - loadRoute(router: Router, config: RouteConfig, navigationInstruction: NavigationInstruction): Promise; -} -/** - * A pipeline step responsible for loading a route config of a navigation instruction - */ -export declare class LoadRouteStep { - constructor(routeLoader: RouteLoader); - /** - * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline - */ - run(navigationInstruction: NavigationInstruction, next: Next): Promise; } \ No newline at end of file diff --git a/dist/commonjs/aurelia-router.js b/dist/commonjs/aurelia-router.js index c4cf1f70..b91bc05a 100644 --- a/dist/commonjs/aurelia-router.js +++ b/dist/commonjs/aurelia-router.js @@ -8,1753 +8,1871 @@ var aureliaHistory = require('aurelia-history'); var aureliaRouteRecognizer = require('aurelia-route-recognizer'); var aureliaEventAggregator = require('aurelia-event-aggregator'); +/*! ***************************************************************************** +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 = function(d, b) { + 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]; }; + return extendStatics(d, b); +}; + +function __extends(d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +} + /** -* Determines if the provided object is a navigation command. -* A navigation command is anything with a navigate method. -* -* @param obj The object to check. -*/ -function isNavigationCommand(obj) { - return obj && typeof obj.navigate === 'function'; -} -/** -* Used during the activation lifecycle to cause a redirect. -*/ -var Redirect = /** @class */ (function () { - /** - * @param url The URL fragment to use as the navigation destination. - * @param options The navigation options. - */ - function Redirect(url, options) { - if (options === void 0) { options = {}; } - this.url = url; - this.options = Object.assign({ trigger: true, replace: true }, options); - this.shouldContinueProcessing = false; + * Class used to represent an instruction during a navigation. + */ +var NavigationInstruction = /** @class */ (function () { + function NavigationInstruction(init) { + /** + * Current built viewport plan of this nav instruction + */ + this.plan = null; + this.options = {}; + Object.assign(this, init); + this.params = this.params || {}; + this.viewPortInstructions = {}; + var ancestorParams = []; + var current = this; + do { + var currentParams = Object.assign({}, current.params); + if (current.config && current.config.hasChildRouter) { + // remove the param for the injected child route segment + delete currentParams[current.getWildCardName()]; + } + ancestorParams.unshift(currentParams); + current = current.parentInstruction; + } while (current); + var allParams = Object.assign.apply(Object, [{}, this.queryParams].concat(ancestorParams)); + this.lifecycleArgs = [allParams, this.config, this]; } /** - * Called by the activation system to set the child router. - * - * @param router The router. - */ - Redirect.prototype.setRouter = function (router) { - this.router = router; + * Gets an array containing this instruction and all child instructions for the current navigation. + */ + NavigationInstruction.prototype.getAllInstructions = function () { + var instructions = [this]; + var viewPortInstructions = this.viewPortInstructions; + for (var key in viewPortInstructions) { + var childInstruction = viewPortInstructions[key].childNavigationInstruction; + if (childInstruction) { + instructions.push.apply(instructions, childInstruction.getAllInstructions()); + } + } + return instructions; }; /** - * Called by the navigation pipeline to navigate. - * - * @param appRouter The router to be redirected. - */ - Redirect.prototype.navigate = function (appRouter) { - var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); - navigatingRouter.navigate(this.url, this.options); + * Gets an array containing the instruction and all child instructions for the previous navigation. + * Previous instructions are no longer available after navigation completes. + */ + NavigationInstruction.prototype.getAllPreviousInstructions = function () { + return this.getAllInstructions().map(function (c) { return c.previousInstruction; }).filter(function (c) { return c; }); + }; + NavigationInstruction.prototype.addViewPortInstruction = function (nameOrInitOptions, strategy, moduleId, component) { + var viewPortInstruction; + var viewPortName = typeof nameOrInitOptions === 'string' ? nameOrInitOptions : nameOrInitOptions.name; + var lifecycleArgs = this.lifecycleArgs; + var config = Object.assign({}, lifecycleArgs[1], { currentViewPort: viewPortName }); + if (typeof nameOrInitOptions === 'string') { + viewPortInstruction = { + name: nameOrInitOptions, + strategy: strategy, + moduleId: moduleId, + component: component, + childRouter: component.childRouter, + lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] + }; + } + else { + viewPortInstruction = { + name: viewPortName, + strategy: nameOrInitOptions.strategy, + component: nameOrInitOptions.component, + moduleId: nameOrInitOptions.moduleId, + childRouter: nameOrInitOptions.component.childRouter, + lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] + }; + } + return this.viewPortInstructions[viewPortName] = viewPortInstruction; }; - return Redirect; -}()); -/** -* Used during the activation lifecycle to cause a redirect to a named route. -*/ -var RedirectToRoute = /** @class */ (function () { /** - * @param route The name of the route. - * @param params The parameters to be sent to the activation method. - * @param options The options to use for navigation. + * Gets the name of the route pattern's wildcard parameter, if applicable. */ - function RedirectToRoute(route, params, options) { - if (params === void 0) { params = {}; } - if (options === void 0) { options = {}; } - this.route = route; - this.params = params; - this.options = Object.assign({ trigger: true, replace: true }, options); - this.shouldContinueProcessing = false; - } - /** - * Called by the activation system to set the child router. - * - * @param router The router. - */ - RedirectToRoute.prototype.setRouter = function (router) { - this.router = router; + NavigationInstruction.prototype.getWildCardName = function () { + // todo: potential issue, or at least unsafe typings + var configRoute = this.config.route; + var wildcardIndex = configRoute.lastIndexOf('*'); + return configRoute.substr(wildcardIndex + 1); }; /** - * Called by the navigation pipeline to navigate. - * - * @param appRouter The router to be redirected. - */ - RedirectToRoute.prototype.navigate = function (appRouter) { - var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); - navigatingRouter.navigateToRoute(this.route, this.params, this.options); + * Gets the path and query string created by filling the route + * pattern's wildcard parameter with the matching param. + */ + NavigationInstruction.prototype.getWildcardPath = function () { + var wildcardName = this.getWildCardName(); + var path = this.params[wildcardName] || ''; + var queryString = this.queryString; + if (queryString) { + path += '?' + queryString; + } + return path; }; - return RedirectToRoute; -}()); - -/** -* The strategy to use when activating modules during navigation. -*/ -var activationStrategy = { - noChange: 'no-change', - invokeLifecycle: 'invoke-lifecycle', - replace: 'replace' -}; -/** - * Transform a navigation instruction into viewport plan record object, - * or a redirect request if user viewmodel demands - */ -var BuildNavigationPlanStep = /** @class */ (function () { - function BuildNavigationPlanStep() { - } - BuildNavigationPlanStep.prototype.run = function (navigationInstruction, next) { - return _buildNavigationPlan(navigationInstruction) - .then(function (plan) { - if (plan instanceof Redirect) { - return next.cancel(plan); + /** + * Gets the instruction's base URL, accounting for wildcard route parameters. + */ + NavigationInstruction.prototype.getBaseUrl = function () { + var _this = this; + var $encodeURI = encodeURI; + var fragment = decodeURI(this.fragment); + if (fragment === '') { + var nonEmptyRoute = this.router.routes.find(function (route) { + return route.name === _this.config.name && + route.route !== ''; + }); + if (nonEmptyRoute) { + fragment = nonEmptyRoute.route; } - navigationInstruction.plan = plan; - return next(); - }) - .catch(next.cancel); + } + if (!this.params) { + return $encodeURI(fragment); + } + var wildcardName = this.getWildCardName(); + var path = this.params[wildcardName] || ''; + if (!path) { + return $encodeURI(fragment); + } + return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path))); }; - return BuildNavigationPlanStep; -}()); -function _buildNavigationPlan(instruction, forceLifecycleMinimum) { - var config = instruction.config; - // todo: separate and export for unit tests - if ('redirect' in config) { - var router_1 = instruction.router; - return router_1 - ._createNavigationInstruction(config.redirect) - .then(function (newInstruction) { - var params = {}; - for (var key in newInstruction.params) { - // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this } - var val = newInstruction.params[key]; - if (typeof val === 'string' && val[0] === ':') { - val = val.slice(1); - // And if that param is found on the original instruction then use it - if (val in instruction.params) { - params[key] = instruction.params[val]; - } + /** + * Finalize a viewport instruction + * @internal + */ + NavigationInstruction.prototype._commitChanges = function (waitToSwap) { + var _this = this; + var router = this.router; + router.currentInstruction = this; + var previousInstruction = this.previousInstruction; + if (previousInstruction) { + previousInstruction.config.navModel.isActive = false; + } + this.config.navModel.isActive = true; + router.refreshNavigation(); + var loads = []; + var delaySwaps = []; + var viewPortInstructions = this.viewPortInstructions; + var _loop_1 = function (viewPortName) { + var viewPortInstruction = viewPortInstructions[viewPortName]; + var viewPort = router.viewPorts[viewPortName]; + if (!viewPort) { + throw new Error("There was no router-view found in the view for " + viewPortInstruction.moduleId + "."); + } + var childNavInstruction = viewPortInstruction.childNavigationInstruction; + if (viewPortInstruction.strategy === "replace" /* Replace */) { + if (childNavInstruction && childNavInstruction.parentCatchHandler) { + loads.push(childNavInstruction._commitChanges(waitToSwap)); } else { - params[key] = newInstruction.params[key]; + if (waitToSwap) { + delaySwaps.push({ viewPort: viewPort, viewPortInstruction: viewPortInstruction }); + } + loads.push(viewPort + .process(viewPortInstruction, waitToSwap) + .then(function () { return childNavInstruction + ? childNavInstruction._commitChanges(waitToSwap) + : Promise.resolve(); })); } } - var redirectLocation = router_1.generate(newInstruction.config, params, instruction.options); - // Special handling for child routes - for (var key in instruction.params) { - redirectLocation = redirectLocation.replace(":" + key, instruction.params[key]); - } - if (instruction.queryString) { - redirectLocation += '?' + instruction.queryString; - } - return Promise.resolve(new Redirect(redirectLocation)); - }); - } - var prev = instruction.previousInstruction; - var plan = {}; - var defaults = instruction.router.viewPortDefaults; - if (prev) { - var newParams = hasDifferentParameterValues(prev, instruction); - var pending_1 = []; - var _loop_1 = function (viewPortName) { - var _a; - var prevViewPortInstruction = prev.viewPortInstructions[viewPortName]; - var nextViewPortConfig = viewPortName in config.viewPorts ? config.viewPorts[viewPortName] : prevViewPortInstruction; - if (nextViewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) { - nextViewPortConfig = defaults[viewPortName]; - } - var viewPortPlan = plan[viewPortName] = { - name: viewPortName, - config: nextViewPortConfig, - prevComponent: prevViewPortInstruction.component, - prevModuleId: prevViewPortInstruction.moduleId - }; - if (prevViewPortInstruction.moduleId !== nextViewPortConfig.moduleId) { - viewPortPlan.strategy = activationStrategy.replace; - } - else if ('determineActivationStrategy' in prevViewPortInstruction.component.viewModel) { - viewPortPlan.strategy = (_a = prevViewPortInstruction.component.viewModel).determineActivationStrategy.apply(_a, instruction.lifecycleArgs); - } - else if (config.activationStrategy) { - viewPortPlan.strategy = config.activationStrategy; - } - else if (newParams || forceLifecycleMinimum) { - viewPortPlan.strategy = activationStrategy.invokeLifecycle; - } else { - viewPortPlan.strategy = activationStrategy.noChange; - } - if (viewPortPlan.strategy !== activationStrategy.replace && prevViewPortInstruction.childRouter) { - var path = instruction.getWildcardPath(); - var task = prevViewPortInstruction - .childRouter - ._createNavigationInstruction(path, instruction) - .then(function (childInstruction) { - viewPortPlan.childNavigationInstruction = childInstruction; - return _buildNavigationPlan(childInstruction, viewPortPlan.strategy === activationStrategy.invokeLifecycle) - .then(function (childPlan) { - if (childPlan instanceof Redirect) { - return Promise.reject(childPlan); - } - childInstruction.plan = childPlan; - // for bluebird ? - return null; - }); - }); - pending_1.push(task); + if (childNavInstruction) { + loads.push(childNavInstruction._commitChanges(waitToSwap)); + } } }; - for (var viewPortName in prev.viewPortInstructions) { + for (var viewPortName in viewPortInstructions) { _loop_1(viewPortName); } - return Promise.all(pending_1).then(function () { return plan; }); - } - for (var viewPortName in config.viewPorts) { - var viewPortConfig = config.viewPorts[viewPortName]; - if (viewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) { - viewPortConfig = defaults[viewPortName]; - } - plan[viewPortName] = { - name: viewPortName, - strategy: activationStrategy.replace, - config: viewPortConfig - }; - } - return Promise.resolve(plan); -} -function hasDifferentParameterValues(prev, next) { - var prevParams = prev.params; - var nextParams = next.params; - var nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; - for (var key in nextParams) { - if (key === nextWildCardName) { - continue; - } - if (prevParams[key] !== nextParams[key]) { - return true; + return Promise + .all(loads) + .then(function () { + delaySwaps.forEach(function (x) { return x.viewPort.swap(x.viewPortInstruction); }); + return null; + }) + .then(function () { return prune(_this); }); + }; + /**@internal */ + NavigationInstruction.prototype._updateTitle = function () { + var router = this.router; + var title = this._buildTitle(router.titleSeparator); + if (title) { + router.history.setTitle(title); } - } - for (var key in prevParams) { - if (key === nextWildCardName) { - continue; + }; + /**@internal */ + NavigationInstruction.prototype._buildTitle = function (separator) { + if (separator === void 0) { separator = ' | '; } + var title = ''; + var childTitles = []; + var navModelTitle = this.config.navModel.title; + var instructionRouter = this.router; + var viewPortInstructions = this.viewPortInstructions; + if (navModelTitle) { + title = instructionRouter.transformTitle(navModelTitle); } - if (prevParams[key] !== nextParams[key]) { - return true; + for (var viewPortName in viewPortInstructions) { + var viewPortInstruction = viewPortInstructions[viewPortName]; + var child_nav_instruction = viewPortInstruction.childNavigationInstruction; + if (child_nav_instruction) { + var childTitle = child_nav_instruction._buildTitle(separator); + if (childTitle) { + childTitles.push(childTitle); + } + } } - } - if (!next.options.compareQueryParams) { - return false; - } - var prevQueryParams = prev.queryParams; - var nextQueryParams = next.queryParams; - for (var key in nextQueryParams) { - if (prevQueryParams[key] !== nextQueryParams[key]) { - return true; + if (childTitles.length) { + title = childTitles.join(separator) + (title ? separator : '') + title; } - } - for (var key in prevQueryParams) { - if (prevQueryParams[key] !== nextQueryParams[key]) { - return true; + if (instructionRouter.title) { + title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title); } - } - return false; -} - -/** - * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route - */ -var CanDeactivatePreviousStep = /** @class */ (function () { - function CanDeactivatePreviousStep() { - } - CanDeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { - return processDeactivatable(navigationInstruction, 'canDeactivate', next); + return title; }; - return CanDeactivatePreviousStep; + return NavigationInstruction; }()); +var prune = function (instruction) { + instruction.previousInstruction = null; + instruction.plan = null; +}; + /** - * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route - */ -var CanActivateNextStep = /** @class */ (function () { - function CanActivateNextStep() { +* Class for storing and interacting with a route's navigation settings. +*/ +var NavModel = /** @class */ (function () { + function NavModel(router, relativeHref) { + /** + * True if this nav item is currently active. + */ + this.isActive = false; + /** + * The title. + */ + this.title = null; + /** + * This nav item's absolute href. + */ + this.href = null; + /** + * This nav item's relative href. + */ + this.relativeHref = null; + /** + * Data attached to the route at configuration time. + */ + this.settings = {}; + /** + * The route config. + */ + this.config = null; + this.router = router; + this.relativeHref = relativeHref; } - CanActivateNextStep.prototype.run = function (navigationInstruction, next) { - return processActivatable(navigationInstruction, 'canActivate', next); + /** + * Sets the route's title and updates document.title. + * If the a navigation is in progress, the change will be applied + * to document.title when the navigation completes. + * + * @param title The new title. + */ + NavModel.prototype.setTitle = function (title) { + this.title = title; + if (this.isActive) { + this.router.updateTitle(); + } }; - return CanActivateNextStep; -}()); -/** - * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route - */ -var DeactivatePreviousStep = /** @class */ (function () { - function DeactivatePreviousStep() { + return NavModel; +}()); + +function _normalizeAbsolutePath(path, hasPushState, absolute) { + if (absolute === void 0) { absolute = false; } + if (!hasPushState && path[0] !== '#') { + path = '#' + path; } - DeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { - return processDeactivatable(navigationInstruction, 'deactivate', next, true); - }; - return DeactivatePreviousStep; -}()); -/** - * A pipeline step responsible for finding and activating method `activate` on a view model of a route - */ -var ActivateNextStep = /** @class */ (function () { - function ActivateNextStep() { + if (hasPushState && absolute) { + path = path.substring(1, path.length); } - ActivateNextStep.prototype.run = function (navigationInstruction, next) { - return processActivatable(navigationInstruction, 'activate', next, true); - }; - return ActivateNextStep; -}()); -/** - * Recursively find list of deactivate-able view models - * and invoke the either 'canDeactivate' or 'deactivate' on each - */ -var processDeactivatable = function (navigationInstruction, callbackName, next, ignoreResult) { - var plan = navigationInstruction.plan; - var infos = findDeactivatable(plan, callbackName); - var i = infos.length; // query from inside out - function inspect(val) { - if (ignoreResult || shouldContinue(val)) { - return iterate(); - } - return next.cancel(val); + return path; +} +function _createRootedPath(fragment, baseUrl, hasPushState, absolute) { + if (isAbsoluteUrl.test(fragment)) { + return fragment; } - function iterate() { - if (i--) { - try { - var viewModel = infos[i]; - var result = viewModel[callbackName](navigationInstruction); - return processPotential(result, inspect, next.cancel); - } - catch (error) { - return next.cancel(error); - } + var path = ''; + if (baseUrl.length && baseUrl[0] !== '/') { + path += '/'; + } + path += baseUrl; + if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') { + path += '/'; + } + if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') { + path = path.substring(0, path.length - 1); + } + return _normalizeAbsolutePath(path + fragment, hasPushState, absolute); +} +function _resolveUrl(fragment, baseUrl, hasPushState) { + if (isRootedPath.test(fragment)) { + return _normalizeAbsolutePath(fragment, hasPushState); + } + return _createRootedPath(fragment, baseUrl, hasPushState); +} +function _ensureArrayWithSingleRoutePerConfig(config) { + var routeConfigs = []; + if (Array.isArray(config.route)) { + for (var i = 0, ii = config.route.length; i < ii; ++i) { + var current = Object.assign({}, config); + current.route = config.route[i]; + routeConfigs.push(current); } - navigationInstruction.router.couldDeactivate = true; - return next(); } - return iterate(); -}; + else { + routeConfigs.push(Object.assign({}, config)); + } + return routeConfigs; +} +var isRootedPath = /^#?\//; +var isAbsoluteUrl = /^([a-z][a-z0-9+\-.]*:)?\/\//i; + /** - * Recursively find and returns a list of deactivate-able view models + * Class used to configure a [[Router]] instance. + * + * @constructor */ -var findDeactivatable = function (plan, callbackName, list) { - if (list === void 0) { list = []; } - for (var viewPortName in plan) { - var viewPortPlan = plan[viewPortName]; - var prevComponent = viewPortPlan.prevComponent; - if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace) - && prevComponent) { - var viewModel = prevComponent.viewModel; - if (callbackName in viewModel) { - list.push(viewModel); - } - } - if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) { - addPreviousDeactivatable(prevComponent, callbackName, list); - } - else if (viewPortPlan.childNavigationInstruction) { - findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list); - } - } - return list; -}; -var addPreviousDeactivatable = function (component, callbackName, list) { - var childRouter = component.childRouter; - if (childRouter && childRouter.currentInstruction) { - var viewPortInstructions = childRouter.currentInstruction.viewPortInstructions; - for (var viewPortName in viewPortInstructions) { - var viewPortInstruction = viewPortInstructions[viewPortName]; - var prevComponent = viewPortInstruction.component; - var prevViewModel = prevComponent.viewModel; - if (callbackName in prevViewModel) { - list.push(prevViewModel); - } - addPreviousDeactivatable(prevComponent, callbackName, list); - } - } -}; -var processActivatable = function (navigationInstruction, callbackName, next, ignoreResult) { - var infos = findActivatable(navigationInstruction, callbackName); - var length = infos.length; - var i = -1; // query from top down - function inspect(val, router) { - if (ignoreResult || shouldContinue(val, router)) { - return iterate(); - } - return next.cancel(val); - } - function iterate() { - var _a; - i++; - if (i < length) { - try { - var current_1 = infos[i]; - var result = (_a = current_1.viewModel)[callbackName].apply(_a, current_1.lifecycleArgs); - return processPotential(result, function (val) { return inspect(val, current_1.router); }, next.cancel); - } - catch (error) { - return next.cancel(error); - } - } - return next(); - } - return iterate(); -}; -/** - * Find list of activatable view model and add to list (3rd parameter) - */ -var findActivatable = function (navigationInstruction, callbackName, list, router) { - if (list === void 0) { list = []; } - var plan = navigationInstruction.plan; - Object - .keys(plan) - .forEach(function (viewPortName) { - var viewPortPlan = plan[viewPortName]; - var viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName]; - var viewPortComponent = viewPortInstruction.component; - var viewModel = viewPortComponent.viewModel; - if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle - || viewPortPlan.strategy === activationStrategy.replace) - && callbackName in viewModel) { - list.push({ - viewModel: viewModel, - lifecycleArgs: viewPortInstruction.lifecycleArgs, - router: router - }); - } - var childNavInstruction = viewPortPlan.childNavigationInstruction; - if (childNavInstruction) { - findActivatable(childNavInstruction, callbackName, list, viewPortComponent.childRouter || router); - } - }); - return list; -}; -var shouldContinue = function (output, router) { - if (output instanceof Error) { - return false; - } - if (isNavigationCommand(output)) { - if (typeof output.setRouter === 'function') { - output.setRouter(router); - } - return !!output.shouldContinueProcessing; - } - if (output === undefined) { - return true; - } - return output; -}; -/** - * wraps a subscription, allowing unsubscribe calls even if - * the first value comes synchronously - */ -var SafeSubscription = /** @class */ (function () { - function SafeSubscription(subscriptionFunc) { - this._subscribed = true; - this._subscription = subscriptionFunc(this); - if (!this._subscribed) { - this.unsubscribe(); - } - } - Object.defineProperty(SafeSubscription.prototype, "subscribed", { - get: function () { - return this._subscribed; - }, - enumerable: true, - configurable: true - }); - SafeSubscription.prototype.unsubscribe = function () { - if (this._subscribed && this._subscription) { - this._subscription.unsubscribe(); - } - this._subscribed = false; - }; - return SafeSubscription; -}()); -/** - * A function to process return value from `activate`/`canActivate` steps - * Supports observable/promise - * - * For observable, resolve at first next() or on complete() - */ -var processPotential = function (obj, resolve, reject) { - // if promise like - if (obj && typeof obj.then === 'function') { - return Promise.resolve(obj).then(resolve).catch(reject); - } - // if observable - if (obj && typeof obj.subscribe === 'function') { - var obs_1 = obj; - return new SafeSubscription(function (sub) { return obs_1.subscribe({ - next: function () { - if (sub.subscribed) { - sub.unsubscribe(); - resolve(obj); - } - }, - error: function (error) { - if (sub.subscribed) { - sub.unsubscribe(); - reject(error); - } - }, - complete: function () { - if (sub.subscribed) { - sub.unsubscribe(); - resolve(obj); - } - } - }); }); - } - // else just resolve - try { - return resolve(obj); - } - catch (error) { - return reject(error); - } -}; - -/*! ***************************************************************************** -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 = function(d, b) { - 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]; }; - return extendStatics(d, b); -}; - -function __extends(d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); -} - -/** - * A pipeline step for instructing a piepline to commit changes on a navigation instruction - */ -var CommitChangesStep = /** @class */ (function () { - function CommitChangesStep() { - } - CommitChangesStep.prototype.run = function (navigationInstruction, next) { - return navigationInstruction - ._commitChanges(/*wait to swap?*/ true) - .then(function () { - navigationInstruction._updateTitle(); - return next(); - }); - }; - return CommitChangesStep; -}()); -/** -* Class used to represent an instruction during a navigation. -*/ -var NavigationInstruction = /** @class */ (function () { - function NavigationInstruction(init) { - /** - * Current built viewport plan of this nav instruction - */ - this.plan = null; - this.options = {}; - Object.assign(this, init); - this.params = this.params || {}; - this.viewPortInstructions = {}; - var ancestorParams = []; - var current = this; - do { - var currentParams = Object.assign({}, current.params); - if (current.config && current.config.hasChildRouter) { - // remove the param for the injected child route segment - delete currentParams[current.getWildCardName()]; - } - ancestorParams.unshift(currentParams); - current = current.parentInstruction; - } while (current); - var allParams = Object.assign.apply(Object, [{}, this.queryParams].concat(ancestorParams)); - this.lifecycleArgs = [allParams, this.config, this]; +var RouterConfiguration = /** @class */ (function () { + function RouterConfiguration() { + this.instructions = []; + this.options = {}; + this.pipelineSteps = []; } /** - * Gets an array containing this instruction and all child instructions for the current navigation. - */ - NavigationInstruction.prototype.getAllInstructions = function () { - var instructions = [this]; - var viewPortInstructions = this.viewPortInstructions; - for (var key in viewPortInstructions) { - var childInstruction = viewPortInstructions[key].childNavigationInstruction; - if (childInstruction) { - instructions.push.apply(instructions, childInstruction.getAllInstructions()); - } + * Adds a step to be run during the [[Router]]'s navigation pipeline. + * + * @param name The name of the pipeline slot to insert the step into. + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPipelineStep = function (name, step) { + if (step === null || step === undefined) { + throw new Error('Pipeline step cannot be null or undefined.'); } - return instructions; + this.pipelineSteps.push({ name: name, step: step }); + return this; }; /** - * Gets an array containing the instruction and all child instructions for the previous navigation. - * Previous instructions are no longer available after navigation completes. - */ - NavigationInstruction.prototype.getAllPreviousInstructions = function () { - return this.getAllInstructions().map(function (c) { return c.previousInstruction; }).filter(function (c) { return c; }); + * Adds a step to be run during the [[Router]]'s authorize pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addAuthorizeStep = function (step) { + return this.addPipelineStep("authorize" /* Authorize */, step); }; /** - * Adds a viewPort instruction. Returns the newly created instruction based on parameters - */ - NavigationInstruction.prototype.addViewPortInstruction = function (name, strategy, moduleId, component) { - var lifecycleArgs = this.lifecycleArgs; - var config = Object.assign({}, lifecycleArgs[1], { currentViewPort: name }); - var viewportInstruction = this.viewPortInstructions[name] = { - name: name, - strategy: strategy, - moduleId: moduleId, - component: component, - childRouter: component.childRouter, - lifecycleArgs: [].concat(lifecycleArgs[0], config, lifecycleArgs[2]) - }; - return viewportInstruction; + * Adds a step to be run during the [[Router]]'s preActivate pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPreActivateStep = function (step) { + return this.addPipelineStep("preActivate" /* PreActivate */, step); }; /** - * Gets the name of the route pattern's wildcard parameter, if applicable. - */ - NavigationInstruction.prototype.getWildCardName = function () { - // todo: potential issue, or at least unsafe typings - var configRoute = this.config.route; - var wildcardIndex = configRoute.lastIndexOf('*'); - return configRoute.substr(wildcardIndex + 1); + * Adds a step to be run during the [[Router]]'s preRender pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPreRenderStep = function (step) { + return this.addPipelineStep("preRender" /* PreRender */, step); }; /** - * Gets the path and query string created by filling the route - * pattern's wildcard parameter with the matching param. - */ - NavigationInstruction.prototype.getWildcardPath = function () { - var wildcardName = this.getWildCardName(); - var path = this.params[wildcardName] || ''; - var queryString = this.queryString; - if (queryString) { - path += '?' + queryString; - } - return path; + * Adds a step to be run during the [[Router]]'s postRender pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPostRenderStep = function (step) { + return this.addPipelineStep("postRender" /* PostRender */, step); }; /** - * Gets the instruction's base URL, accounting for wildcard route parameters. - */ - NavigationInstruction.prototype.getBaseUrl = function () { - var _this = this; - var $encodeURI = encodeURI; - var fragment = decodeURI(this.fragment); - if (fragment === '') { - var nonEmptyRoute = this.router.routes.find(function (route) { - return route.name === _this.config.name && - route.route !== ''; - }); - if (nonEmptyRoute) { - fragment = nonEmptyRoute.route; - } - } - if (!this.params) { - return $encodeURI(fragment); - } - var wildcardName = this.getWildCardName(); - var path = this.params[wildcardName] || ''; - if (!path) { - return $encodeURI(fragment); - } - return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path))); + * Configures a route that will be used if there is no previous location available on navigation cancellation. + * + * @param fragment The URL fragment to use as the navigation destination. + * @chainable + */ + RouterConfiguration.prototype.fallbackRoute = function (fragment) { + this._fallbackRoute = fragment; + return this; }; - /**@internal */ - NavigationInstruction.prototype._commitChanges = function (waitToSwap) { + /** + * Maps one or more routes to be registered with the router. + * + * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map. + * @chainable + */ + RouterConfiguration.prototype.map = function (route) { var _this = this; - var router = this.router; - router.currentInstruction = this; - var previousInstruction = this.previousInstruction; - if (previousInstruction) { - previousInstruction.config.navModel.isActive = false; - } - this.config.navModel.isActive = true; - router.refreshNavigation(); - var loads = []; - var delaySwaps = []; - var viewPortInstructions = this.viewPortInstructions; - var _loop_1 = function (viewPortName) { - var viewPortInstruction = viewPortInstructions[viewPortName]; - var viewPort = router.viewPorts[viewPortName]; - if (!viewPort) { - throw new Error("There was no router-view found in the view for " + viewPortInstruction.moduleId + "."); - } - var child_nav_instruction = viewPortInstruction.childNavigationInstruction; - if (viewPortInstruction.strategy === activationStrategy.replace) { - if (child_nav_instruction && child_nav_instruction.parentCatchHandler) { - loads.push(child_nav_instruction._commitChanges(waitToSwap)); - } - else { - if (waitToSwap) { - delaySwaps.push({ viewPort: viewPort, viewPortInstruction: viewPortInstruction }); - } - loads.push(viewPort - .process(viewPortInstruction, waitToSwap) - .then(function () { return child_nav_instruction - ? child_nav_instruction._commitChanges(waitToSwap) - : Promise.resolve(); })); - } - } - else { - if (child_nav_instruction) { - loads.push(child_nav_instruction._commitChanges(waitToSwap)); - } - } - }; - for (var viewPortName in viewPortInstructions) { - _loop_1(viewPortName); + if (Array.isArray(route)) { + route.forEach(function (r) { return _this.map(r); }); + return this; } - return Promise - .all(loads) - .then(function () { - delaySwaps.forEach(function (x) { return x.viewPort.swap(x.viewPortInstruction); }); - return null; - }) - .then(function () { return prune(_this); }); + return this.mapRoute(route); }; - /**@internal */ - NavigationInstruction.prototype._updateTitle = function () { - var router = this.router; - var title = this._buildTitle(router.titleSeparator); - if (title) { - router.history.setTitle(title); - } + /** + * Configures defaults to use for any view ports. + * + * @param viewPortConfig a view port configuration object to use as a + * default, of the form { viewPortName: { moduleId } }. + * @chainable + */ + RouterConfiguration.prototype.useViewPortDefaults = function (viewPortConfig) { + this.viewPortDefaults = viewPortConfig; + return this; }; - /**@internal */ - NavigationInstruction.prototype._buildTitle = function (separator) { - if (separator === void 0) { separator = ' | '; } - var title = ''; - var childTitles = []; - var navModelTitle = this.config.navModel.title; - var instructionRouter = this.router; - var viewPortInstructions = this.viewPortInstructions; - if (navModelTitle) { - title = instructionRouter.transformTitle(navModelTitle); - } - for (var viewPortName in viewPortInstructions) { - var viewPortInstruction = viewPortInstructions[viewPortName]; - var child_nav_instruction = viewPortInstruction.childNavigationInstruction; - if (child_nav_instruction) { - var childTitle = child_nav_instruction._buildTitle(separator); - if (childTitle) { - childTitles.push(childTitle); + /** + * Maps a single route to be registered with the router. + * + * @param route The [[RouteConfig]] to map. + * @chainable + */ + RouterConfiguration.prototype.mapRoute = function (config) { + this.instructions.push(function (router) { + var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); + var navModel; + for (var i = 0, ii = routeConfigs.length; i < ii; ++i) { + var routeConfig = routeConfigs[i]; + routeConfig.settings = routeConfig.settings || {}; + if (!navModel) { + navModel = router.createNavModel(routeConfig); } + router.addRoute(routeConfig, navModel); } - } - if (childTitles.length) { - title = childTitles.join(separator) + (title ? separator : '') + title; - } - if (instructionRouter.title) { - title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title); - } - return title; + }); + return this; + }; + /** + * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes. + * + * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the + * [[NavigationInstruction]] and selects a moduleId to load. + * @chainable + */ + RouterConfiguration.prototype.mapUnknownRoutes = function (config) { + this.unknownRouteConfig = config; + return this; }; - return NavigationInstruction; -}()); -var prune = function (instruction) { - instruction.previousInstruction = null; - instruction.plan = null; -}; - -/** -* Class for storing and interacting with a route's navigation settings. -*/ -var NavModel = /** @class */ (function () { - function NavModel(router, relativeHref) { - /** - * True if this nav item is currently active. - */ - this.isActive = false; - /** - * The title. - */ - this.title = null; - /** - * This nav item's absolute href. - */ - this.href = null; - /** - * This nav item's relative href. - */ - this.relativeHref = null; - /** - * Data attached to the route at configuration time. - */ - this.settings = {}; - /** - * The route config. - */ - this.config = null; - this.router = router; - this.relativeHref = relativeHref; - } /** - * Sets the route's title and updates document.title. - * If the a navigation is in progress, the change will be applied - * to document.title when the navigation completes. - * - * @param title The new title. - */ - NavModel.prototype.setTitle = function (title) { - this.title = title; - if (this.isActive) { - this.router.updateTitle(); + * Applies the current configuration to the specified [[Router]]. + * + * @param router The [[Router]] to apply the configuration to. + */ + RouterConfiguration.prototype.exportToRouter = function (router) { + var instructions = this.instructions; + for (var i = 0, ii = instructions.length; i < ii; ++i) { + instructions[i](router); + } + var _a = this, title = _a.title, titleSeparator = _a.titleSeparator, unknownRouteConfig = _a.unknownRouteConfig, _fallbackRoute = _a._fallbackRoute, viewPortDefaults = _a.viewPortDefaults; + if (title) { + router.title = title; + } + if (titleSeparator) { + router.titleSeparator = titleSeparator; + } + if (unknownRouteConfig) { + router.handleUnknownRoutes(unknownRouteConfig); + } + if (_fallbackRoute) { + router.fallbackRoute = _fallbackRoute; + } + if (viewPortDefaults) { + router.useViewPortDefaults(viewPortDefaults); + } + Object.assign(router.options, this.options); + var pipelineSteps = this.pipelineSteps; + var pipelineStepCount = pipelineSteps.length; + if (pipelineStepCount) { + if (!router.isRoot) { + throw new Error('Pipeline steps can only be added to the root router'); + } + var pipelineProvider = router.pipelineProvider; + for (var i = 0, ii = pipelineStepCount; i < ii; ++i) { + var _b = pipelineSteps[i], name_1 = _b.name, step = _b.step; + pipelineProvider.addStep(name_1, step); + } } }; - return NavModel; + return RouterConfiguration; }()); -function _normalizeAbsolutePath(path, hasPushState, absolute) { - if (absolute === void 0) { absolute = false; } - if (!hasPushState && path[0] !== '#') { - path = '#' + path; - } - if (hasPushState && absolute) { - path = path.substring(1, path.length); - } - return path; -} -function _createRootedPath(fragment, baseUrl, hasPushState, absolute) { - if (isAbsoluteUrl.test(fragment)) { - return fragment; - } - var path = ''; - if (baseUrl.length && baseUrl[0] !== '/') { - path += '/'; - } - path += baseUrl; - if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') { - path += '/'; - } - if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') { - path = path.substring(0, path.length - 1); - } - return _normalizeAbsolutePath(path + fragment, hasPushState, absolute); -} -function _resolveUrl(fragment, baseUrl, hasPushState) { - if (isRootedPath.test(fragment)) { - return _normalizeAbsolutePath(fragment, hasPushState); - } - return _createRootedPath(fragment, baseUrl, hasPushState); -} -function _ensureArrayWithSingleRoutePerConfig(config) { - var routeConfigs = []; - if (Array.isArray(config.route)) { - for (var i = 0, ii = config.route.length; i < ii; ++i) { - var current = Object.assign({}, config); - current.route = config.route[i]; - routeConfigs.push(current); - } - } - else { - routeConfigs.push(Object.assign({}, config)); - } - return routeConfigs; -} -var isRootedPath = /^#?\//; -var isAbsoluteUrl = /^([a-z][a-z0-9+\-.]*:)?\/\//i; - /** - * Class used to configure a [[Router]] instance. - * - * @constructor + * The primary class responsible for handling routing and navigation. */ -var RouterConfiguration = /** @class */ (function () { - function RouterConfiguration() { - this.instructions = []; +var Router = /** @class */ (function () { + /** + * @param container The [[Container]] to use when child routers. + * @param history The [[History]] implementation to delegate navigation requests to. + */ + function Router(container, history) { + var _this = this; + /** + * The parent router, or null if this instance is not a child router. + */ + this.parent = null; this.options = {}; - this.pipelineSteps = []; + /** + * The defaults used when a viewport lacks specified content + */ + this.viewPortDefaults = {}; + /** + * Extension point to transform the document title before it is built and displayed. + * By default, child routers delegate to the parent router, and the app router + * returns the title unchanged. + */ + this.transformTitle = function (title) { + if (_this.parent) { + return _this.parent.transformTitle(title); + } + return title; + }; + this.container = container; + this.history = history; + this.reset(); } /** - * Adds a step to be run during the [[Router]]'s navigation pipeline. - * - * @param name The name of the pipeline slot to insert the step into. - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPipelineStep = function (name, step) { - if (step === null || step === undefined) { - throw new Error('Pipeline step cannot be null or undefined.'); + * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. + * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. + */ + Router.prototype.reset = function () { + var _this = this; + this.viewPorts = {}; + this.routes = []; + this.baseUrl = ''; + this.isConfigured = false; + this.isNavigating = false; + this.isExplicitNavigation = false; + this.isExplicitNavigationBack = false; + this.isNavigatingFirst = false; + this.isNavigatingNew = false; + this.isNavigatingRefresh = false; + this.isNavigatingForward = false; + this.isNavigatingBack = false; + this.couldDeactivate = false; + this.navigation = []; + this.currentInstruction = null; + this.viewPortDefaults = {}; + this._fallbackOrder = 100; + this._recognizer = new aureliaRouteRecognizer.RouteRecognizer(); + this._childRecognizer = new aureliaRouteRecognizer.RouteRecognizer(); + this._configuredPromise = new Promise(function (resolve) { + _this._resolveConfiguredPromise = resolve; + }); + }; + Object.defineProperty(Router.prototype, "isRoot", { + /** + * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent. + */ + get: function () { + return !this.parent; + }, + enumerable: true, + configurable: true + }); + /** + * Registers a viewPort to be used as a rendering target for activated routes. + * + * @param viewPort The viewPort. + * @param name The name of the viewPort. 'default' if unspecified. + */ + Router.prototype.registerViewPort = function (viewPort, name) { + name = name || 'default'; + this.viewPorts[name] = viewPort; + }; + /** + * Returns a Promise that resolves when the router is configured. + */ + Router.prototype.ensureConfigured = function () { + return this._configuredPromise; + }; + /** + * Configures the router. + * + * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]]. + */ + Router.prototype.configure = function (callbackOrConfig) { + var _this = this; + this.isConfigured = true; + var result = callbackOrConfig; + var config; + if (typeof callbackOrConfig === 'function') { + config = new RouterConfiguration(); + result = callbackOrConfig(config); } - this.pipelineSteps.push({ name: name, step: step }); - return this; + return Promise + .resolve(result) + .then(function (c) { + if (c && c.exportToRouter) { + config = c; + } + config.exportToRouter(_this); + _this.isConfigured = true; + _this._resolveConfiguredPromise(); + }); }; /** - * Adds a step to be run during the [[Router]]'s authorize pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addAuthorizeStep = function (step) { - return this.addPipelineStep("authorize" /* Authorize */, step); + * Navigates to a new location. + * + * @param fragment The URL fragment to use as the navigation destination. + * @param options The navigation options. + */ + Router.prototype.navigate = function (fragment, options) { + if (!this.isConfigured && this.parent) { + return this.parent.navigate(fragment, options); + } + this.isExplicitNavigation = true; + return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options); }; /** - * Adds a step to be run during the [[Router]]'s preActivate pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPreActivateStep = function (step) { - return this.addPipelineStep("preActivate" /* PreActivate */, step); + * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed + * by [[Router.navigate]]. + * + * @param route The name of the route to use when generating the navigation location. + * @param params The route parameters to be used when populating the route pattern. + * @param options The navigation options. + */ + Router.prototype.navigateToRoute = function (route, params, options) { + var path = this.generate(route, params); + return this.navigate(path, options); + }; + /** + * Navigates back to the most recent location in history. + */ + Router.prototype.navigateBack = function () { + this.isExplicitNavigationBack = true; + this.history.navigateBack(); + }; + /** + * Creates a child router of the current router. + * + * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified. + * @returns {Router} The new child Router. + */ + Router.prototype.createChild = function (container) { + var childRouter = new Router(container || this.container.createChild(), this.history); + childRouter.parent = this; + return childRouter; + }; + /** + * Generates a URL fragment matching the specified route pattern. + * + * @param name The name of the route whose pattern should be used to generate the fragment. + * @param params The route params to be used to populate the route pattern. + * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url. + * @returns {string} A string containing the generated URL fragment. + */ + Router.prototype.generate = function (nameOrRoute, params, options) { + if (params === void 0) { params = {}; } + if (options === void 0) { options = {}; } + // A child recognizer generates routes for potential child routes. Any potential child route is added + // to the childRoute property of params for the childRouter to recognize. When generating routes, we + // use the childRecognizer when childRoute params are available to generate a child router enabled route. + var recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer; + var hasRoute = recognizer.hasRoute(nameOrRoute); + if (!hasRoute) { + if (this.parent) { + return this.parent.generate(nameOrRoute, params, options); + } + throw new Error("A route with name '" + nameOrRoute + "' could not be found. Check that `name: '" + nameOrRoute + "'` was specified in the route's config."); + } + var path = recognizer.generate(nameOrRoute, params); + var rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute); + return options.absolute ? "" + this.history.getAbsoluteRoot() + rootedPath : rootedPath; }; /** - * Adds a step to be run during the [[Router]]'s preRender pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPreRenderStep = function (step) { - return this.addPipelineStep("preRender" /* PreRender */, step); + * Creates a [[NavModel]] for the specified route config. + * + * @param config The route config. + */ + Router.prototype.createNavModel = function (config) { + var navModel = new NavModel(this, 'href' in config + ? config.href + // potential error when config.route is a string[] ? + : config.route); + navModel.title = config.title; + navModel.order = config.nav; + navModel.href = config.href; + navModel.settings = config.settings; + navModel.config = config; + return navModel; }; /** - * Adds a step to be run during the [[Router]]'s postRender pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPostRenderStep = function (step) { - return this.addPipelineStep("postRender" /* PostRender */, step); + * Registers a new route with the router. + * + * @param config The [[RouteConfig]]. + * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes. + */ + Router.prototype.addRoute = function (config, navModel) { + if (Array.isArray(config.route)) { + var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); + // the following is wrong. todo: fix this after TS refactoring release + routeConfigs.forEach(this.addRoute.bind(this)); + return; + } + validateRouteConfig(config); + if (!('viewPorts' in config) && !config.navigationStrategy) { + config.viewPorts = { + 'default': { + moduleId: config.moduleId, + view: config.view + } + }; + } + if (!navModel) { + navModel = this.createNavModel(config); + } + this.routes.push(config); + var path = config.route; + if (path.charAt(0) === '/') { + path = path.substr(1); + } + var caseSensitive = config.caseSensitive === true; + var state = this._recognizer.add({ + path: path, + handler: config, + caseSensitive: caseSensitive + }); + if (path) { + var settings = config.settings; + delete config.settings; + var withChild = JSON.parse(JSON.stringify(config)); + config.settings = settings; + withChild.route = path + "/*childRoute"; + withChild.hasChildRouter = true; + this._childRecognizer.add({ + path: withChild.route, + handler: withChild, + caseSensitive: caseSensitive + }); + withChild.navModel = navModel; + withChild.settings = config.settings; + withChild.navigationStrategy = config.navigationStrategy; + } + config.navModel = navModel; + var navigation = this.navigation; + if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) { + if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) { + throw new Error('Invalid route config for "' + config.route + '" : dynamic routes must specify an "href:" to be included in the navigation model.'); + } + if (typeof navModel.order !== 'number') { + navModel.order = ++this._fallbackOrder; + } + navigation.push(navModel); + // this is a potential error / inconsistency between browsers + // + // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort + // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, + // but sorted with respect to all different elements. + // Note: the ECMAscript standard does not guarantee this behaviour, + // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this. + navigation.sort(function (a, b) { return a.order - b.order; }); + } }; /** - * Configures a route that will be used if there is no previous location available on navigation cancellation. - * - * @param fragment The URL fragment to use as the navigation destination. - * @chainable - */ - RouterConfiguration.prototype.fallbackRoute = function (fragment) { - this._fallbackRoute = fragment; - return this; + * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name. + * + * @param name The name of the route to check. + */ + Router.prototype.hasRoute = function (name) { + return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name)); }; /** - * Maps one or more routes to be registered with the router. - * - * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map. - * @chainable - */ - RouterConfiguration.prototype.map = function (route) { - if (Array.isArray(route)) { - route.forEach(this.map.bind(this)); - return this; - } - return this.mapRoute(route); + * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name. + * + * @param name The name of the route to check. + */ + Router.prototype.hasOwnRoute = function (name) { + return this._recognizer.hasRoute(name); }; /** - * Configures defaults to use for any view ports. + * Register a handler to use when the incoming URL fragment doesn't match any registered routes. * - * @param viewPortConfig a view port configuration object to use as a - * default, of the form { viewPortName: { moduleId } }. - * @chainable + * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]]. */ - RouterConfiguration.prototype.useViewPortDefaults = function (viewPortConfig) { - this.viewPortDefaults = viewPortConfig; - return this; + Router.prototype.handleUnknownRoutes = function (config) { + var _this = this; + if (!config) { + throw new Error('Invalid unknown route handler'); + } + this.catchAllHandler = function (instruction) { + return _this + ._createRouteConfig(config, instruction) + .then(function (c) { + instruction.config = c; + return instruction; + }); + }; }; /** - * Maps a single route to be registered with the router. - * - * @param route The [[RouteConfig]] to map. - * @chainable - */ - RouterConfiguration.prototype.mapRoute = function (config) { - this.instructions.push(function (router) { - var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); - var navModel; - for (var i = 0, ii = routeConfigs.length; i < ii; ++i) { - var routeConfig = routeConfigs[i]; - routeConfig.settings = routeConfig.settings || {}; - if (!navModel) { - navModel = router.createNavModel(routeConfig); - } - router.addRoute(routeConfig, navModel); - } - }); - return this; + * Updates the document title using the current navigation instruction. + */ + Router.prototype.updateTitle = function () { + var parentRouter = this.parent; + if (parentRouter) { + return parentRouter.updateTitle(); + } + var currentInstruction = this.currentInstruction; + if (currentInstruction) { + currentInstruction._updateTitle(); + } + return undefined; }; /** - * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes. - * - * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the - * [[NavigationInstruction]] and selects a moduleId to load. - * @chainable - */ - RouterConfiguration.prototype.mapUnknownRoutes = function (config) { - this.unknownRouteConfig = config; - return this; + * Updates the navigation routes with hrefs relative to the current location. + * Note: This method will likely move to a plugin in a future release. + */ + Router.prototype.refreshNavigation = function () { + var nav = this.navigation; + for (var i = 0, length_1 = nav.length; i < length_1; i++) { + var current = nav[i]; + if (!current.config.href) { + current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState); + } + else { + current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState); + } + } }; /** - * Applies the current configuration to the specified [[Router]]. - * - * @param router The [[Router]] to apply the configuration to. - */ - RouterConfiguration.prototype.exportToRouter = function (router) { - var instructions = this.instructions; - for (var i = 0, ii = instructions.length; i < ii; ++i) { - instructions[i](router); + * Sets the default configuration for the view ports. This specifies how to + * populate a view port for which no module is specified. The default is + * an empty view/view-model pair. + */ + Router.prototype.useViewPortDefaults = function ($viewPortDefaults) { + // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction + var viewPortDefaults = $viewPortDefaults; + for (var viewPortName in viewPortDefaults) { + var viewPortConfig = viewPortDefaults[viewPortName]; + this.viewPortDefaults[viewPortName] = { + moduleId: viewPortConfig.moduleId + }; + } + }; + /**@internal */ + Router.prototype._refreshBaseUrl = function () { + var parentRouter = this.parent; + if (parentRouter) { + this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction); + } + }; + /**@internal */ + Router.prototype._createNavigationInstruction = function (url, parentInstruction) { + if (url === void 0) { url = ''; } + if (parentInstruction === void 0) { parentInstruction = null; } + var fragment = url; + var queryString = ''; + var queryIndex = url.indexOf('?'); + if (queryIndex !== -1) { + fragment = url.substr(0, queryIndex); + queryString = url.substr(queryIndex + 1); + } + var urlRecognizationResults = this._recognizer.recognize(url); + if (!urlRecognizationResults || !urlRecognizationResults.length) { + urlRecognizationResults = this._childRecognizer.recognize(url); + } + var instructionInit = { + fragment: fragment, + queryString: queryString, + config: null, + parentInstruction: parentInstruction, + previousInstruction: this.currentInstruction, + router: this, + options: { + compareQueryParams: this.options.compareQueryParams + } + }; + var result; + if (urlRecognizationResults && urlRecognizationResults.length) { + var first = urlRecognizationResults[0]; + var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: first.params, + queryParams: first.queryParams || urlRecognizationResults.queryParams, + config: first.config || first.handler + })); + if (typeof first.handler === 'function') { + result = evaluateNavigationStrategy(instruction, first.handler, first); + } + else if (first.handler && typeof first.handler.navigationStrategy === 'function') { + result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); + } + else { + result = Promise.resolve(instruction); + } + } + else if (this.catchAllHandler) { + var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: { path: fragment }, + queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, + config: null // config will be created by the catchAllHandler + })); + result = evaluateNavigationStrategy(instruction, this.catchAllHandler); + } + else if (this.parent) { + var router = this._parentCatchAllHandler(this.parent); + if (router) { + var newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction); + var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: { path: fragment }, + queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, + router: router, + parentInstruction: newParentInstruction, + parentCatchHandler: true, + config: null // config will be created by the chained parent catchAllHandler + })); + result = evaluateNavigationStrategy(instruction, router.catchAllHandler); + } } - if (this.title) { - router.title = this.title; + if (result && parentInstruction) { + this.baseUrl = generateBaseUrl(this.parent, parentInstruction); } - if (this.titleSeparator) { - router.titleSeparator = this.titleSeparator; + return result || Promise.reject(new Error("Route not found: " + url)); + }; + /**@internal */ + Router.prototype._findParentInstructionFromRouter = function (router, instruction) { + if (instruction.router === router) { + instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId + return instruction; } - if (this.unknownRouteConfig) { - router.handleUnknownRoutes(this.unknownRouteConfig); + else if (instruction.parentInstruction) { + return this._findParentInstructionFromRouter(router, instruction.parentInstruction); } - if (this._fallbackRoute) { - router.fallbackRoute = this._fallbackRoute; + return undefined; + }; + /**@internal */ + Router.prototype._parentCatchAllHandler = function (router) { + if (router.catchAllHandler) { + return router; } - if (this.viewPortDefaults) { - router.useViewPortDefaults(this.viewPortDefaults); + else if (router.parent) { + return this._parentCatchAllHandler(router.parent); } - Object.assign(router.options, this.options); - var pipelineSteps = this.pipelineSteps; - if (pipelineSteps.length) { - if (!router.isRoot) { - throw new Error('Pipeline steps can only be added to the root router'); + return false; + }; + /** + * @internal + */ + Router.prototype._createRouteConfig = function (config, instruction) { + var _this = this; + return Promise + .resolve(config) + .then(function (c) { + if (typeof c === 'string') { + return { moduleId: c }; } - var pipelineProvider = router.pipelineProvider; - for (var i = 0, ii = pipelineSteps.length; i < ii; ++i) { - var _a = pipelineSteps[i], name_1 = _a.name, step = _a.step; - pipelineProvider.addStep(name_1, step); + else if (typeof c === 'function') { + return c(instruction); + } + return c; + }) + // typing here could be either RouteConfig or RedirectConfig + // but temporarily treat both as RouteConfig + // todo: improve typings precision + .then(function (c) { return typeof c === 'string' ? { moduleId: c } : c; }) + .then(function (c) { + c.route = instruction.params.path; + validateRouteConfig(c); + if (!c.navModel) { + c.navModel = _this.createNavModel(c); + } + return c; + }); + }; + return Router; +}()); +/* @internal exported for unit testing */ +var generateBaseUrl = function (router, instruction) { + return "" + (router.baseUrl || '') + (instruction.getBaseUrl() || ''); +}; +/* @internal exported for unit testing */ +var validateRouteConfig = function (config) { + if (typeof config !== 'object') { + throw new Error('Invalid Route Config'); + } + if (typeof config.route !== 'string') { + var name_1 = config.name || '(no name)'; + throw new Error('Invalid Route Config for "' + name_1 + '": You must specify a "route:" pattern.'); + } + if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) { + throw new Error('Invalid Route Config for "' + config.route + '": You must specify a "moduleId:", "redirect:", "navigationStrategy:", or "viewPorts:".'); + } +}; +/* @internal exported for unit testing */ +var evaluateNavigationStrategy = function (instruction, evaluator, context) { + return Promise + .resolve(evaluator.call(context, instruction)) + .then(function () { + if (!('viewPorts' in instruction.config)) { + instruction.config.viewPorts = { + 'default': { + moduleId: instruction.config.moduleId + } + }; + } + return instruction; + }); +}; + +/**@internal exported for unit testing */ +var createNextFn = function (instruction, steps) { + var index = -1; + var next = function () { + index++; + if (index < steps.length) { + var currentStep = steps[index]; + try { + return currentStep(instruction, next); + } + catch (e) { + return next.reject(e); } } + else { + return next.complete(); + } }; - return RouterConfiguration; -}()); + next.complete = createCompletionHandler(next, "completed" /* Completed */); + next.cancel = createCompletionHandler(next, "canceled" /* Canceled */); + next.reject = createCompletionHandler(next, "rejected" /* Rejected */); + return next; +}; +/**@internal exported for unit testing */ +var createCompletionHandler = function (next, status) { + return function (output) { return Promise + .resolve({ + status: status, + output: output, + completed: status === "completed" /* Completed */ + }); }; +}; /** - * The primary class responsible for handling routing and navigation. + * The class responsible for managing and processing the navigation pipeline. */ -var Router = /** @class */ (function () { - /** - * @param container The [[Container]] to use when child routers. - * @param history The [[History]] implementation to delegate navigation requests to. - */ - function Router(container, history) { - var _this = this; - /** - * The parent router, or null if this instance is not a child router. - */ - this.parent = null; - this.options = {}; - /** - * The defaults used when a viewport lacks specified content - */ - this.viewPortDefaults = {}; +var Pipeline = /** @class */ (function () { + function Pipeline() { /** - * Extension point to transform the document title before it is built and displayed. - * By default, child routers delegate to the parent router, and the app router - * returns the title unchanged. - */ - this.transformTitle = function (title) { - if (_this.parent) { - return _this.parent.transformTitle(title); - } - return title; - }; - this.container = container; - this.history = history; - this.reset(); + * The pipeline steps. And steps added via addStep will be converted to a function + * The actualy running functions with correct step contexts of this pipeline + */ + this.steps = []; } /** - * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. - * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. - */ - Router.prototype.reset = function () { - var _this = this; - this.viewPorts = {}; - this.routes = []; - this.baseUrl = ''; - this.isConfigured = false; - this.isNavigating = false; - this.isExplicitNavigation = false; - this.isExplicitNavigationBack = false; - this.isNavigatingFirst = false; - this.isNavigatingNew = false; - this.isNavigatingRefresh = false; - this.isNavigatingForward = false; - this.isNavigatingBack = false; - this.couldDeactivate = false; - this.navigation = []; - this.currentInstruction = null; - this.viewPortDefaults = {}; - this._fallbackOrder = 100; - this._recognizer = new aureliaRouteRecognizer.RouteRecognizer(); - this._childRecognizer = new aureliaRouteRecognizer.RouteRecognizer(); - this._configuredPromise = new Promise(function (resolve) { - _this._resolveConfiguredPromise = resolve; - }); - }; - Object.defineProperty(Router.prototype, "isRoot", { - /** - * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent. - */ - get: function () { - return !this.parent; - }, - enumerable: true, - configurable: true - }); - /** - * Registers a viewPort to be used as a rendering target for activated routes. - * - * @param viewPort The viewPort. - * @param name The name of the viewPort. 'default' if unspecified. - */ - Router.prototype.registerViewPort = function (viewPort, name) { - name = name || 'default'; - this.viewPorts[name] = viewPort; - }; - /** - * Returns a Promise that resolves when the router is configured. - */ - Router.prototype.ensureConfigured = function () { - return this._configuredPromise; - }; - /** - * Configures the router. - * - * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]]. - */ - Router.prototype.configure = function (callbackOrConfig) { - var _this = this; - this.isConfigured = true; - var result = callbackOrConfig; - var config; - if (typeof callbackOrConfig === 'function') { - config = new RouterConfiguration(); - result = callbackOrConfig(config); + * Adds a step to the pipeline. + * + * @param step The pipeline step. + */ + Pipeline.prototype.addStep = function (step) { + var run; + if (typeof step === 'function') { + run = step; } - return Promise - .resolve(result) - .then(function (c) { - if (c && c.exportToRouter) { - config = c; + else if (typeof step.getSteps === 'function') { + // getSteps is to enable support open slots + // where devs can add multiple steps into the same slot name + var steps = step.getSteps(); + for (var i = 0, l = steps.length; i < l; i++) { + this.addStep(steps[i]); } - config.exportToRouter(_this); - _this.isConfigured = true; - _this._resolveConfiguredPromise(); - }); - }; - /** - * Navigates to a new location. - * - * @param fragment The URL fragment to use as the navigation destination. - * @param options The navigation options. - */ - Router.prototype.navigate = function (fragment, options) { - if (!this.isConfigured && this.parent) { - return this.parent.navigate(fragment, options); + return this; } - this.isExplicitNavigation = true; - return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options); + else { + run = step.run.bind(step); + } + this.steps.push(run); + return this; }; /** - * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed - * by [[Router.navigate]]. - * - * @param route The name of the route to use when generating the navigation location. - * @param params The route parameters to be used when populating the route pattern. - * @param options The navigation options. - */ - Router.prototype.navigateToRoute = function (route, params, options) { - var path = this.generate(route, params); - return this.navigate(path, options); + * Runs the pipeline. + * + * @param instruction The navigation instruction to process. + */ + Pipeline.prototype.run = function (instruction) { + var nextFn = createNextFn(instruction, this.steps); + return nextFn(); }; + return Pipeline; +}()); + +/** +* Determines if the provided object is a navigation command. +* A navigation command is anything with a navigate method. +* +* @param obj The object to check. +*/ +function isNavigationCommand(obj) { + return obj && typeof obj.navigate === 'function'; +} +/** +* Used during the activation lifecycle to cause a redirect. +*/ +var Redirect = /** @class */ (function () { /** - * Navigates back to the most recent location in history. - */ - Router.prototype.navigateBack = function () { - this.isExplicitNavigationBack = true; - this.history.navigateBack(); + * @param url The URL fragment to use as the navigation destination. + * @param options The navigation options. + */ + function Redirect(url, options) { + if (options === void 0) { options = {}; } + this.url = url; + this.options = Object.assign({ trigger: true, replace: true }, options); + this.shouldContinueProcessing = false; + } + /** + * Called by the activation system to set the child router. + * + * @param router The router. + */ + Redirect.prototype.setRouter = function (router) { + this.router = router; }; /** - * Creates a child router of the current router. + * Called by the navigation pipeline to navigate. * - * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified. - * @returns {Router} The new child Router. + * @param appRouter The router to be redirected. */ - Router.prototype.createChild = function (container) { - var childRouter = new Router(container || this.container.createChild(), this.history); - childRouter.parent = this; - return childRouter; + Redirect.prototype.navigate = function (appRouter) { + var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); + navigatingRouter.navigate(this.url, this.options); }; + return Redirect; +}()); +/** + * Used during the activation lifecycle to cause a redirect to a named route. + */ +var RedirectToRoute = /** @class */ (function () { /** - * Generates a URL fragment matching the specified route pattern. - * - * @param name The name of the route whose pattern should be used to generate the fragment. - * @param params The route params to be used to populate the route pattern. - * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url. - * @returns {string} A string containing the generated URL fragment. - */ - Router.prototype.generate = function (nameOrRoute, params, options) { + * @param route The name of the route. + * @param params The parameters to be sent to the activation method. + * @param options The options to use for navigation. + */ + function RedirectToRoute(route, params, options) { if (params === void 0) { params = {}; } if (options === void 0) { options = {}; } - // A child recognizer generates routes for potential child routes. Any potential child route is added - // to the childRoute property of params for the childRouter to recognize. When generating routes, we - // use the childRecognizer when childRoute params are available to generate a child router enabled route. - var recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer; - var hasRoute = recognizer.hasRoute(nameOrRoute); - if (!hasRoute) { - if (this.parent) { - return this.parent.generate(nameOrRoute, params, options); - } - throw new Error("A route with name '" + nameOrRoute + "' could not be found. Check that `name: '" + nameOrRoute + "'` was specified in the route's config."); - } - var path = recognizer.generate(nameOrRoute, params); - var rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute); - return options.absolute ? "" + this.history.getAbsoluteRoot() + rootedPath : rootedPath; - }; + this.route = route; + this.params = params; + this.options = Object.assign({ trigger: true, replace: true }, options); + this.shouldContinueProcessing = false; + } /** - * Creates a [[NavModel]] for the specified route config. - * - * @param config The route config. - */ - Router.prototype.createNavModel = function (config) { - var navModel = new NavModel(this, 'href' in config - ? config.href - // potential error when config.route is a string[] ? - : config.route); - navModel.title = config.title; - navModel.order = config.nav; - navModel.href = config.href; - navModel.settings = config.settings; - navModel.config = config; - return navModel; + * Called by the activation system to set the child router. + * + * @param router The router. + */ + RedirectToRoute.prototype.setRouter = function (router) { + this.router = router; }; /** - * Registers a new route with the router. - * - * @param config The [[RouteConfig]]. - * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes. - */ - Router.prototype.addRoute = function (config, navModel) { - if (Array.isArray(config.route)) { - var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); - // the following is wrong. todo: fix this after TS refactoring release - routeConfigs.forEach(this.addRoute.bind(this)); - return; - } - validateRouteConfig(config); - if (!('viewPorts' in config) && !config.navigationStrategy) { - config.viewPorts = { - 'default': { - moduleId: config.moduleId, - view: config.view + * Called by the navigation pipeline to navigate. + * + * @param appRouter The router to be redirected. + */ + RedirectToRoute.prototype.navigate = function (appRouter) { + var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); + navigatingRouter.navigateToRoute(this.route, this.params, this.options); + }; + return RedirectToRoute; +}()); + +/** + * @internal exported for unit testing + */ +function _buildNavigationPlan(instruction, forceLifecycleMinimum) { + var config = instruction.config; + if ('redirect' in config) { + return buildRedirectPlan(instruction); + } + var prevInstruction = instruction.previousInstruction; + var defaultViewPortConfigs = instruction.router.viewPortDefaults; + if (prevInstruction) { + return buildTransitionPlans(instruction, prevInstruction, defaultViewPortConfigs, forceLifecycleMinimum); + } + // first navigation, only need to prepare a few information for each viewport plan + var viewPortPlans = {}; + var viewPortConfigs = config.viewPorts; + for (var viewPortName in viewPortConfigs) { + var viewPortConfig = viewPortConfigs[viewPortName]; + if (viewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) { + viewPortConfig = defaultViewPortConfigs[viewPortName]; + } + viewPortPlans[viewPortName] = { + name: viewPortName, + strategy: "replace" /* Replace */, + config: viewPortConfig + }; + } + return Promise.resolve(viewPortPlans); +} +/** + * Build redirect plan based on config of a navigation instruction + * @internal exported for unit testing + */ +var buildRedirectPlan = function (instruction) { + var config = instruction.config; + var router = instruction.router; + return router + ._createNavigationInstruction(config.redirect) + .then(function (redirectInstruction) { + var params = {}; + var originalInstructionParams = instruction.params; + var redirectInstructionParams = redirectInstruction.params; + for (var key in redirectInstructionParams) { + // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this } + var val = redirectInstructionParams[key]; + if (typeof val === 'string' && val[0] === ':') { + val = val.slice(1); + // And if that param is found on the original instruction then use it + if (val in originalInstructionParams) { + params[key] = originalInstructionParams[val]; } - }; + } + else { + params[key] = redirectInstructionParams[key]; + } } - if (!navModel) { - navModel = this.createNavModel(config); + var redirectLocation = router.generate(redirectInstruction.config, params, instruction.options); + // Special handling for child routes + for (var key in originalInstructionParams) { + redirectLocation = redirectLocation.replace(":" + key, originalInstructionParams[key]); } - this.routes.push(config); - var path = config.route; - if (path.charAt(0) === '/') { - path = path.substr(1); + var queryString = instruction.queryString; + if (queryString) { + redirectLocation += '?' + queryString; } - var caseSensitive = config.caseSensitive === true; - var state = this._recognizer.add({ - path: path, - handler: config, - caseSensitive: caseSensitive + return Promise.resolve(new Redirect(redirectLocation)); + }); +}; +/** + * @param viewPortPlans the Plan record that holds information about built plans + * @internal exported for unit testing + */ +var buildTransitionPlans = function (currentInstruction, previousInstruction, defaultViewPortConfigs, forceLifecycleMinimum) { + var viewPortPlans = {}; + var newInstructionConfig = currentInstruction.config; + var hasNewParams = hasDifferentParameterValues(previousInstruction, currentInstruction); + var pending = []; + var previousViewPortInstructions = previousInstruction.viewPortInstructions; + var _loop_1 = function (viewPortName) { + var prevViewPortInstruction = previousViewPortInstructions[viewPortName]; + var prevViewPortComponent = prevViewPortInstruction.component; + var newInstructionViewPortConfigs = newInstructionConfig.viewPorts; + // if this is invoked on a viewport without any changes, based on new url, + // newViewPortConfig will be the existing viewport instruction + var nextViewPortConfig = viewPortName in newInstructionViewPortConfigs + ? newInstructionViewPortConfigs[viewPortName] + : prevViewPortInstruction; + if (nextViewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) { + nextViewPortConfig = defaultViewPortConfigs[viewPortName]; + } + var viewPortActivationStrategy = determineActivationStrategy(currentInstruction, prevViewPortInstruction, nextViewPortConfig, hasNewParams, forceLifecycleMinimum); + var viewPortPlan = viewPortPlans[viewPortName] = { + name: viewPortName, + // ViewPortInstruction can quack like a RouteConfig + config: nextViewPortConfig, + prevComponent: prevViewPortComponent, + prevModuleId: prevViewPortInstruction.moduleId, + strategy: viewPortActivationStrategy + }; + // recursively build nav plans for all existing child routers/viewports of this viewport + // this is possible because existing child viewports and routers already have necessary information + // to process the wildcard path from parent instruction + if (viewPortActivationStrategy !== "replace" /* Replace */ && prevViewPortInstruction.childRouter) { + var path = currentInstruction.getWildcardPath(); + var task = prevViewPortInstruction + .childRouter + ._createNavigationInstruction(path, currentInstruction) + .then(function (childInstruction) { + viewPortPlan.childNavigationInstruction = childInstruction; + return _buildNavigationPlan(childInstruction, + // is it safe to assume viewPortPlan has not been changed from previous assignment? + // if so, can just use local variable viewPortPlanStrategy + // there could be user code modifying viewport plan during _createNavigationInstruction? + viewPortPlan.strategy === "invoke-lifecycle" /* InvokeLifecycle */) + .then(function (childPlan) { + if (childPlan instanceof Redirect) { + return Promise.reject(childPlan); + } + childInstruction.plan = childPlan; + // for bluebird ? + return null; + }); + }); + pending.push(task); + } + }; + for (var viewPortName in previousViewPortInstructions) { + _loop_1(viewPortName); + } + return Promise.all(pending).then(function () { return viewPortPlans; }); +}; +/** + * @param newViewPortConfig if this is invoked on a viewport without any changes, based on new url, newViewPortConfig will be the existing viewport instruction + * @internal exported for unit testing + */ +var determineActivationStrategy = function (currentNavInstruction, prevViewPortInstruction, newViewPortConfig, +// indicates whether there is difference between old and new url params +hasNewParams, forceLifecycleMinimum) { + var newInstructionConfig = currentNavInstruction.config; + var prevViewPortViewModel = prevViewPortInstruction.component.viewModel; + var viewPortPlanStrategy; + if (prevViewPortInstruction.moduleId !== newViewPortConfig.moduleId) { + viewPortPlanStrategy = "replace" /* Replace */; + } + else if ('determineActivationStrategy' in prevViewPortViewModel) { + viewPortPlanStrategy = prevViewPortViewModel.determineActivationStrategy.apply(prevViewPortViewModel, currentNavInstruction.lifecycleArgs); + } + else if (newInstructionConfig.activationStrategy) { + viewPortPlanStrategy = newInstructionConfig.activationStrategy; + } + else if (hasNewParams || forceLifecycleMinimum) { + viewPortPlanStrategy = "invoke-lifecycle" /* InvokeLifecycle */; + } + else { + viewPortPlanStrategy = "no-change" /* NoChange */; + } + return viewPortPlanStrategy; +}; +/**@internal exported for unit testing */ +var hasDifferentParameterValues = function (prev, next) { + var prevParams = prev.params; + var nextParams = next.params; + var nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; + for (var key in nextParams) { + if (key === nextWildCardName) { + continue; + } + if (prevParams[key] !== nextParams[key]) { + return true; + } + } + for (var key in prevParams) { + if (key === nextWildCardName) { + continue; + } + if (prevParams[key] !== nextParams[key]) { + return true; + } + } + if (!next.options.compareQueryParams) { + return false; + } + var prevQueryParams = prev.queryParams; + var nextQueryParams = next.queryParams; + for (var key in nextQueryParams) { + if (prevQueryParams[key] !== nextQueryParams[key]) { + return true; + } + } + for (var key in prevQueryParams) { + if (prevQueryParams[key] !== nextQueryParams[key]) { + return true; + } + } + return false; +}; + +/** + * Transform a navigation instruction into viewport plan record object, + * or a redirect request if user viewmodel demands + */ +var BuildNavigationPlanStep = /** @class */ (function () { + function BuildNavigationPlanStep() { + } + BuildNavigationPlanStep.prototype.run = function (navigationInstruction, next) { + return _buildNavigationPlan(navigationInstruction) + .then(function (plan) { + if (plan instanceof Redirect) { + return next.cancel(plan); + } + navigationInstruction.plan = plan; + return next(); + }) + .catch(next.cancel); + }; + return BuildNavigationPlanStep; +}()); + +/** + * @internal Exported for unit testing + */ +var loadNewRoute = function (routeLoader, navigationInstruction) { + var loadingPlans = determineLoadingPlans(navigationInstruction); + var loadPromises = loadingPlans.map(function (loadingPlan) { return loadRoute(routeLoader, loadingPlan.navigationInstruction, loadingPlan.viewPortPlan); }); + return Promise.all(loadPromises); +}; +/** + * @internal Exported for unit testing + */ +var determineLoadingPlans = function (navigationInstruction, loadingPlans) { + if (loadingPlans === void 0) { loadingPlans = []; } + var viewPortPlans = navigationInstruction.plan; + for (var viewPortName in viewPortPlans) { + var viewPortPlan = viewPortPlans[viewPortName]; + var childNavInstruction = viewPortPlan.childNavigationInstruction; + if (viewPortPlan.strategy === "replace" /* Replace */) { + loadingPlans.push({ viewPortPlan: viewPortPlan, navigationInstruction: navigationInstruction }); + if (childNavInstruction) { + determineLoadingPlans(childNavInstruction, loadingPlans); + } + } + else { + var viewPortInstruction = navigationInstruction.addViewPortInstruction({ + name: viewPortName, + strategy: viewPortPlan.strategy, + moduleId: viewPortPlan.prevModuleId, + component: viewPortPlan.prevComponent + }); + if (childNavInstruction) { + viewPortInstruction.childNavigationInstruction = childNavInstruction; + determineLoadingPlans(childNavInstruction, loadingPlans); + } + } + } + return loadingPlans; +}; +/** + * @internal Exported for unit testing + */ +var loadRoute = function (routeLoader, navigationInstruction, viewPortPlan) { + var planConfig = viewPortPlan.config; + var moduleId = planConfig ? planConfig.moduleId : null; + return loadComponent(routeLoader, navigationInstruction, planConfig) + .then(function (component) { + var viewPortInstruction = navigationInstruction.addViewPortInstruction({ + name: viewPortPlan.name, + strategy: viewPortPlan.strategy, + moduleId: moduleId, + component: component }); - if (path) { - var settings = config.settings; - delete config.settings; - var withChild = JSON.parse(JSON.stringify(config)); - config.settings = settings; - withChild.route = path + "/*childRoute"; - withChild.hasChildRouter = true; - this._childRecognizer.add({ - path: withChild.route, - handler: withChild, - caseSensitive: caseSensitive + var childRouter = component.childRouter; + if (childRouter) { + var path = navigationInstruction.getWildcardPath(); + return childRouter + ._createNavigationInstruction(path, navigationInstruction) + .then(function (childInstruction) { + viewPortPlan.childNavigationInstruction = childInstruction; + return _buildNavigationPlan(childInstruction) + .then(function (childPlan) { + if (childPlan instanceof Redirect) { + return Promise.reject(childPlan); + } + childInstruction.plan = childPlan; + viewPortInstruction.childNavigationInstruction = childInstruction; + return loadNewRoute(routeLoader, childInstruction); + }); }); - withChild.navModel = navModel; - withChild.settings = config.settings; - withChild.navigationStrategy = config.navigationStrategy; } - config.navModel = navModel; - var navigation = this.navigation; - if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) { - if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) { - throw new Error('Invalid route config for "' + config.route + '" : dynamic routes must specify an "href:" to be included in the navigation model.'); - } - if (typeof navModel.order !== 'number') { - navModel.order = ++this._fallbackOrder; - } - navigation.push(navModel); - // this is a potential error / inconsistency between browsers - // - // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort - // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, - // but sorted with respect to all different elements. - // Note: the ECMAscript standard does not guarantee this behaviour, - // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this. - navigation.sort(function (a, b) { return a.order - b.order; }); + // ts complains without this, though they are same + return void 0; + }); +}; +/** + * Load a routed-component based on navigation instruction and route config + * @internal exported for unit testing only + */ +var loadComponent = function (routeLoader, navigationInstruction, config) { + var router = navigationInstruction.router; + var lifecycleArgs = navigationInstruction.lifecycleArgs; + return Promise.resolve() + .then(function () { return routeLoader.loadRoute(router, config, navigationInstruction); }) + .then( + /** + * @param component an object carrying information about loaded route + * typically contains information about view model, childContainer, view and router + */ + function (component) { + var viewModel = component.viewModel, childContainer = component.childContainer; + component.router = router; + component.config = config; + if ('configureRouter' in viewModel) { + var childRouter_1 = childContainer.getChildRouter(); + component.childRouter = childRouter_1; + return childRouter_1 + .configure(function (c) { return viewModel.configureRouter(c, childRouter_1, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]); }) + .then(function () { return component; }); } - }; + return component; + }); +}; + +/** + * Abstract class that is responsible for loading view / view model from a route config + * The default implementation can be found in `aurelia-templating-router` + */ +var RouteLoader = /** @class */ (function () { + function RouteLoader() { + } /** - * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name. - * - * @param name The name of the route to check. - */ - Router.prototype.hasRoute = function (name) { - return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name)); + * Load a route config based on its viewmodel / view configuration + */ + // return typing: return typings used to be never + // as it was a throw. Changing it to Promise should not cause any issues + RouteLoader.prototype.loadRoute = function (router, config, navigationInstruction) { + throw new Error('Route loaders must implement "loadRoute(router, config, navigationInstruction)".'); }; + return RouteLoader; +}()); + +/** + * A pipeline step responsible for loading a route config of a navigation instruction + */ +var LoadRouteStep = /** @class */ (function () { + function LoadRouteStep(routeLoader) { + this.routeLoader = routeLoader; + } + /**@internal */ + LoadRouteStep.inject = function () { return [RouteLoader]; }; /** - * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name. - * - * @param name The name of the route to check. - */ - Router.prototype.hasOwnRoute = function (name) { - return this._recognizer.hasRoute(name); + * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline + */ + LoadRouteStep.prototype.run = function (navigationInstruction, next) { + return loadNewRoute(this.routeLoader, navigationInstruction) + .then(next, next.cancel); }; - /** - * Register a handler to use when the incoming URL fragment doesn't match any registered routes. - * - * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]]. - */ - Router.prototype.handleUnknownRoutes = function (config) { - var _this = this; - if (!config) { - throw new Error('Invalid unknown route handler'); - } - this.catchAllHandler = function (instruction) { - return _this - ._createRouteConfig(config, instruction) - .then(function (c) { - instruction.config = c; - return instruction; - }); - }; + return LoadRouteStep; +}()); + +/** + * A pipeline step for instructing a piepline to commit changes on a navigation instruction + */ +var CommitChangesStep = /** @class */ (function () { + function CommitChangesStep() { + } + CommitChangesStep.prototype.run = function (navigationInstruction, next) { + return navigationInstruction + ._commitChanges(/*wait to swap?*/ true) + .then(function () { + navigationInstruction._updateTitle(); + return next(); + }); }; + return CommitChangesStep; +}()); + +/** + * An optional interface describing the available activation strategies. + * @internal Used internally. + */ +var InternalActivationStrategy; +(function (InternalActivationStrategy) { /** - * Updates the document title using the current navigation instruction. - */ - Router.prototype.updateTitle = function () { - var parentRouter = this.parent; - if (parentRouter) { - return parentRouter.updateTitle(); - } - var currentInstruction = this.currentInstruction; - if (currentInstruction) { - currentInstruction._updateTitle(); - } - return undefined; - }; + * Reuse the existing view model, without invoking Router lifecycle hooks. + */ + InternalActivationStrategy["NoChange"] = "no-change"; /** - * Updates the navigation routes with hrefs relative to the current location. - * Note: This method will likely move to a plugin in a future release. - */ - Router.prototype.refreshNavigation = function () { - var nav = this.navigation; - for (var i = 0, length_1 = nav.length; i < length_1; i++) { - var current = nav[i]; - if (!current.config.href) { - current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState); - } - else { - current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState); - } - } - }; + * Reuse the existing view model, invoking Router lifecycle hooks. + */ + InternalActivationStrategy["InvokeLifecycle"] = "invoke-lifecycle"; /** - * Sets the default configuration for the view ports. This specifies how to - * populate a view port for which no module is specified. The default is - * an empty view/view-model pair. + * Replace the existing view model, invoking Router lifecycle hooks. */ - Router.prototype.useViewPortDefaults = function ($viewPortDefaults) { - // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction - var viewPortDefaults = $viewPortDefaults; - for (var viewPortName in viewPortDefaults) { - var viewPortConfig = viewPortDefaults[viewPortName]; - this.viewPortDefaults[viewPortName] = { - moduleId: viewPortConfig.moduleId - }; - } - }; - /**@internal */ - Router.prototype._refreshBaseUrl = function () { - var parentRouter = this.parent; - if (parentRouter) { - this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction); - } - }; - /**@internal */ - Router.prototype._createNavigationInstruction = function (url, parentInstruction) { - if (url === void 0) { url = ''; } - if (parentInstruction === void 0) { parentInstruction = null; } - var fragment = url; - var queryString = ''; - var queryIndex = url.indexOf('?'); - if (queryIndex !== -1) { - fragment = url.substr(0, queryIndex); - queryString = url.substr(queryIndex + 1); - } - var urlRecognizationResults = this._recognizer.recognize(url); - if (!urlRecognizationResults || !urlRecognizationResults.length) { - urlRecognizationResults = this._childRecognizer.recognize(url); - } - var instructionInit = { - fragment: fragment, - queryString: queryString, - config: null, - parentInstruction: parentInstruction, - previousInstruction: this.currentInstruction, - router: this, - options: { - compareQueryParams: this.options.compareQueryParams - } - }; - var result; - if (urlRecognizationResults && urlRecognizationResults.length) { - var first = urlRecognizationResults[0]; - var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: first.params, - queryParams: first.queryParams || urlRecognizationResults.queryParams, - config: first.config || first.handler - })); - if (typeof first.handler === 'function') { - result = evaluateNavigationStrategy(instruction, first.handler, first); - } - else if (first.handler && typeof first.handler.navigationStrategy === 'function') { - result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); + InternalActivationStrategy["Replace"] = "replace"; +})(InternalActivationStrategy || (InternalActivationStrategy = {})); +/** + * The strategy to use when activating modules during navigation. + */ +// kept for compat reason +var activationStrategy = { + noChange: "no-change" /* NoChange */, + invokeLifecycle: "invoke-lifecycle" /* InvokeLifecycle */, + replace: "replace" /* Replace */ +}; + +/** + * Recursively find list of deactivate-able view models + * and invoke the either 'canDeactivate' or 'deactivate' on each + * @internal exported for unit testing + */ +var processDeactivatable = function (navigationInstruction, callbackName, next, ignoreResult) { + var plan = navigationInstruction.plan; + var infos = findDeactivatable(plan, callbackName); + var i = infos.length; // query from inside out + function inspect(val) { + if (ignoreResult || shouldContinue(val)) { + return iterate(); + } + return next.cancel(val); + } + function iterate() { + if (i--) { + try { + var viewModel = infos[i]; + var result = viewModel[callbackName](navigationInstruction); + return processPotential(result, inspect, next.cancel); } - else { - result = Promise.resolve(instruction); + catch (error) { + return next.cancel(error); } } - else if (this.catchAllHandler) { - var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: { path: fragment }, - queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, - config: null // config will be created by the catchAllHandler - })); - result = evaluateNavigationStrategy(instruction, this.catchAllHandler); - } - else if (this.parent) { - var router = this._parentCatchAllHandler(this.parent); - if (router) { - var newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction); - var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: { path: fragment }, - queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, - router: router, - parentInstruction: newParentInstruction, - parentCatchHandler: true, - config: null // config will be created by the chained parent catchAllHandler - })); - result = evaluateNavigationStrategy(instruction, router.catchAllHandler); + navigationInstruction.router.couldDeactivate = true; + return next(); + } + return iterate(); +}; +/** + * Recursively find and returns a list of deactivate-able view models + * @internal exported for unit testing + */ +var findDeactivatable = function (plan, callbackName, list) { + if (list === void 0) { list = []; } + for (var viewPortName in plan) { + var viewPortPlan = plan[viewPortName]; + var prevComponent = viewPortPlan.prevComponent; + if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace) + && prevComponent) { + var viewModel = prevComponent.viewModel; + if (callbackName in viewModel) { + list.push(viewModel); } } - if (result && parentInstruction) { - this.baseUrl = generateBaseUrl(this.parent, parentInstruction); - } - return result || Promise.reject(new Error("Route not found: " + url)); - }; - /**@internal */ - Router.prototype._findParentInstructionFromRouter = function (router, instruction) { - if (instruction.router === router) { - instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId - return instruction; + if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) { + addPreviousDeactivatable(prevComponent, callbackName, list); } - else if (instruction.parentInstruction) { - return this._findParentInstructionFromRouter(router, instruction.parentInstruction); + else if (viewPortPlan.childNavigationInstruction) { + findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list); } - return undefined; - }; - /**@internal */ - Router.prototype._parentCatchAllHandler = function (router) { - if (router.catchAllHandler) { - return router; + } + return list; +}; +/** + * @internal exported for unit testing + */ +var addPreviousDeactivatable = function (component, callbackName, list) { + var childRouter = component.childRouter; + if (childRouter && childRouter.currentInstruction) { + var viewPortInstructions = childRouter.currentInstruction.viewPortInstructions; + for (var viewPortName in viewPortInstructions) { + var viewPortInstruction = viewPortInstructions[viewPortName]; + var prevComponent = viewPortInstruction.component; + var prevViewModel = prevComponent.viewModel; + if (callbackName in prevViewModel) { + list.push(prevViewModel); + } + addPreviousDeactivatable(prevComponent, callbackName, list); } - else if (router.parent) { - return this._parentCatchAllHandler(router.parent); + } +}; +/** + * @internal exported for unit testing + */ +var processActivatable = function (navigationInstruction, callbackName, next, ignoreResult) { + var infos = findActivatable(navigationInstruction, callbackName); + var length = infos.length; + var i = -1; // query from top down + function inspect(val, router) { + if (ignoreResult || shouldContinue(val, router)) { + return iterate(); } - return false; - }; - /** - * @internal - */ - Router.prototype._createRouteConfig = function (config, instruction) { - var _this = this; - return Promise - .resolve(config) - .then(function (c) { - if (typeof c === 'string') { - return { moduleId: c }; - } - else if (typeof c === 'function') { - return c(instruction); + return next.cancel(val); + } + function iterate() { + var _a; + i++; + if (i < length) { + try { + var current_1 = infos[i]; + var result = (_a = current_1.viewModel)[callbackName].apply(_a, current_1.lifecycleArgs); + return processPotential(result, function (val) { return inspect(val, current_1.router); }, next.cancel); } - return c; - }) - // typing here could be either RouteConfig or RedirectConfig - // but temporarily treat both as RouteConfig - // todo: improve typings precision - .then(function (c) { return typeof c === 'string' ? { moduleId: c } : c; }) - .then(function (c) { - c.route = instruction.params.path; - validateRouteConfig(c); - if (!c.navModel) { - c.navModel = _this.createNavModel(c); + catch (error) { + return next.cancel(error); } - return c; - }); - }; - return Router; -}()); -/* @internal exported for unit testing */ -var generateBaseUrl = function (router, instruction) { - return "" + (router.baseUrl || '') + (instruction.getBaseUrl() || ''); + } + return next(); + } + return iterate(); }; -/* @internal exported for unit testing */ -var validateRouteConfig = function (config) { - if (typeof config !== 'object') { - throw new Error('Invalid Route Config'); +/** + * Find list of activatable view model and add to list (3rd parameter) + * @internal exported for unit testing + */ +var findActivatable = function (navigationInstruction, callbackName, list, router) { + if (list === void 0) { list = []; } + var plan = navigationInstruction.plan; + Object + .keys(plan) + .forEach(function (viewPortName) { + var viewPortPlan = plan[viewPortName]; + var viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName]; + var viewPortComponent = viewPortInstruction.component; + var viewModel = viewPortComponent.viewModel; + if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle + || viewPortPlan.strategy === activationStrategy.replace) + && callbackName in viewModel) { + list.push({ + viewModel: viewModel, + lifecycleArgs: viewPortInstruction.lifecycleArgs, + router: router + }); + } + var childNavInstruction = viewPortPlan.childNavigationInstruction; + if (childNavInstruction) { + findActivatable(childNavInstruction, callbackName, list, viewPortComponent.childRouter || router); + } + }); + return list; +}; +var shouldContinue = function (output, router) { + if (output instanceof Error) { + return false; } - if (typeof config.route !== 'string') { - var name_1 = config.name || '(no name)'; - throw new Error('Invalid Route Config for "' + name_1 + '": You must specify a "route:" pattern.'); + if (isNavigationCommand(output)) { + if (typeof output.setRouter === 'function') { + output.setRouter(router); + } + return !!output.shouldContinueProcessing; } - if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) { - throw new Error('Invalid Route Config for "' + config.route + '": You must specify a "moduleId:", "redirect:", "navigationStrategy:", or "viewPorts:".'); + if (output === undefined) { + return true; } + return output; }; -/* @internal exported for unit testing */ -var evaluateNavigationStrategy = function (instruction, evaluator, context) { - return Promise.resolve(evaluator.call(context, instruction)).then(function () { - if (!('viewPorts' in instruction.config)) { - instruction.config.viewPorts = { - 'default': { - moduleId: instruction.config.moduleId - } - }; - } - return instruction; - }); -}; - -/**@internal exported for unit testing */ -var createNextFn = function (instruction, steps) { - var index = -1; - var next = function () { - index++; - if (index < steps.length) { - var currentStep = steps[index]; - try { - return currentStep(instruction, next); - } - catch (e) { - return next.reject(e); - } +/** + * wraps a subscription, allowing unsubscribe calls even if + * the first value comes synchronously + */ +var SafeSubscription = /** @class */ (function () { + function SafeSubscription(subscriptionFunc) { + this._subscribed = true; + this._subscription = subscriptionFunc(this); + if (!this._subscribed) { + this.unsubscribe(); } - else { - return next.complete(); + } + Object.defineProperty(SafeSubscription.prototype, "subscribed", { + get: function () { + return this._subscribed; + }, + enumerable: true, + configurable: true + }); + SafeSubscription.prototype.unsubscribe = function () { + if (this._subscribed && this._subscription) { + this._subscription.unsubscribe(); } + this._subscribed = false; }; - next.complete = createCompletionHandler(next, "completed" /* Completed */); - next.cancel = createCompletionHandler(next, "canceled" /* Canceled */); - next.reject = createCompletionHandler(next, "rejected" /* Rejected */); - return next; -}; -/**@internal exported for unit testing */ -var createCompletionHandler = function (next, status) { - return function (output) { return Promise - .resolve({ - status: status, - output: output, - completed: status === "completed" /* Completed */ - }); }; -}; - + return SafeSubscription; +}()); /** -* The class responsible for managing and processing the navigation pipeline. -*/ -var Pipeline = /** @class */ (function () { - function Pipeline() { - /** - * The pipeline steps. And steps added via addStep will be converted to a function - * The actualy running functions with correct step contexts of this pipeline - */ - this.steps = []; + * A function to process return value from `activate`/`canActivate` steps + * Supports observable/promise + * + * For observable, resolve at first next() or on complete() + */ +var processPotential = function (obj, resolve, reject) { + // if promise like + if (obj && typeof obj.then === 'function') { + return Promise.resolve(obj).then(resolve).catch(reject); } - /** - * Adds a step to the pipeline. - * - * @param step The pipeline step. - */ - Pipeline.prototype.addStep = function (step) { - var run; - if (typeof step === 'function') { - run = step; - } - else if (typeof step.getSteps === 'function') { - // getSteps is to enable support open slots - // where devs can add multiple steps into the same slot name - var steps = step.getSteps(); - for (var i = 0, l = steps.length; i < l; i++) { - this.addStep(steps[i]); + // if observable + if (obj && typeof obj.subscribe === 'function') { + var obs_1 = obj; + return new SafeSubscription(function (sub) { return obs_1.subscribe({ + next: function () { + if (sub.subscribed) { + sub.unsubscribe(); + resolve(obj); + } + }, + error: function (error) { + if (sub.subscribed) { + sub.unsubscribe(); + reject(error); + } + }, + complete: function () { + if (sub.subscribed) { + sub.unsubscribe(); + resolve(obj); + } } - return this; - } - else { - run = step.run.bind(step); - } - this.steps.push(run); - return this; - }; - /** - * Runs the pipeline. - * - * @param instruction The navigation instruction to process. - */ - Pipeline.prototype.run = function (instruction) { - var nextFn = createNextFn(instruction, this.steps); - return nextFn(); - }; - return Pipeline; -}()); + }); }); + } + // else just resolve + try { + return resolve(obj); + } + catch (error) { + return reject(error); + } +}; /** - * Abstract class that is responsible for loading view / view model from a route config - * The default implementation can be found in `aurelia-templating-router` + * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route */ -var RouteLoader = /** @class */ (function () { - function RouteLoader() { +var CanDeactivatePreviousStep = /** @class */ (function () { + function CanDeactivatePreviousStep() { } - /** - * Load a route config based on its viewmodel / view configuration - */ - // return typing: return typings used to be never - // as it was a throw. Changing it to Promise should not cause any issues - RouteLoader.prototype.loadRoute = function (router, config, navigationInstruction) { - throw new Error('Route loaders must implement "loadRoute(router, config, navigationInstruction)".'); + CanDeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { + return processDeactivatable(navigationInstruction, 'canDeactivate', next); }; - return RouteLoader; + return CanDeactivatePreviousStep; }()); /** - * A pipeline step responsible for loading a route config of a navigation instruction + * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route */ -var LoadRouteStep = /** @class */ (function () { - function LoadRouteStep(routeLoader) { - this.routeLoader = routeLoader; +var CanActivateNextStep = /** @class */ (function () { + function CanActivateNextStep() { } - /**@internal */ - LoadRouteStep.inject = function () { return [RouteLoader]; }; - /** - * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline - */ - LoadRouteStep.prototype.run = function (navigationInstruction, next) { - return loadNewRoute(this.routeLoader, navigationInstruction) - .then(next, next.cancel); + CanActivateNextStep.prototype.run = function (navigationInstruction, next) { + return processActivatable(navigationInstruction, 'canActivate', next); }; - return LoadRouteStep; + return CanActivateNextStep; }()); /** - * @internal Exported for unit testing - */ -var loadNewRoute = function (routeLoader, navigationInstruction) { - var toLoad = determineWhatToLoad(navigationInstruction); - var loadPromises = toLoad.map(function (loadingPlan) { return loadRoute(routeLoader, loadingPlan.navigationInstruction, loadingPlan.viewPortPlan); }); - return Promise.all(loadPromises); -}; -/** - * @internal Exported for unit testing + * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route */ -var determineWhatToLoad = function (navigationInstruction, toLoad) { - if (toLoad === void 0) { toLoad = []; } - var plan = navigationInstruction.plan; - for (var viewPortName in plan) { - var viewPortPlan = plan[viewPortName]; - var child_nav_instruction = viewPortPlan.childNavigationInstruction; - if (viewPortPlan.strategy === activationStrategy.replace) { - toLoad.push({ viewPortPlan: viewPortPlan, navigationInstruction: navigationInstruction }); - if (child_nav_instruction) { - determineWhatToLoad(child_nav_instruction, toLoad); - } - } - else { - var viewPortInstruction = navigationInstruction.addViewPortInstruction(viewPortName, viewPortPlan.strategy, viewPortPlan.prevModuleId, viewPortPlan.prevComponent); - if (child_nav_instruction) { - viewPortInstruction.childNavigationInstruction = child_nav_instruction; - determineWhatToLoad(child_nav_instruction, toLoad); - } - } +var DeactivatePreviousStep = /** @class */ (function () { + function DeactivatePreviousStep() { } - return toLoad; -}; -/** - * @internal Exported for unit testing - */ -var loadRoute = function (routeLoader, navigationInstruction, viewPortPlan) { - var moduleId = viewPortPlan.config ? viewPortPlan.config.moduleId : null; - return loadComponent(routeLoader, navigationInstruction, viewPortPlan.config) - .then(function (component) { - var viewPortInstruction = navigationInstruction.addViewPortInstruction(viewPortPlan.name, viewPortPlan.strategy, moduleId, component); - var childRouter = component.childRouter; - if (childRouter) { - var path = navigationInstruction.getWildcardPath(); - return childRouter - ._createNavigationInstruction(path, navigationInstruction) - .then(function (childInstruction) { - viewPortPlan.childNavigationInstruction = childInstruction; - return _buildNavigationPlan(childInstruction) - .then(function (childPlan) { - if (childPlan instanceof Redirect) { - return Promise.reject(childPlan); - } - childInstruction.plan = childPlan; - viewPortInstruction.childNavigationInstruction = childInstruction; - return loadNewRoute(routeLoader, childInstruction); - }); - }); - } - // ts complains without this, though they are same - return void 0; - }); -}; + DeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { + return processDeactivatable(navigationInstruction, 'deactivate', next, true); + }; + return DeactivatePreviousStep; +}()); /** - * Load a routed-component based on navigation instruction and route config - * @internal exported for unit testing only + * A pipeline step responsible for finding and activating method `activate` on a view model of a route */ -var loadComponent = function (routeLoader, navigationInstruction, config) { - var router = navigationInstruction.router; - var lifecycleArgs = navigationInstruction.lifecycleArgs; - return Promise.resolve() - .then(function () { return routeLoader.loadRoute(router, config, navigationInstruction); }) - .then( - /** - * @param component an object carrying information about loaded route - * typically contains information about view model, childContainer, view and router - */ - function (component) { - var viewModel = component.viewModel, childContainer = component.childContainer; - component.router = router; - component.config = config; - if ('configureRouter' in viewModel) { - var childRouter_1 = childContainer.getChildRouter(); - component.childRouter = childRouter_1; - return childRouter_1 - .configure(function (c) { return viewModel.configureRouter(c, childRouter_1, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]); }) - .then(function () { return component; }); - } - return component; - }); -}; +var ActivateNextStep = /** @class */ (function () { + function ActivateNextStep() { + } + ActivateNextStep.prototype.run = function (navigationInstruction, next) { + return processActivatable(navigationInstruction, 'activate', next, true); + }; + return ActivateNextStep; +}()); /** * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution @@ -1773,8 +1891,8 @@ var PipelineSlot = /** @class */ (function () { return PipelineSlot; }()); /** -* Class responsible for creating the navigation pipeline. -*/ + * Class responsible for creating the navigation pipeline. + */ var PipelineProvider = /** @class */ (function () { function PipelineProvider(container) { this.container = container; @@ -1782,22 +1900,22 @@ var PipelineProvider = /** @class */ (function () { BuildNavigationPlanStep, CanDeactivatePreviousStep, LoadRouteStep, - this._createPipelineSlot("authorize" /* Authorize */), + createPipelineSlot(container, "authorize" /* Authorize */), CanActivateNextStep, - this._createPipelineSlot("preActivate" /* PreActivate */, 'modelbind'), + createPipelineSlot(container, "preActivate" /* PreActivate */, 'modelbind'), // NOTE: app state changes start below - point of no return DeactivatePreviousStep, ActivateNextStep, - this._createPipelineSlot("preRender" /* PreRender */, 'precommit'), + createPipelineSlot(container, "preRender" /* PreRender */, 'precommit'), CommitChangesStep, - this._createPipelineSlot("postRender" /* PostRender */, 'postcomplete') + createPipelineSlot(container, "postRender" /* PostRender */, 'postcomplete') ]; } /**@internal */ PipelineProvider.inject = function () { return [aureliaDependencyInjection.Container]; }; /** - * Create the navigation pipeline. - */ + * Create the navigation pipeline. + */ PipelineProvider.prototype.createPipeline = function (useCanDeactivateStep) { var _this = this; if (useCanDeactivateStep === void 0) { useCanDeactivateStep = true; } @@ -1815,14 +1933,15 @@ var PipelineProvider = /** @class */ (function () { return this.steps.find(function (x) { return x.slotName === name || x.slotAlias === name; }); }; /** - * Adds a step into the pipeline at a known slot location. - */ + * Adds a step into the pipeline at a known slot location. + */ PipelineProvider.prototype.addStep = function (name, step) { var found = this._findStep(name); if (found) { + var slotSteps = found.steps; // prevent duplicates - if (!found.steps.includes(step)) { - found.steps.push(step); + if (!slotSteps.includes(step)) { + slotSteps.push(step); } } else { @@ -1835,13 +1954,13 @@ var PipelineProvider = /** @class */ (function () { PipelineProvider.prototype.removeStep = function (name, step) { var slot = this._findStep(name); if (slot) { - var steps = slot.steps; - steps.splice(steps.indexOf(step), 1); + var slotSteps = slot.steps; + slotSteps.splice(slotSteps.indexOf(step), 1); } }; /** - * @internal * Clears all steps from a slot in the pipeline + * @internal */ PipelineProvider.prototype._clearSteps = function (name) { if (name === void 0) { name = ''; } @@ -1854,22 +1973,22 @@ var PipelineProvider = /** @class */ (function () { * Resets all pipeline slots */ PipelineProvider.prototype.reset = function () { - this._clearSteps('authorize'); - this._clearSteps('preActivate'); - this._clearSteps('preRender'); - this._clearSteps('postRender'); - }; - /**@internal */ - PipelineProvider.prototype._createPipelineSlot = function (name, alias) { - return new PipelineSlot(this.container, name, alias); + this._clearSteps("authorize" /* Authorize */); + this._clearSteps("preActivate" /* PreActivate */); + this._clearSteps("preRender" /* PreRender */); + this._clearSteps("postRender" /* PostRender */); }; return PipelineProvider; -}()); +}()); +/**@internal */ +var createPipelineSlot = function (container, name, alias) { + return new PipelineSlot(container, name, alias); +}; var logger = LogManager.getLogger('app-router'); /** -* The main application router. -*/ + * The main application router. + */ var AppRouter = /** @class */ (function (_super) { __extends(AppRouter, _super); function AppRouter(container, history, pipelineProvider, events) { @@ -1881,9 +2000,9 @@ var AppRouter = /** @class */ (function (_super) { /**@internal */ AppRouter.inject = function () { return [aureliaDependencyInjection.Container, aureliaHistory.History, PipelineProvider, aureliaEventAggregator.EventAggregator]; }; /** - * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. - * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. - */ + * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. + * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. + */ AppRouter.prototype.reset = function () { _super.prototype.reset.call(this); this.maxInstructionCount = 10; @@ -1895,10 +2014,10 @@ var AppRouter = /** @class */ (function (_super) { } }; /** - * Loads the specified URL. - * - * @param url The URL fragment to load. - */ + * Loads the specified URL. + * + * @param url The URL fragment to load. + */ AppRouter.prototype.loadUrl = function (url) { var _this = this; return this @@ -1910,11 +2029,11 @@ var AppRouter = /** @class */ (function (_super) { }); }; /** - * Registers a viewPort to be used as a rendering target for activated routes. - * - * @param viewPort The viewPort. This is typically a element in Aurelia default impl - * @param name The name of the viewPort. 'default' if unspecified. - */ + * Registers a viewPort to be used as a rendering target for activated routes. + * + * @param viewPort The viewPort. This is typically a element in Aurelia default impl + * @param name The name of the viewPort. 'default' if unspecified. + */ AppRouter.prototype.registerViewPort = function (viewPort, name) { var _this = this; // having strong typing without changing public API @@ -1958,10 +2077,10 @@ var AppRouter = /** @class */ (function (_super) { return Promise.resolve(); }; /** - * Activates the router. This instructs the router to begin listening for history changes and processing instructions. - * - * @params options The set of options to activate the router with. - */ + * Activates the router. This instructs the router to begin listening for history changes and processing instructions. + * + * @params options The set of options to activate the router with. + */ AppRouter.prototype.activate = function (options) { if (this.isActive) { return; @@ -1974,8 +2093,8 @@ var AppRouter = /** @class */ (function (_super) { this._dequeueInstruction(); }; /** - * Deactivates the router. - */ + * Deactivates the router. + */ AppRouter.prototype.deactivate = function () { this.isActive = false; this.history.deactivate(); @@ -2006,20 +2125,21 @@ var AppRouter = /** @class */ (function (_super) { } _this.isNavigating = true; var navtracker = _this.history.getState('NavigationTracker'); - if (!navtracker && !_this.currentNavigationTracker) { + var currentNavTracker = _this.currentNavigationTracker; + if (!navtracker && !currentNavTracker) { _this.isNavigatingFirst = true; _this.isNavigatingNew = true; } else if (!navtracker) { _this.isNavigatingNew = true; } - else if (!_this.currentNavigationTracker) { + else if (!currentNavTracker) { _this.isNavigatingRefresh = true; } - else if (_this.currentNavigationTracker < navtracker) { + else if (currentNavTracker < navtracker) { _this.isNavigatingForward = true; } - else if (_this.currentNavigationTracker > navtracker) { + else if (currentNavTracker > navtracker) { _this.isNavigatingBack = true; } if (!navtracker) { @@ -2028,15 +2148,16 @@ var AppRouter = /** @class */ (function (_super) { } _this.currentNavigationTracker = navtracker; instruction.previousInstruction = _this.currentInstruction; + var maxInstructionCount = _this.maxInstructionCount; if (!instructionCount) { _this.events.publish("router:navigation:processing" /* Processing */, { instruction: instruction }); } - else if (instructionCount === _this.maxInstructionCount - 1) { + else if (instructionCount === maxInstructionCount - 1) { logger.error(instructionCount + 1 + " navigation instructions have been attempted without success. Restoring last known good location."); restorePreviousLocation(_this); return _this._dequeueInstruction(instructionCount + 1); } - else if (instructionCount > _this.maxInstructionCount) { + else if (instructionCount > maxInstructionCount) { throw new Error('Maximum navigation attempts exceeded. Giving up.'); } var pipeline = _this.pipelineProvider.createPipeline(!_this.couldDeactivate); @@ -2093,6 +2214,7 @@ var processResult = function (instruction, result, instructionCount, router) { }; var resolveInstruction = function (instruction, result, isInnerInstruction, router) { instruction.resolve(result); + var eventAggregator = router.events; var eventArgs = { instruction: instruction, result: result }; if (!isInnerInstruction) { router.isNavigating = false; @@ -2116,18 +2238,18 @@ var resolveInstruction = function (instruction, result, isInnerInstruction, rout router.history.previousLocation = instruction.fragment + queryString; eventName = "router:navigation:success" /* Success */; } - router.events.publish(eventName, eventArgs); - router.events.publish("router:navigation:complete" /* Complete */, eventArgs); + eventAggregator.publish(eventName, eventArgs); + eventAggregator.publish("router:navigation:complete" /* Complete */, eventArgs); } else { - router.events.publish("router:navigation:child:complete" /* ChildComplete */, eventArgs); + eventAggregator.publish("router:navigation:child:complete" /* ChildComplete */, eventArgs); } return result; }; var restorePreviousLocation = function (router) { var previousLocation = router.history.previousLocation; if (previousLocation) { - router.navigate(router.history.previousLocation, { trigger: false, replace: true }); + router.navigate(previousLocation, { trigger: false, replace: true }); } else if (router.fallbackRoute) { router.navigate(router.fallbackRoute, { trigger: true, replace: true }); diff --git a/dist/commonjs/aurelia-router.js.map b/dist/commonjs/aurelia-router.js.map index c8cb35a3..f9326750 100644 --- a/dist/commonjs/aurelia-router.js.map +++ b/dist/commonjs/aurelia-router.js.map @@ -1 +1 @@ -{"version":3,"file":"aurelia-router.js","sources":["../../src/navigation-commands.ts","../../src/navigation-plan.ts","../../src/activation.ts","../../src/navigation-instruction.ts","../../src/nav-model.ts","../../src/util.ts","../../src/router-configuration.ts","../../src/router.ts","../../src/next.ts","../../src/pipeline.ts","../../src/route-loading.ts","../../src/pipeline-provider.ts","../../src/app-router.ts","../../src/pipeline-status.ts","../../src/router-event.ts","../../src/pipeline-slot-name.ts"],"sourcesContent":["import { NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface NavigationOptions {\n useAppRouter?: boolean;\n }\n}\n\n/**\n* When a navigation command is encountered, the current navigation\n* will be cancelled and control will be passed to the navigation\n* command so it can determine the correct action.\n*/\nexport interface NavigationCommand {\n navigate: (router: Router) => void;\n /**@internal */\n shouldContinueProcessing?: boolean;\n /**@internal */\n setRouter?: (router: Router) => void;\n}\n\n/**\n* Determines if the provided object is a navigation command.\n* A navigation command is anything with a navigate method.\n*\n* @param obj The object to check.\n*/\nexport function isNavigationCommand(obj: any): obj is NavigationCommand {\n return obj && typeof obj.navigate === 'function';\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect.\n*/\nexport class Redirect implements NavigationCommand {\n\n url: string;\n /**@internal */\n options: NavigationOptions;\n /**@internal */\n shouldContinueProcessing: boolean;\n\n private router: Router;\n\n /**\n * @param url The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n constructor(url: string, options: NavigationOptions = {}) {\n this.url = url;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigate(this.url, this.options);\n }\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect to a named route.\n*/\nexport class RedirectToRoute implements NavigationCommand {\n\n route: string;\n params: any;\n /**@internal */\n options: NavigationOptions;\n\n /**@internal */\n shouldContinueProcessing: boolean;\n\n /**@internal */\n router: Router;\n\n /**\n * @param route The name of the route.\n * @param params The parameters to be sent to the activation method.\n * @param options The options to use for navigation.\n */\n constructor(route: string, params: any = {}, options: NavigationOptions = {}) {\n this.route = route;\n this.params = params;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigateToRoute(this.route, this.params, this.options);\n }\n}\n","import { ActivationStrategy, Next, ViewPortPlan } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\n\n/**\n* The strategy to use when activating modules during navigation.\n*/\nexport const activationStrategy: ActivationStrategy = {\n noChange: 'no-change',\n invokeLifecycle: 'invoke-lifecycle',\n replace: 'replace'\n};\n\n/**\n * Transform a navigation instruction into viewport plan record object,\n * or a redirect request if user viewmodel demands\n */\nexport class BuildNavigationPlanStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return _buildNavigationPlan(navigationInstruction)\n .then(plan => {\n if (plan instanceof Redirect) {\n return next.cancel(plan);\n }\n navigationInstruction.plan = plan;\n return next();\n })\n .catch(next.cancel);\n }\n}\n\nexport function _buildNavigationPlan(\n instruction: NavigationInstruction,\n forceLifecycleMinimum?: boolean\n): Promise | Redirect> {\n let config = instruction.config;\n\n // todo: separate and export for unit tests\n if ('redirect' in config) {\n const router = instruction.router;\n return router\n ._createNavigationInstruction(config.redirect)\n .then(newInstruction => {\n const params: Record = {};\n for (let key in newInstruction.params) {\n // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this }\n let val = newInstruction.params[key];\n if (typeof val === 'string' && val[0] === ':') {\n val = val.slice(1);\n // And if that param is found on the original instruction then use it\n if (val in instruction.params) {\n params[key] = instruction.params[val];\n }\n } else {\n params[key] = newInstruction.params[key];\n }\n }\n let redirectLocation = router.generate(newInstruction.config, params, instruction.options);\n\n // Special handling for child routes\n for (let key in instruction.params) {\n redirectLocation = redirectLocation.replace(`:${key}`, instruction.params[key]);\n }\n\n if (instruction.queryString) {\n redirectLocation += '?' + instruction.queryString;\n }\n\n return Promise.resolve(new Redirect(redirectLocation));\n });\n }\n\n const prev = instruction.previousInstruction;\n const plan: Record = {};\n const defaults = instruction.router.viewPortDefaults;\n\n if (prev) {\n let newParams = hasDifferentParameterValues(prev, instruction);\n let pending: Promise[] = [];\n\n for (let viewPortName in prev.viewPortInstructions) {\n const prevViewPortInstruction = prev.viewPortInstructions[viewPortName];\n let nextViewPortConfig = viewPortName in config.viewPorts ? config.viewPorts[viewPortName] : prevViewPortInstruction;\n if (nextViewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) {\n nextViewPortConfig = defaults[viewPortName];\n }\n\n const viewPortPlan = plan[viewPortName] = {\n name: viewPortName,\n config: nextViewPortConfig,\n prevComponent: prevViewPortInstruction.component,\n prevModuleId: prevViewPortInstruction.moduleId\n } as ViewPortPlan;\n\n if (prevViewPortInstruction.moduleId !== nextViewPortConfig.moduleId) {\n viewPortPlan.strategy = activationStrategy.replace;\n } else if ('determineActivationStrategy' in prevViewPortInstruction.component.viewModel) {\n viewPortPlan.strategy = prevViewPortInstruction.component.viewModel\n .determineActivationStrategy(...instruction.lifecycleArgs);\n } else if (config.activationStrategy) {\n viewPortPlan.strategy = config.activationStrategy;\n } else if (newParams || forceLifecycleMinimum) {\n viewPortPlan.strategy = activationStrategy.invokeLifecycle;\n } else {\n viewPortPlan.strategy = activationStrategy.noChange;\n }\n\n if (viewPortPlan.strategy !== activationStrategy.replace && prevViewPortInstruction.childRouter) {\n const path = instruction.getWildcardPath();\n const task: Promise = prevViewPortInstruction\n .childRouter\n ._createNavigationInstruction(path, instruction)\n .then((childInstruction: any) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(\n childInstruction,\n viewPortPlan.strategy === activationStrategy.invokeLifecycle\n )\n .then(childPlan => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n // for bluebird ?\n return null;\n });\n });\n\n pending.push(task);\n }\n }\n\n return Promise.all(pending).then(() => plan);\n }\n\n for (let viewPortName in config.viewPorts) {\n let viewPortConfig = config.viewPorts[viewPortName];\n if (viewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) {\n viewPortConfig = defaults[viewPortName];\n }\n plan[viewPortName] = {\n name: viewPortName,\n strategy: activationStrategy.replace,\n config: viewPortConfig\n };\n }\n\n return Promise.resolve(plan);\n}\n\nfunction hasDifferentParameterValues(prev: NavigationInstruction, next: NavigationInstruction): boolean {\n let prevParams = prev.params;\n let nextParams = next.params;\n let nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null;\n\n for (let key in nextParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n for (let key in prevParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n if (!next.options.compareQueryParams) {\n return false;\n }\n\n let prevQueryParams = prev.queryParams;\n let nextQueryParams = next.queryParams;\n for (let key in nextQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n for (let key in prevQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n return false;\n}\n","import { Next, ViewPortComponent, ViewPortPlan, ViewPortInstruction, LifecycleArguments } from './interfaces';\nimport { isNavigationCommand } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy } from './navigation-plan';\nimport { Router } from './router';\n\n/**\n * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route\n */\nexport class CanDeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'canDeactivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route\n */\nexport class CanActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'canActivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route\n */\nexport class DeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'deactivate', next, true);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `activate` on a view model of a route\n */\nexport class ActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'activate', next, true);\n }\n}\n\n/**\n * Recursively find list of deactivate-able view models\n * and invoke the either 'canDeactivate' or 'deactivate' on each\n */\nconst processDeactivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canDeactivate' | 'deactivate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let plan: Record = navigationInstruction.plan;\n let infos = findDeactivatable(plan, callbackName);\n let i = infos.length; // query from inside out\n\n function inspect(val: any): Promise {\n if (ignoreResult || shouldContinue(val)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n if (i--) {\n try {\n let viewModel = infos[i];\n let result = viewModel[callbackName](navigationInstruction);\n return processPotential(result, inspect, next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n navigationInstruction.router.couldDeactivate = true;\n\n return next();\n }\n\n return iterate();\n};\n\n/**\n * Recursively find and returns a list of deactivate-able view models\n */\nconst findDeactivatable = (\n plan: Record,\n callbackName: string,\n list: IActivatableInfo[] = []\n): any[] => {\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let prevComponent = viewPortPlan.prevComponent;\n\n if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace)\n && prevComponent\n ) {\n let viewModel = prevComponent.viewModel;\n\n if (callbackName in viewModel) {\n list.push(viewModel);\n }\n }\n\n if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) {\n addPreviousDeactivatable(prevComponent, callbackName, list);\n } else if (viewPortPlan.childNavigationInstruction) {\n findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list);\n }\n }\n\n return list;\n};\n\nconst addPreviousDeactivatable = (\n component: ViewPortComponent,\n callbackName: string,\n list: IActivatableInfo[]\n): void => {\n let childRouter = component.childRouter;\n\n if (childRouter && childRouter.currentInstruction) {\n let viewPortInstructions = childRouter.currentInstruction.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let prevComponent = viewPortInstruction.component;\n let prevViewModel = prevComponent.viewModel;\n\n if (callbackName in prevViewModel) {\n list.push(prevViewModel);\n }\n\n addPreviousDeactivatable(prevComponent, callbackName, list);\n }\n }\n};\n\nconst processActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let infos = findActivatable(navigationInstruction, callbackName);\n let length = infos.length;\n let i = -1; // query from top down\n\n function inspect(val: any, router: Router): Promise {\n if (ignoreResult || shouldContinue(val, router)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n i++;\n\n if (i < length) {\n try {\n let current = infos[i];\n let result = current.viewModel[callbackName](...current.lifecycleArgs);\n return processPotential(result, (val: any) => inspect(val, current.router), next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n return next();\n }\n\n return iterate();\n};\n\ninterface IActivatableInfo {\n viewModel: any;\n lifecycleArgs: LifecycleArguments;\n router: Router;\n}\n\n/**\n * Find list of activatable view model and add to list (3rd parameter)\n */\nconst findActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n list: IActivatableInfo[] = [],\n router?: Router\n): IActivatableInfo[] => {\n let plan: Record = navigationInstruction.plan;\n\n Object\n .keys(plan)\n .forEach((viewPortName) => {\n let viewPortPlan = plan[viewPortName];\n let viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName] as ViewPortInstruction;\n let viewPortComponent = viewPortInstruction.component;\n let viewModel = viewPortComponent.viewModel;\n\n if (\n (viewPortPlan.strategy === activationStrategy.invokeLifecycle\n || viewPortPlan.strategy === activationStrategy.replace\n )\n && callbackName in viewModel\n ) {\n list.push({\n viewModel,\n lifecycleArgs: viewPortInstruction.lifecycleArgs,\n router\n });\n }\n\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (childNavInstruction) {\n findActivatable(\n childNavInstruction,\n callbackName,\n list,\n viewPortComponent.childRouter || router\n );\n }\n });\n\n return list;\n};\n\nconst shouldContinue = (output: T, router?: Router): boolean | T => {\n if (output instanceof Error) {\n return false;\n }\n\n if (isNavigationCommand(output)) {\n if (typeof output.setRouter === 'function') {\n output.setRouter(router);\n }\n\n return !!output.shouldContinueProcessing;\n }\n\n if (output === undefined) {\n return true;\n }\n\n return output;\n};\n\n/**\n * A basic interface for an Observable type\n */\nexport interface IObservable {\n subscribe(sub?: IObservableConfig): ISubscription;\n}\n\nexport interface IObservableConfig {\n next(): void;\n error(err?: any): void;\n complete(): void;\n}\n\n/**\n * A basic interface for a Subscription to an Observable\n */\ninterface ISubscription {\n unsubscribe(): void;\n}\n\ntype SafeSubscriptionFunc = (sub: SafeSubscription) => ISubscription;\n\n/**\n * wraps a subscription, allowing unsubscribe calls even if\n * the first value comes synchronously\n */\nclass SafeSubscription {\n\n private _subscribed: boolean;\n private _subscription: ISubscription;\n\n constructor(subscriptionFunc: SafeSubscriptionFunc) {\n this._subscribed = true;\n this._subscription = subscriptionFunc(this);\n\n if (!this._subscribed) {\n this.unsubscribe();\n }\n }\n\n get subscribed(): boolean {\n return this._subscribed;\n }\n\n unsubscribe(): void {\n if (this._subscribed && this._subscription) {\n this._subscription.unsubscribe();\n }\n\n this._subscribed = false;\n }\n}\n\n/**\n * A function to process return value from `activate`/`canActivate` steps\n * Supports observable/promise\n *\n * For observable, resolve at first next() or on complete()\n */\nconst processPotential = (obj: any, resolve: (val?: any) => any, reject: (err?: any) => any): any => {\n // if promise like\n if (obj && typeof obj.then === 'function') {\n return Promise.resolve(obj).then(resolve).catch(reject);\n }\n\n // if observable\n if (obj && typeof obj.subscribe === 'function') {\n let obs: IObservable = obj;\n return new SafeSubscription(sub => obs.subscribe({\n next() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n },\n error(error) {\n if (sub.subscribed) {\n sub.unsubscribe();\n reject(error);\n }\n },\n complete() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n }\n }));\n }\n\n // else just resolve\n try {\n return resolve(obj);\n } catch (error) {\n return reject(error);\n }\n};\n","import { ViewPortInstruction, RouteConfig, ViewPort, LifecycleArguments, ActivationStrategyType } from './interfaces';\nimport { Router } from './router';\nimport { activationStrategy } from './navigation-plan';\n\n/**\n * Initialization options for a navigation instruction\n */\nexport interface NavigationInstructionInit {\n fragment: string;\n queryString?: string;\n params?: Record;\n queryParams?: Record;\n config: RouteConfig;\n parentInstruction?: NavigationInstruction;\n previousInstruction?: NavigationInstruction;\n router: Router;\n options?: Object;\n plan?: Record;\n}\n\n/**\n * A pipeline step for instructing a piepline to commit changes on a navigation instruction\n */\nexport class CommitChangesStep {\n run(navigationInstruction: NavigationInstruction, next: Function): Promise {\n return navigationInstruction\n ._commitChanges(/*wait to swap?*/true)\n .then(() => {\n navigationInstruction._updateTitle();\n return next();\n });\n }\n}\n\n/**\n* Class used to represent an instruction during a navigation.\n*/\nexport class NavigationInstruction {\n /**\n * The URL fragment.\n */\n fragment: string;\n\n /**\n * The query string.\n */\n queryString: string;\n\n /**\n * Parameters extracted from the route pattern.\n */\n params: any;\n\n /**\n * Parameters extracted from the query string.\n */\n queryParams: any;\n\n /**\n * The route config for the route matching this instruction.\n */\n config: RouteConfig;\n\n /**\n * The parent instruction, if this instruction was created by a child router.\n */\n parentInstruction: NavigationInstruction;\n\n parentCatchHandler: any;\n\n /**\n * The instruction being replaced by this instruction in the current router.\n */\n previousInstruction: NavigationInstruction;\n\n /**\n * viewPort instructions to used activation.\n */\n viewPortInstructions: Record;\n\n /**\n * The router instance.\n */\n router: Router;\n\n /**\n * Current built viewport plan of this nav instruction\n */\n plan: Record = null;\n\n options: Record = {};\n\n /**@internal */\n lifecycleArgs: LifecycleArguments;\n /**@internal */\n resolve?: (val?: any) => void;\n\n constructor(init: NavigationInstructionInit) {\n Object.assign(this, init);\n\n this.params = this.params || {};\n this.viewPortInstructions = {};\n\n let ancestorParams = [];\n let current: NavigationInstruction = this;\n do {\n let currentParams = Object.assign({}, current.params);\n if (current.config && current.config.hasChildRouter) {\n // remove the param for the injected child route segment\n delete currentParams[current.getWildCardName()];\n }\n\n ancestorParams.unshift(currentParams);\n current = current.parentInstruction;\n } while (current);\n\n let allParams = Object.assign({}, this.queryParams, ...ancestorParams);\n this.lifecycleArgs = [allParams, this.config, this];\n }\n\n /**\n * Gets an array containing this instruction and all child instructions for the current navigation.\n */\n getAllInstructions(): Array {\n let instructions: NavigationInstruction[] = [this];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let key in viewPortInstructions) {\n let childInstruction = viewPortInstructions[key].childNavigationInstruction;\n if (childInstruction) {\n instructions.push(...childInstruction.getAllInstructions());\n }\n }\n\n return instructions;\n }\n\n /**\n * Gets an array containing the instruction and all child instructions for the previous navigation.\n * Previous instructions are no longer available after navigation completes.\n */\n getAllPreviousInstructions(): Array {\n return this.getAllInstructions().map(c => c.previousInstruction).filter(c => c);\n }\n\n /**\n * Adds a viewPort instruction. Returns the newly created instruction based on parameters\n */\n addViewPortInstruction(name: string, strategy: ActivationStrategyType, moduleId: string, component: any): /*ViewPortInstruction*/ any {\n const lifecycleArgs = this.lifecycleArgs;\n const config: RouteConfig = Object.assign({}, lifecycleArgs[1], { currentViewPort: name });\n const viewportInstruction = this.viewPortInstructions[name] = {\n name: name,\n strategy: strategy,\n moduleId: moduleId,\n component: component,\n childRouter: component.childRouter,\n lifecycleArgs: [].concat(lifecycleArgs[0], config, lifecycleArgs[2]) as LifecycleArguments\n };\n\n return viewportInstruction;\n }\n\n /**\n * Gets the name of the route pattern's wildcard parameter, if applicable.\n */\n getWildCardName(): string {\n // todo: potential issue, or at least unsafe typings\n let configRoute = this.config.route as string;\n let wildcardIndex = configRoute.lastIndexOf('*');\n return configRoute.substr(wildcardIndex + 1);\n }\n\n /**\n * Gets the path and query string created by filling the route\n * pattern's wildcard parameter with the matching param.\n */\n getWildcardPath(): string {\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n let queryString = this.queryString;\n\n if (queryString) {\n path += '?' + queryString;\n }\n\n return path;\n }\n\n /**\n * Gets the instruction's base URL, accounting for wildcard route parameters.\n */\n getBaseUrl(): string {\n let $encodeURI = encodeURI;\n let fragment = decodeURI(this.fragment);\n\n if (fragment === '') {\n let nonEmptyRoute = this.router.routes.find(route => {\n return route.name === this.config.name &&\n route.route !== '';\n });\n if (nonEmptyRoute) {\n fragment = nonEmptyRoute.route as any;\n }\n }\n\n if (!this.params) {\n return $encodeURI(fragment);\n }\n\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n\n if (!path) {\n return $encodeURI(fragment);\n }\n\n return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path)));\n }\n\n /**@internal */\n _commitChanges(waitToSwap: boolean): Promise {\n let router = this.router;\n router.currentInstruction = this;\n\n const previousInstruction = this.previousInstruction;\n if (previousInstruction) {\n previousInstruction.config.navModel.isActive = false;\n }\n\n this.config.navModel.isActive = true;\n\n router.refreshNavigation();\n\n let loads: Promise[] = [];\n let delaySwaps: ISwapPlan[] = [];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let viewPort = router.viewPorts[viewPortName];\n\n if (!viewPort) {\n throw new Error(`There was no router-view found in the view for ${viewPortInstruction.moduleId}.`);\n }\n\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n if (viewPortInstruction.strategy === activationStrategy.replace) {\n if (child_nav_instruction && child_nav_instruction.parentCatchHandler) {\n loads.push(child_nav_instruction._commitChanges(waitToSwap));\n } else {\n if (waitToSwap) {\n delaySwaps.push({ viewPort, viewPortInstruction });\n }\n loads.push(\n viewPort\n .process(viewPortInstruction, waitToSwap)\n .then(() => child_nav_instruction\n ? child_nav_instruction._commitChanges(waitToSwap)\n : Promise.resolve()\n )\n );\n }\n } else {\n if (child_nav_instruction) {\n loads.push(child_nav_instruction._commitChanges(waitToSwap));\n }\n }\n }\n\n return Promise\n .all(loads)\n .then(() => {\n delaySwaps.forEach(x => x.viewPort.swap(x.viewPortInstruction));\n return null;\n })\n .then(() => prune(this));\n }\n\n /**@internal */\n _updateTitle(): void {\n let router = this.router;\n let title = this._buildTitle(router.titleSeparator);\n if (title) {\n router.history.setTitle(title);\n }\n }\n\n /**@internal */\n _buildTitle(separator: string = ' | '): string {\n let title = '';\n let childTitles = [];\n let navModelTitle = this.config.navModel.title;\n let instructionRouter = this.router;\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n if (navModelTitle) {\n title = instructionRouter.transformTitle(navModelTitle);\n }\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n\n if (child_nav_instruction) {\n let childTitle = child_nav_instruction._buildTitle(separator);\n if (childTitle) {\n childTitles.push(childTitle);\n }\n }\n }\n\n if (childTitles.length) {\n title = childTitles.join(separator) + (title ? separator : '') + title;\n }\n\n if (instructionRouter.title) {\n title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title);\n }\n\n return title;\n }\n}\n\nconst prune = (instruction: NavigationInstruction): void => {\n instruction.previousInstruction = null;\n instruction.plan = null;\n};\n\ninterface ISwapPlan {\n viewPort: ViewPort;\n viewPortInstruction: ViewPortInstruction;\n}\n","import { Router } from './router';\nimport { RouteConfig } from './interfaces';\n\n/**\n* Class for storing and interacting with a route's navigation settings.\n*/\nexport class NavModel {\n\n /**\n * True if this nav item is currently active.\n */\n isActive: boolean = false;\n\n /**\n * The title.\n */\n title: string = null;\n\n /**\n * This nav item's absolute href.\n */\n href: string = null;\n\n /**\n * This nav item's relative href.\n */\n relativeHref: string = null;\n\n /**\n * Data attached to the route at configuration time.\n */\n settings: any = {};\n\n /**\n * The route config.\n */\n config: RouteConfig = null;\n\n /**\n * The router associated with this navigation model.\n */\n router: Router;\n\n order: number | boolean;\n\n constructor(router: Router, relativeHref: string) {\n this.router = router;\n this.relativeHref = relativeHref;\n }\n\n /**\n * Sets the route's title and updates document.title.\n * If the a navigation is in progress, the change will be applied\n * to document.title when the navigation completes.\n *\n * @param title The new title.\n */\n setTitle(title: string): void {\n this.title = title;\n\n if (this.isActive) {\n this.router.updateTitle();\n }\n }\n}\n","import { RouteConfig } from './interfaces';\n\nexport function _normalizeAbsolutePath(path: string, hasPushState: boolean, absolute: boolean = false) {\n if (!hasPushState && path[0] !== '#') {\n path = '#' + path;\n }\n\n if (hasPushState && absolute) {\n path = path.substring(1, path.length);\n }\n\n return path;\n}\n\nexport function _createRootedPath(fragment: string, baseUrl: string, hasPushState: boolean, absolute?: boolean) {\n if (isAbsoluteUrl.test(fragment)) {\n return fragment;\n }\n\n let path = '';\n\n if (baseUrl.length && baseUrl[0] !== '/') {\n path += '/';\n }\n\n path += baseUrl;\n\n if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') {\n path += '/';\n }\n\n if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') {\n path = path.substring(0, path.length - 1);\n }\n\n return _normalizeAbsolutePath(path + fragment, hasPushState, absolute);\n}\n\nexport function _resolveUrl(fragment: string, baseUrl: string, hasPushState?: boolean) {\n if (isRootedPath.test(fragment)) {\n return _normalizeAbsolutePath(fragment, hasPushState);\n }\n\n return _createRootedPath(fragment, baseUrl, hasPushState);\n}\n\nexport function _ensureArrayWithSingleRoutePerConfig(config: RouteConfig) {\n let routeConfigs = [];\n\n if (Array.isArray(config.route)) {\n for (let i = 0, ii = config.route.length; i < ii; ++i) {\n let current = Object.assign({}, config);\n current.route = config.route[i];\n routeConfigs.push(current);\n }\n } else {\n routeConfigs.push(Object.assign({}, config));\n }\n\n return routeConfigs;\n}\n\nconst isRootedPath = /^#?\\//;\nconst isAbsoluteUrl = /^([a-z][a-z0-9+\\-.]*:)?\\/\\//i;\n","import { RouteConfig, PipelineStep, RouteConfigSpecifier } from './interfaces';\nimport { _ensureArrayWithSingleRoutePerConfig } from './util';\nimport { Router } from './router';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * Class used to configure a [[Router]] instance.\n *\n * @constructor\n */\nexport class RouterConfiguration {\n instructions: Array<(router: Router) => void> = [];\n options: {\n [key: string]: any;\n compareQueryParams?: boolean;\n root?: string;\n pushState?: boolean;\n hashChange?: boolean;\n silent?: boolean;\n } = {};\n pipelineSteps: Array<{ name: string, step: Function | PipelineStep }> = [];\n title: string;\n titleSeparator: string;\n unknownRouteConfig: RouteConfigSpecifier;\n viewPortDefaults: Record;\n\n /**@internal */\n _fallbackRoute: string;\n\n /**\n * Adds a step to be run during the [[Router]]'s navigation pipeline.\n *\n * @param name The name of the pipeline slot to insert the step into.\n * @param step The pipeline step.\n * @chainable\n */\n addPipelineStep(name: string, step: Function | PipelineStep): RouterConfiguration {\n if (step === null || step === undefined) {\n throw new Error('Pipeline step cannot be null or undefined.');\n }\n this.pipelineSteps.push({ name, step });\n return this;\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s authorize pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addAuthorizeStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.Authorize, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preActivate pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreActivateStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreActivate, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreRender, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s postRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPostRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PostRender, step);\n }\n\n /**\n * Configures a route that will be used if there is no previous location available on navigation cancellation.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @chainable\n */\n fallbackRoute(fragment: string): RouterConfiguration {\n this._fallbackRoute = fragment;\n return this;\n }\n\n /**\n * Maps one or more routes to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map.\n * @chainable\n */\n map(route: RouteConfig | RouteConfig[]): RouterConfiguration {\n if (Array.isArray(route)) {\n route.forEach(this.map.bind(this));\n return this;\n }\n\n return this.mapRoute(route);\n }\n\n /**\n * Configures defaults to use for any view ports.\n *\n * @param viewPortConfig a view port configuration object to use as a\n * default, of the form { viewPortName: { moduleId } }.\n * @chainable\n */\n useViewPortDefaults(viewPortConfig: Record): RouterConfiguration {\n this.viewPortDefaults = viewPortConfig;\n return this;\n }\n\n /**\n * Maps a single route to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map.\n * @chainable\n */\n mapRoute(config: RouteConfig): RouterConfiguration {\n this.instructions.push(router => {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n\n let navModel;\n for (let i = 0, ii = routeConfigs.length; i < ii; ++i) {\n let routeConfig = routeConfigs[i];\n routeConfig.settings = routeConfig.settings || {};\n if (!navModel) {\n navModel = router.createNavModel(routeConfig);\n }\n\n router.addRoute(routeConfig, navModel);\n }\n });\n\n return this;\n }\n\n /**\n * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes.\n *\n * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the\n * [[NavigationInstruction]] and selects a moduleId to load.\n * @chainable\n */\n mapUnknownRoutes(config: RouteConfigSpecifier): RouterConfiguration {\n this.unknownRouteConfig = config;\n return this;\n }\n\n /**\n * Applies the current configuration to the specified [[Router]].\n *\n * @param router The [[Router]] to apply the configuration to.\n */\n exportToRouter(router: Router): void {\n let instructions = this.instructions;\n for (let i = 0, ii = instructions.length; i < ii; ++i) {\n instructions[i](router);\n }\n\n if (this.title) {\n router.title = this.title;\n }\n\n if (this.titleSeparator) {\n router.titleSeparator = this.titleSeparator;\n }\n\n if (this.unknownRouteConfig) {\n router.handleUnknownRoutes(this.unknownRouteConfig);\n }\n\n if (this._fallbackRoute) {\n router.fallbackRoute = this._fallbackRoute;\n }\n\n if (this.viewPortDefaults) {\n router.useViewPortDefaults(this.viewPortDefaults);\n }\n\n Object.assign(router.options, this.options);\n\n let pipelineSteps = this.pipelineSteps;\n if (pipelineSteps.length) {\n if (!router.isRoot) {\n throw new Error('Pipeline steps can only be added to the root router');\n }\n\n let pipelineProvider = router.pipelineProvider;\n for (let i = 0, ii = pipelineSteps.length; i < ii; ++i) {\n let { name, step } = pipelineSteps[i];\n pipelineProvider.addStep(name, step);\n }\n }\n }\n}\n","import { RouteRecognizer, RouteHandler, ConfigurableRoute, State, RecognizedRoute } from 'aurelia-route-recognizer';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { NavigationInstruction, NavigationInstructionInit } from './navigation-instruction';\nimport { NavModel } from './nav-model';\nimport { RouterConfiguration } from './router-configuration';\nimport {\n _ensureArrayWithSingleRoutePerConfig,\n _normalizeAbsolutePath,\n _createRootedPath,\n _resolveUrl\n} from './util';\nimport { RouteConfig, NavigationResult, RouteConfigSpecifier, ViewPort, ViewPortInstruction } from './interfaces';\nimport { PipelineProvider } from './pipeline-provider';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface History {\n // This is wrong, as it's an implementation detail from aurelia-history-browser\n // but we are poking it in here so probably will need to make it official in `aurelia-history`\n /**\n * A private flag of Aurelia History implementation to indicate if push state should be used\n */\n _hasPushState: boolean;\n\n previousLocation: string;\n }\n}\n\n/**@internal */\ndeclare module 'aurelia-route-recognizer' {\n interface State {\n types: {\n dynamics: DynamicSegment;\n stars: StarSegment;\n };\n }\n\n interface RouteHandler {\n navigationStrategy?: (instruction: NavigationInstruction) => any;\n }\n\n interface RecognizedRoute {\n config?: RouteConfig;\n queryParams?: Record;\n }\n}\n\ntype RouterConfigurationResolution = RouterConfiguration | ((cfg: RouterConfiguration) => void | RouterConfiguration | Promise);\n\n/**\n * The primary class responsible for handling routing and navigation.\n */\nexport class Router {\n\n /**\n * Container associated with this router. Also used to create child container for creating child router.\n */\n container: Container;\n\n /**\n * History instance of Aurelia abstract class for wrapping platform history global object\n */\n history: History;\n\n /**\n * A registry of registered viewport. Will be used to handle process navigation instruction route loading\n * and dom swapping\n */\n viewPorts: Record;\n\n /**\n * List of route configs registered with this router\n */\n routes: RouteConfig[];\n\n /**\n * The [[Router]]'s current base URL, typically based on the [[Router.currentInstruction]].\n */\n baseUrl: string;\n\n /**\n * If defined, used in generation of document title for [[Router]]'s routes.\n */\n title: string | undefined;\n\n /**\n * The separator used in the document title between [[Router]]'s routes.\n */\n titleSeparator: string | undefined;\n\n /**\n * True if the [[Router]] has been configured.\n */\n isConfigured: boolean;\n\n /**\n * True if the [[Router]] is currently processing a navigation.\n */\n isNavigating: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigate function(s).\n */\n isExplicitNavigation: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigateBack function.\n */\n isExplicitNavigationBack: boolean;\n\n /**\n * True if the [[Router]] is navigating into the app for the first time in the browser session.\n */\n isNavigatingFirst: boolean;\n\n /**\n * True if the [[Router]] is navigating to a page instance not in the browser session history.\n */\n isNavigatingNew: boolean;\n\n /**\n * True if the [[Router]] is navigating forward in the browser session history.\n */\n isNavigatingForward: boolean;\n\n /**\n * True if the [[Router]] is navigating back in the browser session history.\n */\n isNavigatingBack: boolean;\n\n /**\n * True if the [[Router]] is navigating due to a browser refresh.\n */\n isNavigatingRefresh: boolean;\n\n /**\n * True if the previous instruction successfully completed the CanDeactivatePreviousStep in the current navigation.\n */\n couldDeactivate: boolean;\n\n /**\n * The currently active navigation tracker.\n */\n currentNavigationTracker: number;\n\n /**\n * The navigation models for routes that specified [[RouteConfig.nav]].\n */\n navigation: NavModel[];\n\n /**\n * The currently active navigation instruction.\n */\n currentInstruction: NavigationInstruction;\n\n /**\n * The parent router, or null if this instance is not a child router.\n */\n parent: Router = null;\n\n options: any = {};\n\n /**\n * The defaults used when a viewport lacks specified content\n */\n viewPortDefaults: Record = {};\n\n /**@internal */\n catchAllHandler: (instruction: NavigationInstruction) => NavigationInstruction | Promise;\n /**@internal */\n fallbackRoute: string;\n /**@internal */\n pipelineProvider: PipelineProvider;\n /**@internal */\n _fallbackOrder: number;\n /**@internal */\n _recognizer: RouteRecognizer;\n /**@internal */\n _childRecognizer: RouteRecognizer;\n /**@internal */\n _configuredPromise: Promise;\n /**@internal */\n _resolveConfiguredPromise: (value?: any) => void;\n\n /**\n * Extension point to transform the document title before it is built and displayed.\n * By default, child routers delegate to the parent router, and the app router\n * returns the title unchanged.\n */\n transformTitle: (title: string) => string = (title: string) => {\n if (this.parent) {\n return this.parent.transformTitle(title);\n }\n return title;\n }\n\n /**\n * @param container The [[Container]] to use when child routers.\n * @param history The [[History]] implementation to delegate navigation requests to.\n */\n constructor(container: Container, history: History) {\n this.container = container;\n this.history = history;\n this.reset();\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset() {\n this.viewPorts = {};\n this.routes = [];\n this.baseUrl = '';\n this.isConfigured = false;\n this.isNavigating = false;\n this.isExplicitNavigation = false;\n this.isExplicitNavigationBack = false;\n this.isNavigatingFirst = false;\n this.isNavigatingNew = false;\n this.isNavigatingRefresh = false;\n this.isNavigatingForward = false;\n this.isNavigatingBack = false;\n this.couldDeactivate = false;\n this.navigation = [];\n this.currentInstruction = null;\n this.viewPortDefaults = {};\n this._fallbackOrder = 100;\n this._recognizer = new RouteRecognizer();\n this._childRecognizer = new RouteRecognizer();\n this._configuredPromise = new Promise(resolve => {\n this._resolveConfiguredPromise = resolve;\n });\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent.\n */\n get isRoot(): boolean {\n return !this.parent;\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort.\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/any, name?: string): void {\n name = name || 'default';\n this.viewPorts[name] = viewPort;\n }\n\n /**\n * Returns a Promise that resolves when the router is configured.\n */\n ensureConfigured(): Promise {\n return this._configuredPromise;\n }\n\n /**\n * Configures the router.\n *\n * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]].\n */\n configure(callbackOrConfig: RouterConfiguration | ((config: RouterConfiguration) => RouterConfiguration)): Promise {\n this.isConfigured = true;\n\n let result: RouterConfigurationResolution = callbackOrConfig as RouterConfiguration;\n let config: RouterConfiguration;\n if (typeof callbackOrConfig === 'function') {\n config = new RouterConfiguration();\n result = callbackOrConfig(config);\n }\n\n return Promise\n .resolve(result)\n .then((c) => {\n if (c && (c as RouterConfiguration).exportToRouter) {\n config = c;\n }\n\n config.exportToRouter(this);\n this.isConfigured = true;\n this._resolveConfiguredPromise();\n });\n }\n\n /**\n * Navigates to a new location.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n navigate(fragment: string, options?: NavigationOptions): boolean {\n if (!this.isConfigured && this.parent) {\n return this.parent.navigate(fragment, options);\n }\n\n this.isExplicitNavigation = true;\n return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options);\n }\n\n /**\n * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed\n * by [[Router.navigate]].\n *\n * @param route The name of the route to use when generating the navigation location.\n * @param params The route parameters to be used when populating the route pattern.\n * @param options The navigation options.\n */\n navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean {\n let path = this.generate(route, params);\n return this.navigate(path, options);\n }\n\n /**\n * Navigates back to the most recent location in history.\n */\n navigateBack(): void {\n this.isExplicitNavigationBack = true;\n this.history.navigateBack();\n }\n\n /**\n * Creates a child router of the current router.\n *\n * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified.\n * @returns {Router} The new child Router.\n */\n createChild(container?: Container): Router {\n let childRouter = new Router(container || this.container.createChild(), this.history);\n childRouter.parent = this;\n return childRouter;\n }\n\n /**\n * Generates a URL fragment matching the specified route pattern.\n *\n * @param name The name of the route whose pattern should be used to generate the fragment.\n * @param params The route params to be used to populate the route pattern.\n * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url.\n * @returns {string} A string containing the generated URL fragment.\n */\n generate(nameOrRoute: string | RouteConfig, params: any = {}, options: any = {}): string {\n // A child recognizer generates routes for potential child routes. Any potential child route is added\n // to the childRoute property of params for the childRouter to recognize. When generating routes, we\n // use the childRecognizer when childRoute params are available to generate a child router enabled route.\n let recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer;\n let hasRoute = recognizer.hasRoute(nameOrRoute as string | RouteHandler);\n if (!hasRoute) {\n if (this.parent) {\n return this.parent.generate(nameOrRoute, params, options);\n }\n throw new Error(`A route with name '${nameOrRoute}' could not be found. Check that \\`name: '${nameOrRoute}'\\` was specified in the route's config.`);\n }\n let path = recognizer.generate(nameOrRoute as string | RouteHandler, params);\n let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute);\n return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath;\n }\n\n /**\n * Creates a [[NavModel]] for the specified route config.\n *\n * @param config The route config.\n */\n createNavModel(config: RouteConfig): NavModel {\n let navModel = new NavModel(\n this,\n 'href' in config\n ? config.href\n // potential error when config.route is a string[] ?\n : config.route as string);\n navModel.title = config.title;\n navModel.order = config.nav;\n navModel.href = config.href;\n navModel.settings = config.settings;\n navModel.config = config;\n\n return navModel;\n }\n\n /**\n * Registers a new route with the router.\n *\n * @param config The [[RouteConfig]].\n * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes.\n */\n addRoute(config: RouteConfig, navModel?: NavModel): void {\n if (Array.isArray(config.route)) {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n // the following is wrong. todo: fix this after TS refactoring release\n routeConfigs.forEach(this.addRoute.bind(this));\n return;\n }\n\n validateRouteConfig(config);\n\n if (!('viewPorts' in config) && !config.navigationStrategy) {\n config.viewPorts = {\n 'default': {\n moduleId: config.moduleId,\n view: config.view\n }\n };\n }\n\n if (!navModel) {\n navModel = this.createNavModel(config);\n }\n\n this.routes.push(config);\n\n let path = config.route;\n if (path.charAt(0) === '/') {\n path = path.substr(1);\n }\n let caseSensitive = config.caseSensitive === true;\n let state: State = this._recognizer.add({\n path: path,\n handler: config as RouteHandler,\n caseSensitive: caseSensitive\n } as ConfigurableRoute);\n\n if (path) {\n let settings = config.settings;\n delete config.settings;\n let withChild = JSON.parse(JSON.stringify(config));\n config.settings = settings;\n withChild.route = `${path}/*childRoute`;\n withChild.hasChildRouter = true;\n this._childRecognizer.add({\n path: withChild.route,\n handler: withChild,\n caseSensitive: caseSensitive\n });\n\n withChild.navModel = navModel;\n withChild.settings = config.settings;\n withChild.navigationStrategy = config.navigationStrategy;\n }\n\n config.navModel = navModel;\n\n let navigation = this.navigation;\n\n if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) {\n if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) {\n throw new Error('Invalid route config for \"' + config.route + '\" : dynamic routes must specify an \"href:\" to be included in the navigation model.');\n }\n\n if (typeof navModel.order !== 'number') {\n navModel.order = ++this._fallbackOrder;\n }\n\n navigation.push(navModel);\n // this is a potential error / inconsistency between browsers\n //\n // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\n // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other,\n // but sorted with respect to all different elements.\n // Note: the ECMAscript standard does not guarantee this behaviour,\n // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.\n navigation.sort((a, b) => a.order - b.order);\n }\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasRoute(name: string): boolean {\n return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name));\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasOwnRoute(name: string): boolean {\n return this._recognizer.hasRoute(name);\n }\n\n /**\n * Register a handler to use when the incoming URL fragment doesn't match any registered routes.\n *\n * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]].\n */\n handleUnknownRoutes(config?: RouteConfigSpecifier): void {\n if (!config) {\n throw new Error('Invalid unknown route handler');\n }\n\n this.catchAllHandler = instruction => {\n return this\n ._createRouteConfig(config, instruction)\n .then(c => {\n instruction.config = c;\n return instruction;\n });\n };\n }\n\n /**\n * Updates the document title using the current navigation instruction.\n */\n updateTitle(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n return parentRouter.updateTitle();\n }\n\n let currentInstruction = this.currentInstruction;\n if (currentInstruction) {\n currentInstruction._updateTitle();\n }\n return undefined;\n }\n\n /**\n * Updates the navigation routes with hrefs relative to the current location.\n * Note: This method will likely move to a plugin in a future release.\n */\n refreshNavigation(): void {\n let nav = this.navigation;\n\n for (let i = 0, length = nav.length; i < length; i++) {\n let current = nav[i];\n if (!current.config.href) {\n current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState);\n } else {\n current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState);\n }\n }\n }\n\n /**\n * Sets the default configuration for the view ports. This specifies how to\n * populate a view port for which no module is specified. The default is\n * an empty view/view-model pair.\n */\n useViewPortDefaults($viewPortDefaults: Record): void {\n // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction\n let viewPortDefaults: Record = $viewPortDefaults;\n for (let viewPortName in viewPortDefaults) {\n let viewPortConfig = viewPortDefaults[viewPortName];\n this.viewPortDefaults[viewPortName] = {\n moduleId: viewPortConfig.moduleId\n };\n }\n }\n\n /**@internal */\n _refreshBaseUrl(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction);\n }\n }\n\n /**@internal */\n _createNavigationInstruction(url: string = '', parentInstruction: NavigationInstruction = null): Promise {\n let fragment = url;\n let queryString = '';\n\n let queryIndex = url.indexOf('?');\n if (queryIndex !== -1) {\n fragment = url.substr(0, queryIndex);\n queryString = url.substr(queryIndex + 1);\n }\n\n let urlRecognizationResults = this._recognizer.recognize(url) as IRouteRecognizationResults;\n if (!urlRecognizationResults || !urlRecognizationResults.length) {\n urlRecognizationResults = this._childRecognizer.recognize(url) as IRouteRecognizationResults;\n }\n\n let instructionInit: NavigationInstructionInit = {\n fragment,\n queryString,\n config: null,\n parentInstruction,\n previousInstruction: this.currentInstruction,\n router: this,\n options: {\n compareQueryParams: this.options.compareQueryParams\n }\n };\n\n let result: Promise;\n\n if (urlRecognizationResults && urlRecognizationResults.length) {\n let first = urlRecognizationResults[0];\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: first.params,\n queryParams: first.queryParams || urlRecognizationResults.queryParams,\n config: first.config || first.handler\n }));\n\n if (typeof first.handler === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler, first);\n } else if (first.handler && typeof first.handler.navigationStrategy === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler);\n } else {\n result = Promise.resolve(instruction);\n }\n } else if (this.catchAllHandler) {\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n config: null // config will be created by the catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, this.catchAllHandler);\n } else if (this.parent) {\n let router = this._parentCatchAllHandler(this.parent);\n\n if (router) {\n let newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction);\n\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n router: router,\n parentInstruction: newParentInstruction,\n parentCatchHandler: true,\n config: null // config will be created by the chained parent catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, router.catchAllHandler);\n }\n }\n\n if (result && parentInstruction) {\n this.baseUrl = generateBaseUrl(this.parent, parentInstruction);\n }\n\n return result || Promise.reject(new Error(`Route not found: ${url}`));\n }\n\n /**@internal */\n _findParentInstructionFromRouter(router: Router, instruction: NavigationInstruction): NavigationInstruction {\n if (instruction.router === router) {\n instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId\n return instruction;\n } else if (instruction.parentInstruction) {\n return this._findParentInstructionFromRouter(router, instruction.parentInstruction);\n }\n return undefined;\n }\n\n /**@internal */\n _parentCatchAllHandler(router: Router): Router | false {\n if (router.catchAllHandler) {\n return router;\n } else if (router.parent) {\n return this._parentCatchAllHandler(router.parent);\n }\n return false;\n }\n\n /**\n * @internal\n */\n _createRouteConfig(config: RouteConfigSpecifier, instruction: NavigationInstruction): Promise {\n return Promise\n .resolve(config)\n .then((c: any) => {\n if (typeof c === 'string') {\n return { moduleId: c } as RouteConfig;\n } else if (typeof c === 'function') {\n return c(instruction);\n }\n\n return c;\n })\n // typing here could be either RouteConfig or RedirectConfig\n // but temporarily treat both as RouteConfig\n // todo: improve typings precision\n .then((c: string | RouteConfig) => typeof c === 'string' ? { moduleId: c } as RouteConfig : c)\n .then((c: RouteConfig) => {\n c.route = instruction.params.path;\n validateRouteConfig(c);\n\n if (!c.navModel) {\n c.navModel = this.createNavModel(c);\n }\n\n return c;\n });\n }\n}\n\n/* @internal exported for unit testing */\nexport const generateBaseUrl = (router: Router, instruction: NavigationInstruction): string => {\n return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`;\n};\n\n/* @internal exported for unit testing */\nexport const validateRouteConfig = (config: RouteConfig): void => {\n if (typeof config !== 'object') {\n throw new Error('Invalid Route Config');\n }\n\n if (typeof config.route !== 'string') {\n let name = config.name || '(no name)';\n throw new Error('Invalid Route Config for \"' + name + '\": You must specify a \"route:\" pattern.');\n }\n\n if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) {\n throw new Error('Invalid Route Config for \"' + config.route + '\": You must specify a \"moduleId:\", \"redirect:\", \"navigationStrategy:\", or \"viewPorts:\".');\n }\n};\n\n/* @internal exported for unit testing */\nexport const evaluateNavigationStrategy = (\n instruction: NavigationInstruction,\n evaluator: Function,\n context?: any\n): Promise => {\n return Promise.resolve(evaluator.call(context, instruction)).then(() => {\n if (!('viewPorts' in instruction.config)) {\n instruction.config.viewPorts = {\n 'default': {\n moduleId: instruction.config.moduleId\n }\n };\n }\n\n return instruction;\n });\n};\n\ninterface IRouteRecognizationResults extends Array {\n queryParams: Record;\n}\n","import { PipelineStatus } from './pipeline-status';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Next, StepRunnerFunction, NextCompletionHandler } from './interfaces';\n\n/**@internal exported for unit testing */\nexport const createNextFn = (instruction: NavigationInstruction, steps: StepRunnerFunction[]): Next => {\n let index = -1;\n const next: Next = function() {\n index++;\n\n if (index < steps.length) {\n let currentStep = steps[index];\n\n try {\n return currentStep(instruction, next);\n } catch (e) {\n return next.reject(e);\n }\n } else {\n return next.complete();\n }\n } as Next;\n\n next.complete = createCompletionHandler(next, PipelineStatus.Completed);\n next.cancel = createCompletionHandler(next, PipelineStatus.Canceled);\n next.reject = createCompletionHandler(next, PipelineStatus.Rejected);\n\n return next;\n};\n\n/**@internal exported for unit testing */\nexport const createCompletionHandler = (next: Next, status: PipelineStatus): NextCompletionHandler => {\n return (output: any) => Promise\n .resolve({\n status,\n output,\n completed: status === PipelineStatus.Completed\n });\n};\n","import { PipelineStep, PipelineResult, Next, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { createNextFn } from './next';\n\n/**\n* The class responsible for managing and processing the navigation pipeline.\n*/\nexport class Pipeline {\n /**\n * The pipeline steps. And steps added via addStep will be converted to a function\n * The actualy running functions with correct step contexts of this pipeline\n */\n steps: StepRunnerFunction[] = [];\n\n /**\n * Adds a step to the pipeline.\n *\n * @param step The pipeline step.\n */\n addStep(step: StepRunnerFunction | PipelineStep | IPipelineSlot): Pipeline {\n let run;\n\n if (typeof step === 'function') {\n run = step;\n } else if (typeof step.getSteps === 'function') {\n // getSteps is to enable support open slots\n // where devs can add multiple steps into the same slot name\n let steps = step.getSteps();\n for (let i = 0, l = steps.length; i < l; i++) {\n this.addStep(steps[i]);\n }\n\n return this;\n } else {\n run = (step as PipelineStep).run.bind(step);\n }\n\n this.steps.push(run);\n\n return this;\n }\n\n /**\n * Runs the pipeline.\n *\n * @param instruction The navigation instruction to process.\n */\n run(instruction: NavigationInstruction): Promise {\n const nextFn = createNextFn(instruction, this.steps);\n return nextFn();\n }\n}\n","import { Next, RouteConfig, ViewPortComponent, ViewPortPlan, ViewPortInstruction } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy, _buildNavigationPlan } from './navigation-plan';\nimport { Router } from './router';\n\n/**\n * Loading plan calculated based on a navigration-instruction and a viewport plan\n */\ninterface ILoadingPlan {\n viewPortPlan: ViewPortPlan;\n navigationInstruction: NavigationInstruction;\n}\n\n/**\n * Abstract class that is responsible for loading view / view model from a route config\n * The default implementation can be found in `aurelia-templating-router`\n */\nexport class RouteLoader {\n /**\n * Load a route config based on its viewmodel / view configuration\n */\n // return typing: return typings used to be never\n // as it was a throw. Changing it to Promise should not cause any issues\n loadRoute(router: Router, config: RouteConfig, navigationInstruction: NavigationInstruction): Promise {\n throw new Error('Route loaders must implement \"loadRoute(router, config, navigationInstruction)\".');\n }\n}\n\n/**\n * A pipeline step responsible for loading a route config of a navigation instruction\n */\nexport class LoadRouteStep {\n /**@internal */\n static inject() { return [RouteLoader]; }\n /**\n * Route loader isntance that will handle loading route config\n * @internal\n */\n routeLoader: RouteLoader;\n\n constructor(routeLoader: RouteLoader) {\n this.routeLoader = routeLoader;\n }\n\n /**\n * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline\n */\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return loadNewRoute(this.routeLoader, navigationInstruction)\n .then(next, next.cancel);\n }\n}\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadNewRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction\n): Promise => {\n let toLoad = determineWhatToLoad(navigationInstruction);\n let loadPromises = toLoad.map((loadingPlan: ILoadingPlan) => loadRoute(\n routeLoader,\n loadingPlan.navigationInstruction,\n loadingPlan.viewPortPlan\n ));\n\n return Promise.all(loadPromises);\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const determineWhatToLoad = (\n navigationInstruction: NavigationInstruction,\n toLoad: ILoadingPlan[] = []\n): ILoadingPlan[] => {\n let plan: Record = navigationInstruction.plan;\n\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let child_nav_instruction = viewPortPlan.childNavigationInstruction;\n\n if (viewPortPlan.strategy === activationStrategy.replace) {\n toLoad.push({ viewPortPlan, navigationInstruction } as ILoadingPlan);\n\n if (child_nav_instruction) {\n determineWhatToLoad(child_nav_instruction, toLoad);\n }\n } else {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction(\n viewPortName,\n viewPortPlan.strategy,\n viewPortPlan.prevModuleId,\n viewPortPlan.prevComponent\n ) as ViewPortInstruction;\n\n if (child_nav_instruction) {\n viewPortInstruction.childNavigationInstruction = child_nav_instruction;\n determineWhatToLoad(child_nav_instruction, toLoad);\n }\n }\n }\n\n return toLoad;\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n viewPortPlan: ViewPortPlan\n): Promise => {\n let moduleId = viewPortPlan.config ? viewPortPlan.config.moduleId : null;\n\n return loadComponent(routeLoader, navigationInstruction, viewPortPlan.config)\n .then((component) => {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction(\n viewPortPlan.name,\n viewPortPlan.strategy,\n moduleId,\n component\n ) as ViewPortInstruction;\n\n let childRouter = component.childRouter;\n if (childRouter) {\n let path = navigationInstruction.getWildcardPath();\n\n return childRouter\n ._createNavigationInstruction(path, navigationInstruction)\n .then((childInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(childInstruction)\n .then((childPlan) => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n viewPortInstruction.childNavigationInstruction = childInstruction;\n\n return loadNewRoute(routeLoader, childInstruction);\n });\n });\n }\n // ts complains without this, though they are same\n return void 0;\n });\n};\n\n/**\n * Load a routed-component based on navigation instruction and route config\n * @internal exported for unit testing only\n */\nexport const loadComponent = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n config: RouteConfig\n): Promise => {\n let router = navigationInstruction.router;\n let lifecycleArgs = navigationInstruction.lifecycleArgs;\n\n return Promise.resolve()\n .then(() => routeLoader.loadRoute(router, config, navigationInstruction))\n .then(\n /**\n * @param component an object carrying information about loaded route\n * typically contains information about view model, childContainer, view and router\n */\n (component: ViewPortComponent) => {\n let { viewModel, childContainer } = component;\n component.router = router;\n component.config = config;\n\n if ('configureRouter' in viewModel) {\n let childRouter = childContainer.getChildRouter();\n component.childRouter = childRouter;\n\n return childRouter\n .configure(c => viewModel.configureRouter(c, childRouter, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]))\n .then(() => component);\n }\n\n return component;\n });\n};\n","import { Container } from 'aurelia-dependency-injection';\nimport { Pipeline } from './pipeline';\nimport { BuildNavigationPlanStep } from './navigation-plan';\nimport { LoadRouteStep } from './route-loading';\nimport { CommitChangesStep } from './navigation-instruction';\nimport {\n CanDeactivatePreviousStep,\n CanActivateNextStep,\n DeactivatePreviousStep,\n ActivateNextStep\n} from './activation';\nimport { PipelineStep, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution\n */\nclass PipelineSlot implements IPipelineSlot {\n\n /**@internal */\n container: Container;\n /**@internal */\n slotName: string;\n /**@internal */\n slotAlias?: string;\n\n steps: (Function | PipelineStep)[] = [];\n\n constructor(container: Container, name: string, alias?: string) {\n this.container = container;\n this.slotName = name;\n this.slotAlias = alias;\n }\n\n getSteps(): (StepRunnerFunction | IPipelineSlot | PipelineStep)[] {\n return this.steps.map(x => this.container.get(x));\n }\n}\n\n/**\n* Class responsible for creating the navigation pipeline.\n*/\nexport class PipelineProvider {\n\n /**@internal */\n static inject() { return [Container]; }\n /**@internal */\n container: Container;\n /**@internal */\n steps: (Function | PipelineSlot)[];\n\n constructor(container: Container) {\n this.container = container;\n this.steps = [\n BuildNavigationPlanStep,\n CanDeactivatePreviousStep, // optional\n LoadRouteStep,\n this._createPipelineSlot(PipelineSlotName.Authorize),\n CanActivateNextStep, // optional\n this._createPipelineSlot(PipelineSlotName.PreActivate, 'modelbind'),\n // NOTE: app state changes start below - point of no return\n DeactivatePreviousStep, // optional\n ActivateNextStep, // optional\n this._createPipelineSlot(PipelineSlotName.PreRender, 'precommit'),\n CommitChangesStep,\n this._createPipelineSlot(PipelineSlotName.PostRender, 'postcomplete')\n ];\n }\n\n /**\n * Create the navigation pipeline.\n */\n createPipeline(useCanDeactivateStep: boolean = true): Pipeline {\n let pipeline = new Pipeline();\n this.steps.forEach(step => {\n if (useCanDeactivateStep || step !== CanDeactivatePreviousStep) {\n pipeline.addStep(this.container.get(step));\n }\n });\n return pipeline;\n }\n\n /**@internal */\n _findStep(name: string): PipelineSlot {\n // Steps that are not PipelineSlots are constructor functions, and they will automatically fail. Probably.\n return this.steps.find(x => (x as PipelineSlot).slotName === name || (x as PipelineSlot).slotAlias === name) as PipelineSlot;\n }\n\n /**\n * Adds a step into the pipeline at a known slot location.\n */\n addStep(name: string, step: PipelineStep | Function): void {\n let found = this._findStep(name);\n if (found) {\n // prevent duplicates\n if (!found.steps.includes(step)) {\n found.steps.push(step);\n }\n } else {\n throw new Error(`Invalid pipeline slot name: ${name}.`);\n }\n }\n\n /**\n * Removes a step from a slot in the pipeline\n */\n removeStep(name: string, step: PipelineStep): void {\n let slot = this._findStep(name);\n if (slot) {\n let steps = slot.steps;\n steps.splice(steps.indexOf(step), 1);\n }\n }\n\n /**\n * @internal\n * Clears all steps from a slot in the pipeline\n */\n _clearSteps(name: string = ''): void {\n let slot = this._findStep(name);\n if (slot) {\n slot.steps = [];\n }\n }\n\n /**\n * Resets all pipeline slots\n */\n reset(): void {\n this._clearSteps('authorize');\n this._clearSteps('preActivate');\n this._clearSteps('preRender');\n this._clearSteps('postRender');\n }\n\n /**@internal */\n _createPipelineSlot(name: string, alias?: string): PipelineSlot {\n return new PipelineSlot(this.container, name, alias);\n }\n}\n","import * as LogManager from 'aurelia-logging';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\nimport { PipelineProvider } from './pipeline-provider';\nimport { isNavigationCommand } from './navigation-commands';\nimport { EventAggregator } from 'aurelia-event-aggregator';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { ViewPort, ConfiguresRouter, PipelineResult } from './interfaces';\nimport { RouterEvent } from './router-event';\n\n/**@internal */\ndeclare module 'aurelia-dependency-injection' {\n interface Container {\n viewModel?: any;\n }\n}\n\nconst logger = LogManager.getLogger('app-router');\n\n/**\n* The main application router.\n*/\nexport class AppRouter extends Router {\n\n /**@internal */\n static inject() { return [Container, History, PipelineProvider, EventAggregator]; }\n\n events: EventAggregator;\n /**@internal */\n maxInstructionCount: number;\n /**@internal */\n _queue: NavigationInstruction[];\n /**@internal */\n isActive: boolean;\n\n constructor(container: Container, history: History, pipelineProvider: PipelineProvider, events: EventAggregator) {\n super(container, history); // Note the super will call reset internally.\n this.pipelineProvider = pipelineProvider;\n this.events = events;\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset(): void {\n super.reset();\n this.maxInstructionCount = 10;\n if (!this._queue) {\n this._queue = [];\n } else {\n this._queue.length = 0;\n }\n }\n\n /**\n * Loads the specified URL.\n *\n * @param url The URL fragment to load.\n */\n loadUrl(url: string): Promise {\n return this\n ._createNavigationInstruction(url)\n .then(instruction => this._queueInstruction(instruction))\n .catch(error => {\n logger.error(error);\n restorePreviousLocation(this);\n });\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort. This is typically a element in Aurelia default impl\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/ any, name?: string): Promise {\n // having strong typing without changing public API\n const $viewPort: ViewPort = viewPort;\n super.registerViewPort($viewPort, name);\n\n // beside adding viewport to the registry of this instance\n // AppRouter also configure routing/history to start routing functionality\n // There are situation where there are more than 1 element at root view\n // in that case, still only activate once via the following guard\n if (!this.isActive) {\n const viewModel = this._findViewModel($viewPort);\n if ('configureRouter' in viewModel) {\n // If there are more than one element at root view\n // use this flag to guard against configure method being invoked multiple times\n // this flag is set inside method configure\n if (!this.isConfigured) {\n // replace the real resolve with a noop to guarantee that any action in base class Router\n // won't resolve the configurePromise prematurely\n const resolveConfiguredPromise = this._resolveConfiguredPromise;\n this._resolveConfiguredPromise = () => {/**/};\n return this\n .configure(config => {\n viewModel.configureRouter(config, this);\n return config;\n })\n .then(() => {\n this.activate();\n resolveConfiguredPromise();\n });\n }\n } else {\n this.activate();\n }\n }\n // when a viewport is added dynamically to a root view that is already activated\n // just process the navigation instruction\n else {\n this._dequeueInstruction();\n }\n\n return Promise.resolve();\n }\n\n /**\n * Activates the router. This instructs the router to begin listening for history changes and processing instructions.\n *\n * @params options The set of options to activate the router with.\n */\n activate(options?: NavigationOptions): void {\n if (this.isActive) {\n return;\n }\n\n this.isActive = true;\n // route handler property is responsible for handling url change\n // the interface of aurelia-history isn't clear on this perspective\n this.options = Object.assign({ routeHandler: this.loadUrl.bind(this) }, this.options, options);\n this.history.activate(this.options);\n this._dequeueInstruction();\n }\n\n /**\n * Deactivates the router.\n */\n deactivate(): void {\n this.isActive = false;\n this.history.deactivate();\n }\n\n /**@internal */\n _queueInstruction(instruction: NavigationInstruction): Promise {\n return new Promise((resolve) => {\n instruction.resolve = resolve;\n this._queue.unshift(instruction);\n this._dequeueInstruction();\n });\n }\n\n /**@internal */\n _dequeueInstruction(instructionCount: number = 0): Promise {\n return Promise.resolve().then(() => {\n if (this.isNavigating && !instructionCount) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n let instruction = this._queue.shift();\n this._queue.length = 0;\n\n if (!instruction) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n this.isNavigating = true;\n\n let navtracker: number = this.history.getState('NavigationTracker');\n if (!navtracker && !this.currentNavigationTracker) {\n this.isNavigatingFirst = true;\n this.isNavigatingNew = true;\n } else if (!navtracker) {\n this.isNavigatingNew = true;\n } else if (!this.currentNavigationTracker) {\n this.isNavigatingRefresh = true;\n } else if (this.currentNavigationTracker < navtracker) {\n this.isNavigatingForward = true;\n } else if (this.currentNavigationTracker > navtracker) {\n this.isNavigatingBack = true;\n } if (!navtracker) {\n navtracker = Date.now();\n this.history.setState('NavigationTracker', navtracker);\n }\n this.currentNavigationTracker = navtracker;\n\n instruction.previousInstruction = this.currentInstruction;\n\n if (!instructionCount) {\n this.events.publish(RouterEvent.Processing, { instruction });\n } else if (instructionCount === this.maxInstructionCount - 1) {\n logger.error(`${instructionCount + 1} navigation instructions have been attempted without success. Restoring last known good location.`);\n restorePreviousLocation(this);\n return this._dequeueInstruction(instructionCount + 1);\n } else if (instructionCount > this.maxInstructionCount) {\n throw new Error('Maximum navigation attempts exceeded. Giving up.');\n }\n\n let pipeline = this.pipelineProvider.createPipeline(!this.couldDeactivate);\n\n return pipeline\n .run(instruction)\n .then(result => processResult(instruction, result, instructionCount, this))\n .catch(error => {\n return { output: error instanceof Error ? error : new Error(error) } as PipelineResult;\n })\n .then(result => resolveInstruction(instruction, result, !!instructionCount, this));\n });\n }\n\n /**@internal */\n _findViewModel(viewPort: ViewPort): ConfiguresRouter | undefined {\n if (this.container.viewModel) {\n return this.container.viewModel;\n }\n\n if (viewPort.container) {\n let container = viewPort.container;\n\n while (container) {\n if (container.viewModel) {\n this.container.viewModel = container.viewModel;\n return container.viewModel;\n }\n\n container = container.parent;\n }\n }\n\n return undefined;\n }\n}\n\nconst processResult = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n instructionCount: number,\n router: AppRouter\n): Promise => {\n if (!(result && 'completed' in result && 'output' in result)) {\n result = result || {} as PipelineResult;\n result.output = new Error(`Expected router pipeline to return a navigation result, but got [${JSON.stringify(result)}] instead.`);\n }\n\n let finalResult: PipelineResult = null;\n let navigationCommandResult = null;\n if (isNavigationCommand(result.output)) {\n navigationCommandResult = result.output.navigate(router);\n } else {\n finalResult = result;\n\n if (!result.completed) {\n if (result.output instanceof Error) {\n logger.error(result.output.toString());\n }\n\n restorePreviousLocation(router);\n }\n }\n\n return Promise.resolve(navigationCommandResult)\n .then(_ => router._dequeueInstruction(instructionCount + 1))\n .then(innerResult => finalResult || innerResult || result);\n};\n\nconst resolveInstruction = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n isInnerInstruction: boolean,\n router: AppRouter\n): PipelineResult => {\n instruction.resolve(result);\n\n let eventArgs = { instruction, result };\n if (!isInnerInstruction) {\n router.isNavigating = false;\n router.isExplicitNavigation = false;\n router.isExplicitNavigationBack = false;\n router.isNavigatingFirst = false;\n router.isNavigatingNew = false;\n router.isNavigatingRefresh = false;\n router.isNavigatingForward = false;\n router.isNavigatingBack = false;\n router.couldDeactivate = false;\n\n let eventName: string;\n\n if (result.output instanceof Error) {\n eventName = RouterEvent.Error;\n } else if (!result.completed) {\n eventName = RouterEvent.Canceled;\n } else {\n let queryString = instruction.queryString ? ('?' + instruction.queryString) : '';\n router.history.previousLocation = instruction.fragment + queryString;\n eventName = RouterEvent.Success;\n }\n\n router.events.publish(eventName, eventArgs);\n router.events.publish(RouterEvent.Complete, eventArgs);\n } else {\n router.events.publish(RouterEvent.ChildComplete, eventArgs);\n }\n\n return result;\n};\n\nconst restorePreviousLocation = (router: AppRouter): void => {\n let previousLocation = router.history.previousLocation;\n if (previousLocation) {\n router.navigate(router.history.previousLocation, { trigger: false, replace: true });\n } else if (router.fallbackRoute) {\n router.navigate(router.fallbackRoute, { trigger: true, replace: true });\n } else {\n logger.error('Router navigation failed, and no previous location or fallbackRoute could be restored.');\n }\n};\n","/**\n* The status of a Pipeline.\n*/\nexport const enum PipelineStatus {\n Completed = 'completed',\n Canceled = 'canceled',\n Rejected = 'rejected',\n Running = 'running'\n}\n","/**\n * A list of known router events used by the Aurelia router\n * to signal the pipeline has come to a certain state\n */\n// const enum is preserved in tsconfig\nexport const enum RouterEvent {\n Processing = 'router:navigation:processing',\n Error = 'router:navigation:error',\n Canceled = 'router:navigation:canceled',\n Complete = 'router:navigation:complete',\n Success = 'router:navigation:success',\n ChildComplete = 'router:navigation:child:complete'\n}\n","/**\n * Available pipeline slot names to insert interceptor into router pipeline\n */\n// const enum is preserved in tsconfig\nexport const enum PipelineSlotName {\n /**\n * Authorization slot. Invoked early in the pipeline,\n * before `canActivate` hook of incoming route\n */\n Authorize = 'authorize',\n /**\n * Pre-activation slot. Invoked early in the pipeline,\n * Invoked timing:\n * - after Authorization slot\n * - after canActivate hook on new view model\n * - before deactivate hook on old view model\n * - before activate hook on new view model\n */\n PreActivate = 'preActivate',\n /**\n * Pre-render slot. Invoked later in the pipeline\n * Invokcation timing:\n * - after activate hook on new view model\n * - before commit step on new navigation instruction\n */\n PreRender = 'preRender',\n /**\n * Post-render slot. Invoked last in the pipeline\n */\n PostRender = 'postRender'\n}\n"],"names":["RouteRecognizer","Container","LogManager.getLogger","tslib_1.__extends","History","EventAggregator","PipelineStatus","RouterEvent","PipelineSlotName"],"mappings":";;;;;;;;;;AAuBA;;;;;;A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,mBAAW,KAAXA,mBAAW,QAO5B;;ACZD;;;AAGA,AACA,WAAkB,gBAAgB;;;;;IAKhC,2CAAuB,CAAA;;;;;;;;;IASvB,+CAA2B,CAAA;;;;;;;IAO3B,2CAAuB,CAAA;;;;IAIvB,6CAAyB,CAAA;CAC1B,EA1BiBC,wBAAgB,KAAhBA,wBAAgB,QA0BjC;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"aurelia-router.js","sources":["../../src/navigation-instruction.ts","../../src/nav-model.ts","../../src/util.ts","../../src/router-configuration.ts","../../src/router.ts","../../src/next.ts","../../src/pipeline.ts","../../src/navigation-commands.ts","../../src/navigation-plan.ts","../../src/step-build-navigation-plan.ts","../../src/utilities-route-loading.ts","../../src/route-loader.ts","../../src/step-load-route.ts","../../src/step-commit-changes.ts","../../src/activation-strategy.ts","../../src/utilities-activation.ts","../../src/step-activation.ts","../../src/pipeline-provider.ts","../../src/app-router.ts","../../src/pipeline-status.ts","../../src/router-event.ts","../../src/pipeline-slot-name.ts"],"sourcesContent":["import { ViewPortInstruction, RouteConfig, ViewPort, LifecycleArguments, ViewPortComponent } from './interfaces';\nimport { Router } from './router';\nimport { ActivationStrategyType, InternalActivationStrategy } from './activation-strategy';\n\n/**\n * Initialization options for a navigation instruction\n */\nexport interface NavigationInstructionInit {\n fragment: string;\n queryString?: string;\n params?: Record;\n queryParams?: Record;\n config: RouteConfig;\n parentInstruction?: NavigationInstruction;\n previousInstruction?: NavigationInstruction;\n router: Router;\n options?: Object;\n plan?: Record;\n}\n\nexport interface ViewPortInstructionInit {\n name: string;\n strategy: ActivationStrategyType;\n moduleId: string;\n component: ViewPortComponent;\n}\n\n/**\n * Class used to represent an instruction during a navigation.\n */\nexport class NavigationInstruction {\n /**\n * The URL fragment.\n */\n fragment: string;\n\n /**\n * The query string.\n */\n queryString: string;\n\n /**\n * Parameters extracted from the route pattern.\n */\n params: any;\n\n /**\n * Parameters extracted from the query string.\n */\n queryParams: any;\n\n /**\n * The route config for the route matching this instruction.\n */\n config: RouteConfig;\n\n /**\n * The parent instruction, if this instruction was created by a child router.\n */\n parentInstruction: NavigationInstruction;\n\n parentCatchHandler: any;\n\n /**\n * The instruction being replaced by this instruction in the current router.\n */\n previousInstruction: NavigationInstruction;\n\n /**\n * viewPort instructions to used activation.\n */\n viewPortInstructions: Record;\n\n /**\n * The router instance.\n */\n router: Router;\n\n /**\n * Current built viewport plan of this nav instruction\n */\n plan: Record = null;\n\n options: Record = {};\n\n /**@internal */\n lifecycleArgs: LifecycleArguments;\n /**@internal */\n resolve?: (val?: any) => void;\n\n constructor(init: NavigationInstructionInit) {\n Object.assign(this, init);\n\n this.params = this.params || {};\n this.viewPortInstructions = {};\n\n let ancestorParams = [];\n let current: NavigationInstruction = this;\n do {\n let currentParams = Object.assign({}, current.params);\n if (current.config && current.config.hasChildRouter) {\n // remove the param for the injected child route segment\n delete currentParams[current.getWildCardName()];\n }\n\n ancestorParams.unshift(currentParams);\n current = current.parentInstruction;\n } while (current);\n\n let allParams = Object.assign({}, this.queryParams, ...ancestorParams);\n this.lifecycleArgs = [allParams, this.config, this];\n }\n\n /**\n * Gets an array containing this instruction and all child instructions for the current navigation.\n */\n getAllInstructions(): Array {\n let instructions: NavigationInstruction[] = [this];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let key in viewPortInstructions) {\n let childInstruction = viewPortInstructions[key].childNavigationInstruction;\n if (childInstruction) {\n instructions.push(...childInstruction.getAllInstructions());\n }\n }\n\n return instructions;\n }\n\n /**\n * Gets an array containing the instruction and all child instructions for the previous navigation.\n * Previous instructions are no longer available after navigation completes.\n */\n getAllPreviousInstructions(): Array {\n return this.getAllInstructions().map(c => c.previousInstruction).filter(c => c);\n }\n\n /**\n * Adds a viewPort instruction. Returns the newly created instruction based on parameters\n */\n addViewPortInstruction(initOptions: ViewPortInstructionInit): /*ViewPortInstruction*/ any;\n addViewPortInstruction(viewPortName: string, strategy: ActivationStrategyType, moduleId: string, component: any): /*ViewPortInstruction*/ any;\n addViewPortInstruction(\n nameOrInitOptions: string | ViewPortInstructionInit,\n strategy?: ActivationStrategyType,\n moduleId?: string,\n component?: any\n ): /*ViewPortInstruction*/ any {\n\n let viewPortInstruction: ViewPortInstruction;\n let viewPortName = typeof nameOrInitOptions === 'string' ? nameOrInitOptions : nameOrInitOptions.name;\n const lifecycleArgs = this.lifecycleArgs;\n const config: RouteConfig = Object.assign({}, lifecycleArgs[1], { currentViewPort: viewPortName });\n\n if (typeof nameOrInitOptions === 'string') {\n viewPortInstruction = {\n name: nameOrInitOptions,\n strategy: strategy,\n moduleId: moduleId,\n component: component,\n childRouter: component.childRouter,\n lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] as LifecycleArguments\n };\n } else {\n viewPortInstruction = {\n name: viewPortName,\n strategy: nameOrInitOptions.strategy,\n component: nameOrInitOptions.component,\n moduleId: nameOrInitOptions.moduleId,\n childRouter: nameOrInitOptions.component.childRouter,\n lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] as LifecycleArguments\n };\n }\n\n return this.viewPortInstructions[viewPortName] = viewPortInstruction;\n }\n\n /**\n * Gets the name of the route pattern's wildcard parameter, if applicable.\n */\n getWildCardName(): string {\n // todo: potential issue, or at least unsafe typings\n let configRoute = this.config.route as string;\n let wildcardIndex = configRoute.lastIndexOf('*');\n return configRoute.substr(wildcardIndex + 1);\n }\n\n /**\n * Gets the path and query string created by filling the route\n * pattern's wildcard parameter with the matching param.\n */\n getWildcardPath(): string {\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n let queryString = this.queryString;\n\n if (queryString) {\n path += '?' + queryString;\n }\n\n return path;\n }\n\n /**\n * Gets the instruction's base URL, accounting for wildcard route parameters.\n */\n getBaseUrl(): string {\n let $encodeURI = encodeURI;\n let fragment = decodeURI(this.fragment);\n\n if (fragment === '') {\n let nonEmptyRoute = this.router.routes.find(route => {\n return route.name === this.config.name &&\n route.route !== '';\n });\n if (nonEmptyRoute) {\n fragment = nonEmptyRoute.route as any;\n }\n }\n\n if (!this.params) {\n return $encodeURI(fragment);\n }\n\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n\n if (!path) {\n return $encodeURI(fragment);\n }\n\n return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path)));\n }\n\n /**\n * Finalize a viewport instruction\n * @internal\n */\n _commitChanges(waitToSwap: boolean): Promise {\n let router = this.router;\n router.currentInstruction = this;\n\n const previousInstruction = this.previousInstruction;\n if (previousInstruction) {\n previousInstruction.config.navModel.isActive = false;\n }\n\n this.config.navModel.isActive = true;\n\n router.refreshNavigation();\n\n let loads: Promise[] = [];\n let delaySwaps: ISwapPlan[] = [];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let viewPort = router.viewPorts[viewPortName];\n\n if (!viewPort) {\n throw new Error(`There was no router-view found in the view for ${viewPortInstruction.moduleId}.`);\n }\n\n let childNavInstruction = viewPortInstruction.childNavigationInstruction;\n if (viewPortInstruction.strategy === InternalActivationStrategy.Replace) {\n if (childNavInstruction && childNavInstruction.parentCatchHandler) {\n loads.push(childNavInstruction._commitChanges(waitToSwap));\n } else {\n if (waitToSwap) {\n delaySwaps.push({ viewPort, viewPortInstruction });\n }\n loads.push(\n viewPort\n .process(viewPortInstruction, waitToSwap)\n .then(() => childNavInstruction\n ? childNavInstruction._commitChanges(waitToSwap)\n : Promise.resolve()\n )\n );\n }\n } else {\n if (childNavInstruction) {\n loads.push(childNavInstruction._commitChanges(waitToSwap));\n }\n }\n }\n\n return Promise\n .all(loads)\n .then(() => {\n delaySwaps.forEach(x => x.viewPort.swap(x.viewPortInstruction));\n return null;\n })\n .then(() => prune(this));\n }\n\n /**@internal */\n _updateTitle(): void {\n let router = this.router;\n let title = this._buildTitle(router.titleSeparator);\n if (title) {\n router.history.setTitle(title);\n }\n }\n\n /**@internal */\n _buildTitle(separator: string = ' | '): string {\n let title = '';\n let childTitles = [];\n let navModelTitle = this.config.navModel.title;\n let instructionRouter = this.router;\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n if (navModelTitle) {\n title = instructionRouter.transformTitle(navModelTitle);\n }\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n\n if (child_nav_instruction) {\n let childTitle = child_nav_instruction._buildTitle(separator);\n if (childTitle) {\n childTitles.push(childTitle);\n }\n }\n }\n\n if (childTitles.length) {\n title = childTitles.join(separator) + (title ? separator : '') + title;\n }\n\n if (instructionRouter.title) {\n title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title);\n }\n\n return title;\n }\n}\n\nconst prune = (instruction: NavigationInstruction): void => {\n instruction.previousInstruction = null;\n instruction.plan = null;\n};\n\ninterface ISwapPlan {\n viewPort: ViewPort;\n viewPortInstruction: ViewPortInstruction;\n}\n","import { Router } from './router';\nimport { RouteConfig } from './interfaces';\n\n/**\n* Class for storing and interacting with a route's navigation settings.\n*/\nexport class NavModel {\n\n /**\n * True if this nav item is currently active.\n */\n isActive: boolean = false;\n\n /**\n * The title.\n */\n title: string = null;\n\n /**\n * This nav item's absolute href.\n */\n href: string = null;\n\n /**\n * This nav item's relative href.\n */\n relativeHref: string = null;\n\n /**\n * Data attached to the route at configuration time.\n */\n settings: any = {};\n\n /**\n * The route config.\n */\n config: RouteConfig = null;\n\n /**\n * The router associated with this navigation model.\n */\n router: Router;\n\n order: number | boolean;\n\n constructor(router: Router, relativeHref: string) {\n this.router = router;\n this.relativeHref = relativeHref;\n }\n\n /**\n * Sets the route's title and updates document.title.\n * If the a navigation is in progress, the change will be applied\n * to document.title when the navigation completes.\n *\n * @param title The new title.\n */\n setTitle(title: string): void {\n this.title = title;\n\n if (this.isActive) {\n this.router.updateTitle();\n }\n }\n}\n","import { RouteConfig } from './interfaces';\n\nexport function _normalizeAbsolutePath(path: string, hasPushState: boolean, absolute: boolean = false) {\n if (!hasPushState && path[0] !== '#') {\n path = '#' + path;\n }\n\n if (hasPushState && absolute) {\n path = path.substring(1, path.length);\n }\n\n return path;\n}\n\nexport function _createRootedPath(fragment: string, baseUrl: string, hasPushState: boolean, absolute?: boolean) {\n if (isAbsoluteUrl.test(fragment)) {\n return fragment;\n }\n\n let path = '';\n\n if (baseUrl.length && baseUrl[0] !== '/') {\n path += '/';\n }\n\n path += baseUrl;\n\n if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') {\n path += '/';\n }\n\n if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') {\n path = path.substring(0, path.length - 1);\n }\n\n return _normalizeAbsolutePath(path + fragment, hasPushState, absolute);\n}\n\nexport function _resolveUrl(fragment: string, baseUrl: string, hasPushState?: boolean) {\n if (isRootedPath.test(fragment)) {\n return _normalizeAbsolutePath(fragment, hasPushState);\n }\n\n return _createRootedPath(fragment, baseUrl, hasPushState);\n}\n\nexport function _ensureArrayWithSingleRoutePerConfig(config: RouteConfig) {\n let routeConfigs = [];\n\n if (Array.isArray(config.route)) {\n for (let i = 0, ii = config.route.length; i < ii; ++i) {\n let current = Object.assign({}, config);\n current.route = config.route[i];\n routeConfigs.push(current);\n }\n } else {\n routeConfigs.push(Object.assign({}, config));\n }\n\n return routeConfigs;\n}\n\nconst isRootedPath = /^#?\\//;\nconst isAbsoluteUrl = /^([a-z][a-z0-9+\\-.]*:)?\\/\\//i;\n","import { RouteConfig, PipelineStep, RouteConfigSpecifier } from './interfaces';\nimport { _ensureArrayWithSingleRoutePerConfig } from './util';\nimport { Router } from './router';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * Class used to configure a [[Router]] instance.\n *\n * @constructor\n */\nexport class RouterConfiguration {\n instructions: Array<(router: Router) => void> = [];\n options: {\n [key: string]: any;\n compareQueryParams?: boolean;\n root?: string;\n pushState?: boolean;\n hashChange?: boolean;\n silent?: boolean;\n } = {};\n pipelineSteps: Array<{ name: string, step: Function | PipelineStep }> = [];\n title: string;\n titleSeparator: string;\n unknownRouteConfig: RouteConfigSpecifier;\n viewPortDefaults: Record;\n\n /**@internal */\n _fallbackRoute: string;\n\n /**\n * Adds a step to be run during the [[Router]]'s navigation pipeline.\n *\n * @param name The name of the pipeline slot to insert the step into.\n * @param step The pipeline step.\n * @chainable\n */\n addPipelineStep(name: string, step: Function | PipelineStep): RouterConfiguration {\n if (step === null || step === undefined) {\n throw new Error('Pipeline step cannot be null or undefined.');\n }\n this.pipelineSteps.push({ name, step });\n return this;\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s authorize pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addAuthorizeStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.Authorize, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preActivate pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreActivateStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreActivate, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreRender, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s postRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPostRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PostRender, step);\n }\n\n /**\n * Configures a route that will be used if there is no previous location available on navigation cancellation.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @chainable\n */\n fallbackRoute(fragment: string): RouterConfiguration {\n this._fallbackRoute = fragment;\n return this;\n }\n\n /**\n * Maps one or more routes to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map.\n * @chainable\n */\n map(route: RouteConfig | RouteConfig[]): RouterConfiguration {\n if (Array.isArray(route)) {\n route.forEach(r => this.map(r));\n return this;\n }\n\n return this.mapRoute(route);\n }\n\n /**\n * Configures defaults to use for any view ports.\n *\n * @param viewPortConfig a view port configuration object to use as a\n * default, of the form { viewPortName: { moduleId } }.\n * @chainable\n */\n useViewPortDefaults(viewPortConfig: Record): RouterConfiguration {\n this.viewPortDefaults = viewPortConfig;\n return this;\n }\n\n /**\n * Maps a single route to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map.\n * @chainable\n */\n mapRoute(config: RouteConfig): RouterConfiguration {\n this.instructions.push(router => {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n\n let navModel;\n for (let i = 0, ii = routeConfigs.length; i < ii; ++i) {\n let routeConfig = routeConfigs[i];\n routeConfig.settings = routeConfig.settings || {};\n if (!navModel) {\n navModel = router.createNavModel(routeConfig);\n }\n\n router.addRoute(routeConfig, navModel);\n }\n });\n\n return this;\n }\n\n /**\n * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes.\n *\n * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the\n * [[NavigationInstruction]] and selects a moduleId to load.\n * @chainable\n */\n mapUnknownRoutes(config: RouteConfigSpecifier): RouterConfiguration {\n this.unknownRouteConfig = config;\n return this;\n }\n\n /**\n * Applies the current configuration to the specified [[Router]].\n *\n * @param router The [[Router]] to apply the configuration to.\n */\n exportToRouter(router: Router): void {\n let instructions = this.instructions;\n for (let i = 0, ii = instructions.length; i < ii; ++i) {\n instructions[i](router);\n }\n\n let { title, titleSeparator, unknownRouteConfig, _fallbackRoute, viewPortDefaults } = this;\n\n if (title) {\n router.title = title;\n }\n\n if (titleSeparator) {\n router.titleSeparator = titleSeparator;\n }\n\n if (unknownRouteConfig) {\n router.handleUnknownRoutes(unknownRouteConfig);\n }\n\n if (_fallbackRoute) {\n router.fallbackRoute = _fallbackRoute;\n }\n\n if (viewPortDefaults) {\n router.useViewPortDefaults(viewPortDefaults);\n }\n\n Object.assign(router.options, this.options);\n\n let pipelineSteps = this.pipelineSteps;\n let pipelineStepCount = pipelineSteps.length;\n if (pipelineStepCount) {\n if (!router.isRoot) {\n throw new Error('Pipeline steps can only be added to the root router');\n }\n\n let pipelineProvider = router.pipelineProvider;\n for (let i = 0, ii = pipelineStepCount; i < ii; ++i) {\n let { name, step } = pipelineSteps[i];\n pipelineProvider.addStep(name, step);\n }\n }\n }\n}\n","import { RouteRecognizer, RouteHandler, ConfigurableRoute, State, RecognizedRoute } from 'aurelia-route-recognizer';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { NavigationInstruction, NavigationInstructionInit } from './navigation-instruction';\nimport { NavModel } from './nav-model';\nimport { RouterConfiguration } from './router-configuration';\nimport {\n _ensureArrayWithSingleRoutePerConfig,\n _normalizeAbsolutePath,\n _createRootedPath,\n _resolveUrl\n} from './util';\nimport { RouteConfig, RouteConfigSpecifier, ViewPortInstruction } from './interfaces';\nimport { PipelineProvider } from './pipeline-provider';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface History {\n // This is wrong, as it's an implementation detail from aurelia-history-browser\n // but we are poking it in here so probably will need to make it official in `aurelia-history`\n /**\n * A private flag of Aurelia History implementation to indicate if push state should be used\n */\n _hasPushState: boolean;\n\n previousLocation: string;\n }\n}\n\n/**@internal */\ndeclare module 'aurelia-route-recognizer' {\n interface State {\n types: {\n dynamics: DynamicSegment;\n stars: StarSegment;\n };\n }\n\n interface RouteHandler {\n navigationStrategy?: (instruction: NavigationInstruction) => any;\n }\n\n interface RecognizedRoute {\n config?: RouteConfig;\n queryParams?: Record;\n }\n}\n\ntype RouterConfigurationResolution = RouterConfiguration | ((cfg: RouterConfiguration) => void | RouterConfiguration | Promise);\n\n/**\n * The primary class responsible for handling routing and navigation.\n */\nexport class Router {\n\n /**\n * Container associated with this router. Also used to create child container for creating child router.\n */\n container: Container;\n\n /**\n * History instance of Aurelia abstract class for wrapping platform history global object\n */\n history: History;\n\n /**\n * A registry of registered viewport. Will be used to handle process navigation instruction route loading\n * and dom swapping\n */\n viewPorts: Record;\n\n /**\n * List of route configs registered with this router\n */\n routes: RouteConfig[];\n\n /**\n * The [[Router]]'s current base URL, typically based on the [[Router.currentInstruction]].\n */\n baseUrl: string;\n\n /**\n * If defined, used in generation of document title for [[Router]]'s routes.\n */\n title: string | undefined;\n\n /**\n * The separator used in the document title between [[Router]]'s routes.\n */\n titleSeparator: string | undefined;\n\n /**\n * True if the [[Router]] has been configured.\n */\n isConfigured: boolean;\n\n /**\n * True if the [[Router]] is currently processing a navigation.\n */\n isNavigating: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigate function(s).\n */\n isExplicitNavigation: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigateBack function.\n */\n isExplicitNavigationBack: boolean;\n\n /**\n * True if the [[Router]] is navigating into the app for the first time in the browser session.\n */\n isNavigatingFirst: boolean;\n\n /**\n * True if the [[Router]] is navigating to a page instance not in the browser session history.\n */\n isNavigatingNew: boolean;\n\n /**\n * True if the [[Router]] is navigating forward in the browser session history.\n */\n isNavigatingForward: boolean;\n\n /**\n * True if the [[Router]] is navigating back in the browser session history.\n */\n isNavigatingBack: boolean;\n\n /**\n * True if the [[Router]] is navigating due to a browser refresh.\n */\n isNavigatingRefresh: boolean;\n\n /**\n * True if the previous instruction successfully completed the CanDeactivatePreviousStep in the current navigation.\n */\n couldDeactivate: boolean;\n\n /**\n * The currently active navigation tracker.\n */\n currentNavigationTracker: number;\n\n /**\n * The navigation models for routes that specified [[RouteConfig.nav]].\n */\n navigation: NavModel[];\n\n /**\n * The currently active navigation instruction.\n */\n currentInstruction: NavigationInstruction;\n\n /**\n * The parent router, or null if this instance is not a child router.\n */\n parent: Router = null;\n\n options: any = {};\n\n /**\n * The defaults used when a viewport lacks specified content\n */\n viewPortDefaults: Record = {};\n\n /**@internal */\n catchAllHandler: (instruction: NavigationInstruction) => NavigationInstruction | Promise;\n /**@internal */\n fallbackRoute: string;\n /**@internal */\n pipelineProvider: PipelineProvider;\n /**@internal */\n _fallbackOrder: number;\n /**@internal */\n _recognizer: RouteRecognizer;\n /**@internal */\n _childRecognizer: RouteRecognizer;\n /**@internal */\n _configuredPromise: Promise;\n /**@internal */\n _resolveConfiguredPromise: (value?: any) => void;\n\n /**\n * Extension point to transform the document title before it is built and displayed.\n * By default, child routers delegate to the parent router, and the app router\n * returns the title unchanged.\n */\n transformTitle: (title: string) => string = (title: string) => {\n if (this.parent) {\n return this.parent.transformTitle(title);\n }\n return title;\n }\n\n /**\n * @param container The [[Container]] to use when child routers.\n * @param history The [[History]] implementation to delegate navigation requests to.\n */\n constructor(container: Container, history: History) {\n this.container = container;\n this.history = history;\n this.reset();\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset() {\n this.viewPorts = {};\n this.routes = [];\n this.baseUrl = '';\n this.isConfigured = false;\n this.isNavigating = false;\n this.isExplicitNavigation = false;\n this.isExplicitNavigationBack = false;\n this.isNavigatingFirst = false;\n this.isNavigatingNew = false;\n this.isNavigatingRefresh = false;\n this.isNavigatingForward = false;\n this.isNavigatingBack = false;\n this.couldDeactivate = false;\n this.navigation = [];\n this.currentInstruction = null;\n this.viewPortDefaults = {};\n this._fallbackOrder = 100;\n this._recognizer = new RouteRecognizer();\n this._childRecognizer = new RouteRecognizer();\n this._configuredPromise = new Promise(resolve => {\n this._resolveConfiguredPromise = resolve;\n });\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent.\n */\n get isRoot(): boolean {\n return !this.parent;\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort.\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/any, name?: string): void {\n name = name || 'default';\n this.viewPorts[name] = viewPort;\n }\n\n /**\n * Returns a Promise that resolves when the router is configured.\n */\n ensureConfigured(): Promise {\n return this._configuredPromise;\n }\n\n /**\n * Configures the router.\n *\n * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]].\n */\n configure(callbackOrConfig: RouterConfiguration | ((config: RouterConfiguration) => RouterConfiguration)): Promise {\n this.isConfigured = true;\n\n let result: RouterConfigurationResolution = callbackOrConfig as RouterConfiguration;\n let config: RouterConfiguration;\n if (typeof callbackOrConfig === 'function') {\n config = new RouterConfiguration();\n result = callbackOrConfig(config);\n }\n\n return Promise\n .resolve(result)\n .then((c) => {\n if (c && (c as RouterConfiguration).exportToRouter) {\n config = c;\n }\n\n config.exportToRouter(this);\n this.isConfigured = true;\n this._resolveConfiguredPromise();\n });\n }\n\n /**\n * Navigates to a new location.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n navigate(fragment: string, options?: NavigationOptions): boolean {\n if (!this.isConfigured && this.parent) {\n return this.parent.navigate(fragment, options);\n }\n\n this.isExplicitNavigation = true;\n return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options);\n }\n\n /**\n * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed\n * by [[Router.navigate]].\n *\n * @param route The name of the route to use when generating the navigation location.\n * @param params The route parameters to be used when populating the route pattern.\n * @param options The navigation options.\n */\n navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean {\n let path = this.generate(route, params);\n return this.navigate(path, options);\n }\n\n /**\n * Navigates back to the most recent location in history.\n */\n navigateBack(): void {\n this.isExplicitNavigationBack = true;\n this.history.navigateBack();\n }\n\n /**\n * Creates a child router of the current router.\n *\n * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified.\n * @returns {Router} The new child Router.\n */\n createChild(container?: Container): Router {\n let childRouter = new Router(container || this.container.createChild(), this.history);\n childRouter.parent = this;\n return childRouter;\n }\n\n /**\n * Generates a URL fragment matching the specified route pattern.\n *\n * @param name The name of the route whose pattern should be used to generate the fragment.\n * @param params The route params to be used to populate the route pattern.\n * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url.\n * @returns {string} A string containing the generated URL fragment.\n */\n generate(nameOrRoute: string | RouteConfig, params: any = {}, options: any = {}): string {\n // A child recognizer generates routes for potential child routes. Any potential child route is added\n // to the childRoute property of params for the childRouter to recognize. When generating routes, we\n // use the childRecognizer when childRoute params are available to generate a child router enabled route.\n let recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer;\n let hasRoute = recognizer.hasRoute(nameOrRoute as string | RouteHandler);\n if (!hasRoute) {\n if (this.parent) {\n return this.parent.generate(nameOrRoute, params, options);\n }\n throw new Error(`A route with name '${nameOrRoute}' could not be found. Check that \\`name: '${nameOrRoute}'\\` was specified in the route's config.`);\n }\n let path = recognizer.generate(nameOrRoute as string | RouteHandler, params);\n let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute);\n return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath;\n }\n\n /**\n * Creates a [[NavModel]] for the specified route config.\n *\n * @param config The route config.\n */\n createNavModel(config: RouteConfig): NavModel {\n let navModel = new NavModel(\n this,\n 'href' in config\n ? config.href\n // potential error when config.route is a string[] ?\n : config.route as string);\n navModel.title = config.title;\n navModel.order = config.nav;\n navModel.href = config.href;\n navModel.settings = config.settings;\n navModel.config = config;\n\n return navModel;\n }\n\n /**\n * Registers a new route with the router.\n *\n * @param config The [[RouteConfig]].\n * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes.\n */\n addRoute(config: RouteConfig, navModel?: NavModel): void {\n if (Array.isArray(config.route)) {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n // the following is wrong. todo: fix this after TS refactoring release\n routeConfigs.forEach(this.addRoute.bind(this));\n return;\n }\n\n validateRouteConfig(config);\n\n if (!('viewPorts' in config) && !config.navigationStrategy) {\n config.viewPorts = {\n 'default': {\n moduleId: config.moduleId,\n view: config.view\n }\n };\n }\n\n if (!navModel) {\n navModel = this.createNavModel(config);\n }\n\n this.routes.push(config);\n\n let path = config.route;\n if (path.charAt(0) === '/') {\n path = path.substr(1);\n }\n let caseSensitive = config.caseSensitive === true;\n let state: State = this._recognizer.add({\n path: path,\n handler: config as RouteHandler,\n caseSensitive: caseSensitive\n } as ConfigurableRoute);\n\n if (path) {\n let settings = config.settings;\n delete config.settings;\n let withChild = JSON.parse(JSON.stringify(config));\n config.settings = settings;\n withChild.route = `${path}/*childRoute`;\n withChild.hasChildRouter = true;\n this._childRecognizer.add({\n path: withChild.route,\n handler: withChild,\n caseSensitive: caseSensitive\n });\n\n withChild.navModel = navModel;\n withChild.settings = config.settings;\n withChild.navigationStrategy = config.navigationStrategy;\n }\n\n config.navModel = navModel;\n\n let navigation = this.navigation;\n\n if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) {\n if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) {\n throw new Error('Invalid route config for \"' + config.route + '\" : dynamic routes must specify an \"href:\" to be included in the navigation model.');\n }\n\n if (typeof navModel.order !== 'number') {\n navModel.order = ++this._fallbackOrder;\n }\n\n navigation.push(navModel);\n // this is a potential error / inconsistency between browsers\n //\n // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\n // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other,\n // but sorted with respect to all different elements.\n // Note: the ECMAscript standard does not guarantee this behaviour,\n // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.\n navigation.sort((a, b) => a.order - b.order);\n }\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasRoute(name: string): boolean {\n return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name));\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasOwnRoute(name: string): boolean {\n return this._recognizer.hasRoute(name);\n }\n\n /**\n * Register a handler to use when the incoming URL fragment doesn't match any registered routes.\n *\n * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]].\n */\n handleUnknownRoutes(config?: RouteConfigSpecifier): void {\n if (!config) {\n throw new Error('Invalid unknown route handler');\n }\n\n this.catchAllHandler = instruction => {\n return this\n ._createRouteConfig(config, instruction)\n .then(c => {\n instruction.config = c;\n return instruction;\n });\n };\n }\n\n /**\n * Updates the document title using the current navigation instruction.\n */\n updateTitle(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n return parentRouter.updateTitle();\n }\n\n let currentInstruction = this.currentInstruction;\n if (currentInstruction) {\n currentInstruction._updateTitle();\n }\n return undefined;\n }\n\n /**\n * Updates the navigation routes with hrefs relative to the current location.\n * Note: This method will likely move to a plugin in a future release.\n */\n refreshNavigation(): void {\n let nav = this.navigation;\n\n for (let i = 0, length = nav.length; i < length; i++) {\n let current = nav[i];\n if (!current.config.href) {\n current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState);\n } else {\n current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState);\n }\n }\n }\n\n /**\n * Sets the default configuration for the view ports. This specifies how to\n * populate a view port for which no module is specified. The default is\n * an empty view/view-model pair.\n */\n useViewPortDefaults($viewPortDefaults: Record): void {\n // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction\n let viewPortDefaults: Record = $viewPortDefaults;\n for (let viewPortName in viewPortDefaults) {\n let viewPortConfig = viewPortDefaults[viewPortName];\n this.viewPortDefaults[viewPortName] = {\n moduleId: viewPortConfig.moduleId\n };\n }\n }\n\n /**@internal */\n _refreshBaseUrl(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction);\n }\n }\n\n /**@internal */\n _createNavigationInstruction(url: string = '', parentInstruction: NavigationInstruction = null): Promise {\n let fragment = url;\n let queryString = '';\n\n let queryIndex = url.indexOf('?');\n if (queryIndex !== -1) {\n fragment = url.substr(0, queryIndex);\n queryString = url.substr(queryIndex + 1);\n }\n\n let urlRecognizationResults = this._recognizer.recognize(url) as IRouteRecognizationResults;\n if (!urlRecognizationResults || !urlRecognizationResults.length) {\n urlRecognizationResults = this._childRecognizer.recognize(url) as IRouteRecognizationResults;\n }\n\n let instructionInit: NavigationInstructionInit = {\n fragment,\n queryString,\n config: null,\n parentInstruction,\n previousInstruction: this.currentInstruction,\n router: this,\n options: {\n compareQueryParams: this.options.compareQueryParams\n }\n };\n\n let result: Promise;\n\n if (urlRecognizationResults && urlRecognizationResults.length) {\n let first = urlRecognizationResults[0];\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: first.params,\n queryParams: first.queryParams || urlRecognizationResults.queryParams,\n config: first.config || first.handler\n }));\n\n if (typeof first.handler === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler, first);\n } else if (first.handler && typeof first.handler.navigationStrategy === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler);\n } else {\n result = Promise.resolve(instruction);\n }\n } else if (this.catchAllHandler) {\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n config: null // config will be created by the catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, this.catchAllHandler);\n } else if (this.parent) {\n let router = this._parentCatchAllHandler(this.parent);\n\n if (router) {\n let newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction);\n\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n router: router,\n parentInstruction: newParentInstruction,\n parentCatchHandler: true,\n config: null // config will be created by the chained parent catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, router.catchAllHandler);\n }\n }\n\n if (result && parentInstruction) {\n this.baseUrl = generateBaseUrl(this.parent, parentInstruction);\n }\n\n return result || Promise.reject(new Error(`Route not found: ${url}`));\n }\n\n /**@internal */\n _findParentInstructionFromRouter(router: Router, instruction: NavigationInstruction): NavigationInstruction {\n if (instruction.router === router) {\n instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId\n return instruction;\n } else if (instruction.parentInstruction) {\n return this._findParentInstructionFromRouter(router, instruction.parentInstruction);\n }\n return undefined;\n }\n\n /**@internal */\n _parentCatchAllHandler(router: Router): Router | false {\n if (router.catchAllHandler) {\n return router;\n } else if (router.parent) {\n return this._parentCatchAllHandler(router.parent);\n }\n return false;\n }\n\n /**\n * @internal\n */\n _createRouteConfig(config: RouteConfigSpecifier, instruction: NavigationInstruction): Promise {\n return Promise\n .resolve(config)\n .then((c: any) => {\n if (typeof c === 'string') {\n return { moduleId: c } as RouteConfig;\n } else if (typeof c === 'function') {\n return c(instruction);\n }\n\n return c;\n })\n // typing here could be either RouteConfig or RedirectConfig\n // but temporarily treat both as RouteConfig\n // todo: improve typings precision\n .then((c: string | RouteConfig) => typeof c === 'string' ? { moduleId: c } as RouteConfig : c)\n .then((c: RouteConfig) => {\n c.route = instruction.params.path;\n validateRouteConfig(c);\n\n if (!c.navModel) {\n c.navModel = this.createNavModel(c);\n }\n\n return c;\n });\n }\n}\n\n/* @internal exported for unit testing */\nexport const generateBaseUrl = (router: Router, instruction: NavigationInstruction): string => {\n return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`;\n};\n\n/* @internal exported for unit testing */\nexport const validateRouteConfig = (config: RouteConfig): void => {\n if (typeof config !== 'object') {\n throw new Error('Invalid Route Config');\n }\n\n if (typeof config.route !== 'string') {\n let name = config.name || '(no name)';\n throw new Error('Invalid Route Config for \"' + name + '\": You must specify a \"route:\" pattern.');\n }\n\n if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) {\n throw new Error('Invalid Route Config for \"' + config.route + '\": You must specify a \"moduleId:\", \"redirect:\", \"navigationStrategy:\", or \"viewPorts:\".');\n }\n};\n\n/* @internal exported for unit testing */\nexport const evaluateNavigationStrategy = (\n instruction: NavigationInstruction,\n evaluator: Function,\n context?: any\n): Promise => {\n return Promise\n .resolve(evaluator.call(context, instruction))\n .then(() => {\n if (!('viewPorts' in instruction.config)) {\n instruction.config.viewPorts = {\n 'default': {\n moduleId: instruction.config.moduleId\n }\n };\n }\n\n return instruction;\n });\n};\n\ninterface IRouteRecognizationResults extends Array {\n queryParams: Record;\n}\n","import { PipelineStatus } from './pipeline-status';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Next, StepRunnerFunction, NextCompletionHandler } from './interfaces';\n\n/**@internal exported for unit testing */\nexport const createNextFn = (instruction: NavigationInstruction, steps: StepRunnerFunction[]): Next => {\n let index = -1;\n const next: Next = function() {\n index++;\n\n if (index < steps.length) {\n let currentStep = steps[index];\n\n try {\n return currentStep(instruction, next);\n } catch (e) {\n return next.reject(e);\n }\n } else {\n return next.complete();\n }\n } as Next;\n\n next.complete = createCompletionHandler(next, PipelineStatus.Completed);\n next.cancel = createCompletionHandler(next, PipelineStatus.Canceled);\n next.reject = createCompletionHandler(next, PipelineStatus.Rejected);\n\n return next;\n};\n\n/**@internal exported for unit testing */\nexport const createCompletionHandler = (next: Next, status: PipelineStatus): NextCompletionHandler => {\n return (output: any) => Promise\n .resolve({\n status,\n output,\n completed: status === PipelineStatus.Completed\n });\n};\n","import { PipelineStep, PipelineResult, Next, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { createNextFn } from './next';\n\n/**\n * The class responsible for managing and processing the navigation pipeline.\n */\nexport class Pipeline {\n /**\n * The pipeline steps. And steps added via addStep will be converted to a function\n * The actualy running functions with correct step contexts of this pipeline\n */\n steps: StepRunnerFunction[] = [];\n\n /**\n * Adds a step to the pipeline.\n *\n * @param step The pipeline step.\n */\n addStep(step: StepRunnerFunction | PipelineStep | IPipelineSlot): Pipeline {\n let run;\n\n if (typeof step === 'function') {\n run = step;\n } else if (typeof step.getSteps === 'function') {\n // getSteps is to enable support open slots\n // where devs can add multiple steps into the same slot name\n let steps = step.getSteps();\n for (let i = 0, l = steps.length; i < l; i++) {\n this.addStep(steps[i]);\n }\n\n return this;\n } else {\n run = (step as PipelineStep).run.bind(step);\n }\n\n this.steps.push(run);\n\n return this;\n }\n\n /**\n * Runs the pipeline.\n *\n * @param instruction The navigation instruction to process.\n */\n run(instruction: NavigationInstruction): Promise {\n const nextFn = createNextFn(instruction, this.steps);\n return nextFn();\n }\n}\n","import { NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface NavigationOptions {\n useAppRouter?: boolean;\n }\n}\n\n/**\n* When a navigation command is encountered, the current navigation\n* will be cancelled and control will be passed to the navigation\n* command so it can determine the correct action.\n*/\nexport interface NavigationCommand {\n navigate: (router: Router) => void;\n /**@internal */\n shouldContinueProcessing?: boolean;\n /**@internal */\n setRouter?: (router: Router) => void;\n}\n\n/**\n* Determines if the provided object is a navigation command.\n* A navigation command is anything with a navigate method.\n*\n* @param obj The object to check.\n*/\nexport function isNavigationCommand(obj: any): obj is NavigationCommand {\n return obj && typeof obj.navigate === 'function';\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect.\n*/\nexport class Redirect implements NavigationCommand {\n\n url: string;\n /**@internal */\n options: NavigationOptions;\n /**@internal */\n shouldContinueProcessing: boolean;\n\n private router: Router;\n\n /**\n * @param url The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n constructor(url: string, options: NavigationOptions = {}) {\n this.url = url;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigate(this.url, this.options);\n }\n}\n\n/**\n * Used during the activation lifecycle to cause a redirect to a named route.\n */\nexport class RedirectToRoute implements NavigationCommand {\n\n route: string;\n params: any;\n /**@internal */\n options: NavigationOptions;\n\n /**@internal */\n shouldContinueProcessing: boolean;\n\n /**@internal */\n router: Router;\n\n /**\n * @param route The name of the route.\n * @param params The parameters to be sent to the activation method.\n * @param options The options to use for navigation.\n */\n constructor(route: string, params: any = {}, options: NavigationOptions = {}) {\n this.route = route;\n this.params = params;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigateToRoute(this.route, this.params, this.options);\n }\n}\n","import { ViewPortPlan, ViewPortInstruction, RouteConfig, ViewPort } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { InternalActivationStrategy, ActivationStrategyType } from './activation-strategy';\n\ntype ViewPortPlansRecord = Record;\n\n/**\n * @internal exported for unit testing\n */\nexport function _buildNavigationPlan(\n instruction: NavigationInstruction,\n forceLifecycleMinimum?: boolean\n): Promise {\n let config = instruction.config;\n\n if ('redirect' in config) {\n return buildRedirectPlan(instruction);\n }\n\n const prevInstruction = instruction.previousInstruction;\n const defaultViewPortConfigs = instruction.router.viewPortDefaults;\n\n if (prevInstruction) {\n return buildTransitionPlans(instruction, prevInstruction, defaultViewPortConfigs, forceLifecycleMinimum);\n }\n\n // first navigation, only need to prepare a few information for each viewport plan\n const viewPortPlans: ViewPortPlansRecord = {};\n let viewPortConfigs = config.viewPorts;\n for (let viewPortName in viewPortConfigs) {\n let viewPortConfig = viewPortConfigs[viewPortName];\n if (viewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) {\n viewPortConfig = defaultViewPortConfigs[viewPortName];\n }\n viewPortPlans[viewPortName] = {\n name: viewPortName,\n strategy: InternalActivationStrategy.Replace,\n config: viewPortConfig\n };\n }\n\n return Promise.resolve(viewPortPlans);\n}\n\n/**\n * Build redirect plan based on config of a navigation instruction\n * @internal exported for unit testing\n */\nexport const buildRedirectPlan = (instruction: NavigationInstruction) => {\n const config = instruction.config;\n const router = instruction.router;\n return router\n ._createNavigationInstruction(config.redirect)\n .then(redirectInstruction => {\n\n const params: Record = {};\n const originalInstructionParams = instruction.params;\n const redirectInstructionParams = redirectInstruction.params;\n\n for (let key in redirectInstructionParams) {\n // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this }\n let val = redirectInstructionParams[key];\n if (typeof val === 'string' && val[0] === ':') {\n val = val.slice(1);\n // And if that param is found on the original instruction then use it\n if (val in originalInstructionParams) {\n params[key] = originalInstructionParams[val];\n }\n } else {\n params[key] = redirectInstructionParams[key];\n }\n }\n let redirectLocation = router.generate(redirectInstruction.config, params, instruction.options);\n\n // Special handling for child routes\n for (let key in originalInstructionParams) {\n redirectLocation = redirectLocation.replace(`:${key}`, originalInstructionParams[key]);\n }\n\n let queryString = instruction.queryString;\n if (queryString) {\n redirectLocation += '?' + queryString;\n }\n\n return Promise.resolve(new Redirect(redirectLocation));\n });\n};\n\n/**\n * @param viewPortPlans the Plan record that holds information about built plans\n * @internal exported for unit testing\n */\nexport const buildTransitionPlans = (\n currentInstruction: NavigationInstruction,\n previousInstruction: NavigationInstruction,\n defaultViewPortConfigs: Record,\n forceLifecycleMinimum?: boolean\n): Promise => {\n\n let viewPortPlans: ViewPortPlansRecord = {};\n let newInstructionConfig = currentInstruction.config;\n let hasNewParams = hasDifferentParameterValues(previousInstruction, currentInstruction);\n let pending: Promise[] = [];\n let previousViewPortInstructions = previousInstruction.viewPortInstructions as Record;\n\n for (let viewPortName in previousViewPortInstructions) {\n\n const prevViewPortInstruction = previousViewPortInstructions[viewPortName];\n const prevViewPortComponent = prevViewPortInstruction.component;\n const newInstructionViewPortConfigs = newInstructionConfig.viewPorts as Record;\n\n // if this is invoked on a viewport without any changes, based on new url,\n // newViewPortConfig will be the existing viewport instruction\n let nextViewPortConfig = viewPortName in newInstructionViewPortConfigs\n ? newInstructionViewPortConfigs[viewPortName]\n : prevViewPortInstruction;\n\n if (nextViewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) {\n nextViewPortConfig = defaultViewPortConfigs[viewPortName];\n }\n\n const viewPortActivationStrategy = determineActivationStrategy(\n currentInstruction,\n prevViewPortInstruction,\n nextViewPortConfig,\n hasNewParams,\n forceLifecycleMinimum\n );\n const viewPortPlan = viewPortPlans[viewPortName] = {\n name: viewPortName,\n // ViewPortInstruction can quack like a RouteConfig\n config: nextViewPortConfig as RouteConfig,\n prevComponent: prevViewPortComponent,\n prevModuleId: prevViewPortInstruction.moduleId,\n strategy: viewPortActivationStrategy\n } as ViewPortPlan;\n\n // recursively build nav plans for all existing child routers/viewports of this viewport\n // this is possible because existing child viewports and routers already have necessary information\n // to process the wildcard path from parent instruction\n if (viewPortActivationStrategy !== InternalActivationStrategy.Replace && prevViewPortInstruction.childRouter) {\n const path = currentInstruction.getWildcardPath();\n const task: Promise = prevViewPortInstruction\n .childRouter\n ._createNavigationInstruction(path, currentInstruction)\n .then((childInstruction: NavigationInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(\n childInstruction,\n // is it safe to assume viewPortPlan has not been changed from previous assignment?\n // if so, can just use local variable viewPortPlanStrategy\n // there could be user code modifying viewport plan during _createNavigationInstruction?\n viewPortPlan.strategy === InternalActivationStrategy.InvokeLifecycle\n )\n .then(childPlan => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n // for bluebird ?\n return null;\n });\n });\n\n pending.push(task);\n }\n }\n\n return Promise.all(pending).then(() => viewPortPlans);\n};\n\n/**\n * @param newViewPortConfig if this is invoked on a viewport without any changes, based on new url, newViewPortConfig will be the existing viewport instruction\n * @internal exported for unit testing\n */\nexport const determineActivationStrategy = (\n currentNavInstruction: NavigationInstruction,\n prevViewPortInstruction: ViewPortInstruction,\n newViewPortConfig: RouteConfig | ViewPortInstruction,\n // indicates whether there is difference between old and new url params\n hasNewParams: boolean,\n forceLifecycleMinimum?: boolean\n): ActivationStrategyType => {\n\n let newInstructionConfig = currentNavInstruction.config;\n let prevViewPortViewModel = prevViewPortInstruction.component.viewModel;\n let viewPortPlanStrategy: ActivationStrategyType;\n\n if (prevViewPortInstruction.moduleId !== newViewPortConfig.moduleId) {\n viewPortPlanStrategy = InternalActivationStrategy.Replace;\n } else if ('determineActivationStrategy' in prevViewPortViewModel) {\n viewPortPlanStrategy = prevViewPortViewModel.determineActivationStrategy(...currentNavInstruction.lifecycleArgs);\n } else if (newInstructionConfig.activationStrategy) {\n viewPortPlanStrategy = newInstructionConfig.activationStrategy;\n } else if (hasNewParams || forceLifecycleMinimum) {\n viewPortPlanStrategy = InternalActivationStrategy.InvokeLifecycle;\n } else {\n viewPortPlanStrategy = InternalActivationStrategy.NoChange;\n }\n return viewPortPlanStrategy;\n};\n\n/**@internal exported for unit testing */\nexport const hasDifferentParameterValues = (prev: NavigationInstruction, next: NavigationInstruction): boolean => {\n let prevParams = prev.params;\n let nextParams = next.params;\n let nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null;\n\n for (let key in nextParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n for (let key in prevParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n if (!next.options.compareQueryParams) {\n return false;\n }\n\n let prevQueryParams = prev.queryParams;\n let nextQueryParams = next.queryParams;\n for (let key in nextQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n for (let key in prevQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n return false;\n};\n","import { Next } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { _buildNavigationPlan } from './navigation-plan';\n\n/**\n * Transform a navigation instruction into viewport plan record object,\n * or a redirect request if user viewmodel demands\n */\nexport class BuildNavigationPlanStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return _buildNavigationPlan(navigationInstruction)\n .then(plan => {\n if (plan instanceof Redirect) {\n return next.cancel(plan);\n }\n navigationInstruction.plan = plan;\n return next();\n })\n .catch(next.cancel);\n }\n}\n","import { RouteConfig, ViewPortComponent, ViewPortPlan, ViewPortInstruction } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { _buildNavigationPlan } from './navigation-plan';\nimport { InternalActivationStrategy } from './activation-strategy';\nimport { RouteLoader } from './route-loader';\n\n/**\n * Loading plan calculated based on a navigration-instruction and a viewport plan\n */\ninterface ILoadingPlan {\n viewPortPlan: ViewPortPlan;\n navigationInstruction: NavigationInstruction;\n}\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadNewRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction\n): Promise => {\n let loadingPlans = determineLoadingPlans(navigationInstruction);\n let loadPromises = loadingPlans.map((loadingPlan: ILoadingPlan) => loadRoute(\n routeLoader,\n loadingPlan.navigationInstruction,\n loadingPlan.viewPortPlan\n ));\n\n return Promise.all(loadPromises);\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const determineLoadingPlans = (\n navigationInstruction: NavigationInstruction,\n loadingPlans: ILoadingPlan[] = []\n): ILoadingPlan[] => {\n let viewPortPlans: Record = navigationInstruction.plan;\n\n for (let viewPortName in viewPortPlans) {\n let viewPortPlan = viewPortPlans[viewPortName];\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (viewPortPlan.strategy === InternalActivationStrategy.Replace) {\n loadingPlans.push({ viewPortPlan, navigationInstruction } as ILoadingPlan);\n\n if (childNavInstruction) {\n determineLoadingPlans(childNavInstruction, loadingPlans);\n }\n } else {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction({\n name: viewPortName,\n strategy: viewPortPlan.strategy,\n moduleId: viewPortPlan.prevModuleId,\n component: viewPortPlan.prevComponent\n }) as ViewPortInstruction;\n\n if (childNavInstruction) {\n viewPortInstruction.childNavigationInstruction = childNavInstruction;\n determineLoadingPlans(childNavInstruction, loadingPlans);\n }\n }\n }\n\n return loadingPlans;\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n viewPortPlan: ViewPortPlan\n): Promise => {\n let planConfig = viewPortPlan.config;\n let moduleId = planConfig ? planConfig.moduleId : null;\n\n return loadComponent(routeLoader, navigationInstruction, planConfig)\n .then((component) => {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction({\n name: viewPortPlan.name,\n strategy: viewPortPlan.strategy,\n moduleId: moduleId,\n component: component\n }) as ViewPortInstruction;\n\n let childRouter = component.childRouter;\n if (childRouter) {\n let path = navigationInstruction.getWildcardPath();\n\n return childRouter\n ._createNavigationInstruction(path, navigationInstruction)\n .then((childInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(childInstruction)\n .then((childPlan) => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n viewPortInstruction.childNavigationInstruction = childInstruction;\n\n return loadNewRoute(routeLoader, childInstruction);\n });\n });\n }\n // ts complains without this, though they are same\n return void 0;\n });\n};\n\n/**\n * Load a routed-component based on navigation instruction and route config\n * @internal exported for unit testing only\n */\nexport const loadComponent = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n config: RouteConfig\n): Promise => {\n let router = navigationInstruction.router;\n let lifecycleArgs = navigationInstruction.lifecycleArgs;\n\n return Promise.resolve()\n .then(() => routeLoader.loadRoute(router, config, navigationInstruction))\n .then(\n /**\n * @param component an object carrying information about loaded route\n * typically contains information about view model, childContainer, view and router\n */\n (component: ViewPortComponent) => {\n let { viewModel, childContainer } = component;\n component.router = router;\n component.config = config;\n\n if ('configureRouter' in viewModel) {\n let childRouter = childContainer.getChildRouter();\n component.childRouter = childRouter;\n\n return childRouter\n .configure(c => viewModel.configureRouter(c, childRouter, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]))\n .then(() => component);\n }\n\n return component;\n }\n );\n};\n","import { RouteConfig } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Router } from './router';\n\n/**\n * Abstract class that is responsible for loading view / view model from a route config\n * The default implementation can be found in `aurelia-templating-router`\n */\nexport class RouteLoader {\n /**\n * Load a route config based on its viewmodel / view configuration\n */\n // return typing: return typings used to be never\n // as it was a throw. Changing it to Promise should not cause any issues\n loadRoute(router: Router, config: RouteConfig, navigationInstruction: NavigationInstruction): Promise {\n throw new Error('Route loaders must implement \"loadRoute(router, config, navigationInstruction)\".');\n }\n}\n","import { Next } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { loadNewRoute } from './utilities-route-loading';\nimport { RouteLoader } from './route-loader';\n/**\n * A pipeline step responsible for loading a route config of a navigation instruction\n */\nexport class LoadRouteStep {\n /**@internal */\n static inject() { return [RouteLoader]; }\n /**\n * Route loader isntance that will handle loading route config\n * @internal\n */\n routeLoader: RouteLoader;\n constructor(routeLoader: RouteLoader) {\n this.routeLoader = routeLoader;\n }\n /**\n * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline\n */\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return loadNewRoute(this.routeLoader, navigationInstruction)\n .then(next, next.cancel);\n }\n}\n","import { NavigationInstruction } from './navigation-instruction';\n\n/**\n * A pipeline step for instructing a piepline to commit changes on a navigation instruction\n */\nexport class CommitChangesStep {\n run(navigationInstruction: NavigationInstruction, next: Function): Promise {\n return navigationInstruction\n ._commitChanges(/*wait to swap?*/ true)\n .then(() => {\n navigationInstruction._updateTitle();\n return next();\n });\n }\n}\n","/**\n * An optional interface describing the available activation strategies.\n * @internal Used internally.\n */\nexport const enum InternalActivationStrategy {\n /**\n * Reuse the existing view model, without invoking Router lifecycle hooks.\n */\n NoChange = 'no-change',\n /**\n * Reuse the existing view model, invoking Router lifecycle hooks.\n */\n InvokeLifecycle = 'invoke-lifecycle',\n /**\n * Replace the existing view model, invoking Router lifecycle hooks.\n */\n Replace = 'replace'\n}\n\n/**\n * The strategy to use when activating modules during navigation.\n */\n// kept for compat reason\nexport const activationStrategy: ActivationStrategy = {\n noChange: InternalActivationStrategy.NoChange,\n invokeLifecycle: InternalActivationStrategy.InvokeLifecycle,\n replace: InternalActivationStrategy.Replace\n};\n\n/**\n * An optional interface describing the available activation strategies.\n */\nexport interface ActivationStrategy {\n /**\n * Reuse the existing view model, without invoking Router lifecycle hooks.\n */\n noChange: 'no-change';\n /**\n * Reuse the existing view model, invoking Router lifecycle hooks.\n */\n invokeLifecycle: 'invoke-lifecycle';\n /**\n * Replace the existing view model, invoking Router lifecycle hooks.\n */\n replace: 'replace';\n}\n\n/**\n * Enum like type for activation strategy built-in values\n */\nexport type ActivationStrategyType = ActivationStrategy[keyof ActivationStrategy];\n","import { Next, ViewPortComponent, ViewPortPlan, ViewPortInstruction, LifecycleArguments } from './interfaces';\nimport { isNavigationCommand } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy } from './activation-strategy';\nimport { Router } from './router';\n\n/**\n * Recursively find list of deactivate-able view models\n * and invoke the either 'canDeactivate' or 'deactivate' on each\n * @internal exported for unit testing\n */\nexport const processDeactivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canDeactivate' | 'deactivate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let plan: Record = navigationInstruction.plan;\n let infos = findDeactivatable(plan, callbackName);\n let i = infos.length; // query from inside out\n\n function inspect(val: any): Promise {\n if (ignoreResult || shouldContinue(val)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n if (i--) {\n try {\n let viewModel = infos[i];\n let result = viewModel[callbackName](navigationInstruction);\n return processPotential(result, inspect, next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n navigationInstruction.router.couldDeactivate = true;\n\n return next();\n }\n\n return iterate();\n};\n\n/**\n * Recursively find and returns a list of deactivate-able view models\n * @internal exported for unit testing\n */\nexport const findDeactivatable = (\n plan: Record,\n callbackName: string,\n list: IActivatableInfo[] = []\n): any[] => {\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let prevComponent = viewPortPlan.prevComponent;\n\n if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace)\n && prevComponent\n ) {\n let viewModel = prevComponent.viewModel;\n\n if (callbackName in viewModel) {\n list.push(viewModel);\n }\n }\n\n if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) {\n addPreviousDeactivatable(prevComponent, callbackName, list);\n } else if (viewPortPlan.childNavigationInstruction) {\n findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list);\n }\n }\n\n return list;\n};\n\n/**\n * @internal exported for unit testing\n */\nexport const addPreviousDeactivatable = (\n component: ViewPortComponent,\n callbackName: string,\n list: IActivatableInfo[]\n): void => {\n let childRouter = component.childRouter;\n\n if (childRouter && childRouter.currentInstruction) {\n let viewPortInstructions = childRouter.currentInstruction.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let prevComponent = viewPortInstruction.component;\n let prevViewModel = prevComponent.viewModel;\n\n if (callbackName in prevViewModel) {\n list.push(prevViewModel);\n }\n\n addPreviousDeactivatable(prevComponent, callbackName, list);\n }\n }\n};\n\n/**\n * @internal exported for unit testing\n */\nexport const processActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let infos = findActivatable(navigationInstruction, callbackName);\n let length = infos.length;\n let i = -1; // query from top down\n\n function inspect(val: any, router: Router): Promise {\n if (ignoreResult || shouldContinue(val, router)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n i++;\n\n if (i < length) {\n try {\n let current = infos[i];\n let result = current.viewModel[callbackName](...current.lifecycleArgs);\n return processPotential(result, (val: any) => inspect(val, current.router), next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n return next();\n }\n\n return iterate();\n};\n\ninterface IActivatableInfo {\n viewModel: any;\n lifecycleArgs: LifecycleArguments;\n router: Router;\n}\n\n/**\n * Find list of activatable view model and add to list (3rd parameter)\n * @internal exported for unit testing\n */\nexport const findActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n list: IActivatableInfo[] = [],\n router?: Router\n): IActivatableInfo[] => {\n let plan: Record = navigationInstruction.plan;\n\n Object\n .keys(plan)\n .forEach((viewPortName) => {\n let viewPortPlan = plan[viewPortName];\n let viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName] as ViewPortInstruction;\n let viewPortComponent = viewPortInstruction.component;\n let viewModel = viewPortComponent.viewModel;\n\n if (\n (viewPortPlan.strategy === activationStrategy.invokeLifecycle\n || viewPortPlan.strategy === activationStrategy.replace\n )\n && callbackName in viewModel\n ) {\n list.push({\n viewModel,\n lifecycleArgs: viewPortInstruction.lifecycleArgs,\n router\n });\n }\n\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (childNavInstruction) {\n findActivatable(\n childNavInstruction,\n callbackName,\n list,\n viewPortComponent.childRouter || router\n );\n }\n });\n\n return list;\n};\n\nconst shouldContinue = (output: T, router?: Router): boolean | T => {\n if (output instanceof Error) {\n return false;\n }\n\n if (isNavigationCommand(output)) {\n if (typeof output.setRouter === 'function') {\n output.setRouter(router);\n }\n\n return !!output.shouldContinueProcessing;\n }\n\n if (output === undefined) {\n return true;\n }\n\n return output;\n};\n\n/**\n * A basic interface for an Observable type\n */\nexport interface IObservable {\n subscribe(sub?: IObservableConfig): ISubscription;\n}\n\nexport interface IObservableConfig {\n next(): void;\n error(err?: any): void;\n complete(): void;\n}\n\n/**\n * A basic interface for a Subscription to an Observable\n */\ninterface ISubscription {\n unsubscribe(): void;\n}\n\ntype SafeSubscriptionFunc = (sub: SafeSubscription) => ISubscription;\n\n/**\n * wraps a subscription, allowing unsubscribe calls even if\n * the first value comes synchronously\n */\nclass SafeSubscription {\n\n private _subscribed: boolean;\n private _subscription: ISubscription;\n\n constructor(subscriptionFunc: SafeSubscriptionFunc) {\n this._subscribed = true;\n this._subscription = subscriptionFunc(this);\n\n if (!this._subscribed) {\n this.unsubscribe();\n }\n }\n\n get subscribed(): boolean {\n return this._subscribed;\n }\n\n unsubscribe(): void {\n if (this._subscribed && this._subscription) {\n this._subscription.unsubscribe();\n }\n\n this._subscribed = false;\n }\n}\n\n/**\n * A function to process return value from `activate`/`canActivate` steps\n * Supports observable/promise\n *\n * For observable, resolve at first next() or on complete()\n */\nconst processPotential = (obj: any, resolve: (val?: any) => any, reject: (err?: any) => any): any => {\n // if promise like\n if (obj && typeof obj.then === 'function') {\n return Promise.resolve(obj).then(resolve).catch(reject);\n }\n\n // if observable\n if (obj && typeof obj.subscribe === 'function') {\n let obs: IObservable = obj;\n return new SafeSubscription(sub => obs.subscribe({\n next() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n },\n error(error) {\n if (sub.subscribed) {\n sub.unsubscribe();\n reject(error);\n }\n },\n complete() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n }\n }));\n }\n\n // else just resolve\n try {\n return resolve(obj);\n } catch (error) {\n return reject(error);\n }\n};\n","import { Next } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { processDeactivatable, processActivatable } from './utilities-activation';\n\n/**\n * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route\n */\nexport class CanDeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'canDeactivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route\n */\nexport class CanActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'canActivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route\n */\nexport class DeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'deactivate', next, true);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `activate` on a view model of a route\n */\nexport class ActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'activate', next, true);\n }\n}\n","import { Container } from 'aurelia-dependency-injection';\nimport { Pipeline } from './pipeline';\nimport { BuildNavigationPlanStep } from './step-build-navigation-plan';\nimport { LoadRouteStep } from './step-load-route';\nimport { CommitChangesStep } from './step-commit-changes';\nimport { CanDeactivatePreviousStep, CanActivateNextStep, DeactivatePreviousStep, ActivateNextStep } from './step-activation';\nimport { PipelineStep, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution\n */\nclass PipelineSlot implements IPipelineSlot {\n\n /**@internal */\n container: Container;\n /**@internal */\n slotName: string;\n /**@internal */\n slotAlias?: string;\n\n steps: (Function | PipelineStep)[] = [];\n\n constructor(container: Container, name: string, alias?: string) {\n this.container = container;\n this.slotName = name;\n this.slotAlias = alias;\n }\n\n getSteps(): (StepRunnerFunction | IPipelineSlot | PipelineStep)[] {\n return this.steps.map(x => this.container.get(x));\n }\n}\n\n/**\n * Class responsible for creating the navigation pipeline.\n */\nexport class PipelineProvider {\n\n /**@internal */\n static inject() { return [Container]; }\n /**@internal */\n container: Container;\n /**@internal */\n steps: (Function | PipelineSlot)[];\n\n constructor(container: Container) {\n this.container = container;\n this.steps = [\n BuildNavigationPlanStep,\n CanDeactivatePreviousStep, // optional\n LoadRouteStep,\n createPipelineSlot(container, PipelineSlotName.Authorize),\n CanActivateNextStep, // optional\n createPipelineSlot(container, PipelineSlotName.PreActivate, 'modelbind'),\n // NOTE: app state changes start below - point of no return\n DeactivatePreviousStep, // optional\n ActivateNextStep, // optional\n createPipelineSlot(container, PipelineSlotName.PreRender, 'precommit'),\n CommitChangesStep,\n createPipelineSlot(container, PipelineSlotName.PostRender, 'postcomplete')\n ];\n }\n\n /**\n * Create the navigation pipeline.\n */\n createPipeline(useCanDeactivateStep: boolean = true): Pipeline {\n let pipeline = new Pipeline();\n this.steps.forEach(step => {\n if (useCanDeactivateStep || step !== CanDeactivatePreviousStep) {\n pipeline.addStep(this.container.get(step));\n }\n });\n return pipeline;\n }\n\n /**@internal */\n _findStep(name: string): PipelineSlot {\n // Steps that are not PipelineSlots are constructor functions, and they will automatically fail. Probably.\n return this.steps.find(x => (x as PipelineSlot).slotName === name || (x as PipelineSlot).slotAlias === name) as PipelineSlot;\n }\n\n /**\n * Adds a step into the pipeline at a known slot location.\n */\n addStep(name: string, step: PipelineStep | Function): void {\n let found = this._findStep(name);\n if (found) {\n let slotSteps = found.steps;\n // prevent duplicates\n if (!slotSteps.includes(step)) {\n slotSteps.push(step);\n }\n } else {\n throw new Error(`Invalid pipeline slot name: ${name}.`);\n }\n }\n\n /**\n * Removes a step from a slot in the pipeline\n */\n removeStep(name: string, step: PipelineStep): void {\n let slot = this._findStep(name);\n if (slot) {\n let slotSteps = slot.steps;\n slotSteps.splice(slotSteps.indexOf(step), 1);\n }\n }\n\n /**\n * Clears all steps from a slot in the pipeline\n * @internal\n */\n _clearSteps(name: string = ''): void {\n let slot = this._findStep(name);\n if (slot) {\n slot.steps = [];\n }\n }\n\n /**\n * Resets all pipeline slots\n */\n reset(): void {\n this._clearSteps(PipelineSlotName.Authorize);\n this._clearSteps(PipelineSlotName.PreActivate);\n this._clearSteps(PipelineSlotName.PreRender);\n this._clearSteps(PipelineSlotName.PostRender);\n }\n}\n\n/**@internal */\nconst createPipelineSlot = (container: Container, name: PipelineSlotName, alias?: string): PipelineSlot => {\n return new PipelineSlot(container, name, alias);\n};\n","import * as LogManager from 'aurelia-logging';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\nimport { PipelineProvider } from './pipeline-provider';\nimport { isNavigationCommand } from './navigation-commands';\nimport { EventAggregator } from 'aurelia-event-aggregator';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { ViewPort, ConfiguresRouter, PipelineResult } from './interfaces';\nimport { RouterEvent } from './router-event';\n\n/**@internal */\ndeclare module 'aurelia-dependency-injection' {\n interface Container {\n viewModel?: any;\n }\n}\n\nconst logger = LogManager.getLogger('app-router');\n\n/**\n * The main application router.\n */\nexport class AppRouter extends Router {\n\n /**@internal */\n static inject() { return [Container, History, PipelineProvider, EventAggregator]; }\n\n events: EventAggregator;\n /**@internal */\n maxInstructionCount: number;\n /**@internal */\n _queue: NavigationInstruction[];\n /**@internal */\n isActive: boolean;\n\n constructor(container: Container, history: History, pipelineProvider: PipelineProvider, events: EventAggregator) {\n super(container, history); // Note the super will call reset internally.\n this.pipelineProvider = pipelineProvider;\n this.events = events;\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset(): void {\n super.reset();\n this.maxInstructionCount = 10;\n if (!this._queue) {\n this._queue = [];\n } else {\n this._queue.length = 0;\n }\n }\n\n /**\n * Loads the specified URL.\n *\n * @param url The URL fragment to load.\n */\n loadUrl(url: string): Promise {\n return this\n ._createNavigationInstruction(url)\n .then(instruction => this._queueInstruction(instruction))\n .catch(error => {\n logger.error(error);\n restorePreviousLocation(this);\n });\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort. This is typically a element in Aurelia default impl\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/ any, name?: string): Promise {\n // having strong typing without changing public API\n const $viewPort: ViewPort = viewPort;\n super.registerViewPort($viewPort, name);\n\n // beside adding viewport to the registry of this instance\n // AppRouter also configure routing/history to start routing functionality\n // There are situation where there are more than 1 element at root view\n // in that case, still only activate once via the following guard\n if (!this.isActive) {\n const viewModel = this._findViewModel($viewPort);\n if ('configureRouter' in viewModel) {\n // If there are more than one element at root view\n // use this flag to guard against configure method being invoked multiple times\n // this flag is set inside method configure\n if (!this.isConfigured) {\n // replace the real resolve with a noop to guarantee that any action in base class Router\n // won't resolve the configurePromise prematurely\n const resolveConfiguredPromise = this._resolveConfiguredPromise;\n this._resolveConfiguredPromise = () => {/**/};\n return this\n .configure(config => {\n viewModel.configureRouter(config, this);\n return config;\n })\n .then(() => {\n this.activate();\n resolveConfiguredPromise();\n });\n }\n } else {\n this.activate();\n }\n }\n // when a viewport is added dynamically to a root view that is already activated\n // just process the navigation instruction\n else {\n this._dequeueInstruction();\n }\n\n return Promise.resolve();\n }\n\n /**\n * Activates the router. This instructs the router to begin listening for history changes and processing instructions.\n *\n * @params options The set of options to activate the router with.\n */\n activate(options?: NavigationOptions): void {\n if (this.isActive) {\n return;\n }\n\n this.isActive = true;\n // route handler property is responsible for handling url change\n // the interface of aurelia-history isn't clear on this perspective\n this.options = Object.assign({ routeHandler: this.loadUrl.bind(this) }, this.options, options);\n this.history.activate(this.options);\n this._dequeueInstruction();\n }\n\n /**\n * Deactivates the router.\n */\n deactivate(): void {\n this.isActive = false;\n this.history.deactivate();\n }\n\n /**@internal */\n _queueInstruction(instruction: NavigationInstruction): Promise {\n return new Promise((resolve) => {\n instruction.resolve = resolve;\n this._queue.unshift(instruction);\n this._dequeueInstruction();\n });\n }\n\n /**@internal */\n _dequeueInstruction(instructionCount: number = 0): Promise {\n return Promise.resolve().then(() => {\n if (this.isNavigating && !instructionCount) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n let instruction = this._queue.shift();\n this._queue.length = 0;\n\n if (!instruction) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n this.isNavigating = true;\n\n let navtracker: number = this.history.getState('NavigationTracker');\n let currentNavTracker = this.currentNavigationTracker;\n\n if (!navtracker && !currentNavTracker) {\n this.isNavigatingFirst = true;\n this.isNavigatingNew = true;\n } else if (!navtracker) {\n this.isNavigatingNew = true;\n } else if (!currentNavTracker) {\n this.isNavigatingRefresh = true;\n } else if (currentNavTracker < navtracker) {\n this.isNavigatingForward = true;\n } else if (currentNavTracker > navtracker) {\n this.isNavigatingBack = true;\n } if (!navtracker) {\n navtracker = Date.now();\n this.history.setState('NavigationTracker', navtracker);\n }\n this.currentNavigationTracker = navtracker;\n\n instruction.previousInstruction = this.currentInstruction;\n\n let maxInstructionCount = this.maxInstructionCount;\n\n if (!instructionCount) {\n this.events.publish(RouterEvent.Processing, { instruction });\n } else if (instructionCount === maxInstructionCount - 1) {\n logger.error(`${instructionCount + 1} navigation instructions have been attempted without success. Restoring last known good location.`);\n restorePreviousLocation(this);\n return this._dequeueInstruction(instructionCount + 1);\n } else if (instructionCount > maxInstructionCount) {\n throw new Error('Maximum navigation attempts exceeded. Giving up.');\n }\n\n let pipeline = this.pipelineProvider.createPipeline(!this.couldDeactivate);\n\n return pipeline\n .run(instruction)\n .then(result => processResult(instruction, result, instructionCount, this))\n .catch(error => {\n return { output: error instanceof Error ? error : new Error(error) } as PipelineResult;\n })\n .then(result => resolveInstruction(instruction, result, !!instructionCount, this));\n });\n }\n\n /**@internal */\n _findViewModel(viewPort: ViewPort): ConfiguresRouter | undefined {\n if (this.container.viewModel) {\n return this.container.viewModel;\n }\n\n if (viewPort.container) {\n let container = viewPort.container;\n\n while (container) {\n if (container.viewModel) {\n this.container.viewModel = container.viewModel;\n return container.viewModel;\n }\n\n container = container.parent;\n }\n }\n\n return undefined;\n }\n}\n\nconst processResult = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n instructionCount: number,\n router: AppRouter\n): Promise => {\n if (!(result && 'completed' in result && 'output' in result)) {\n result = result || {} as PipelineResult;\n result.output = new Error(`Expected router pipeline to return a navigation result, but got [${JSON.stringify(result)}] instead.`);\n }\n\n let finalResult: PipelineResult = null;\n let navigationCommandResult = null;\n if (isNavigationCommand(result.output)) {\n navigationCommandResult = result.output.navigate(router);\n } else {\n finalResult = result;\n\n if (!result.completed) {\n if (result.output instanceof Error) {\n logger.error(result.output.toString());\n }\n\n restorePreviousLocation(router);\n }\n }\n\n return Promise.resolve(navigationCommandResult)\n .then(_ => router._dequeueInstruction(instructionCount + 1))\n .then(innerResult => finalResult || innerResult || result);\n};\n\nconst resolveInstruction = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n isInnerInstruction: boolean,\n router: AppRouter\n): PipelineResult => {\n instruction.resolve(result);\n\n let eventAggregator = router.events;\n let eventArgs = { instruction, result };\n if (!isInnerInstruction) {\n router.isNavigating = false;\n router.isExplicitNavigation = false;\n router.isExplicitNavigationBack = false;\n router.isNavigatingFirst = false;\n router.isNavigatingNew = false;\n router.isNavigatingRefresh = false;\n router.isNavigatingForward = false;\n router.isNavigatingBack = false;\n router.couldDeactivate = false;\n\n let eventName: string;\n\n if (result.output instanceof Error) {\n eventName = RouterEvent.Error;\n } else if (!result.completed) {\n eventName = RouterEvent.Canceled;\n } else {\n let queryString = instruction.queryString ? ('?' + instruction.queryString) : '';\n router.history.previousLocation = instruction.fragment + queryString;\n eventName = RouterEvent.Success;\n }\n\n eventAggregator.publish(eventName, eventArgs);\n eventAggregator.publish(RouterEvent.Complete, eventArgs);\n } else {\n eventAggregator.publish(RouterEvent.ChildComplete, eventArgs);\n }\n\n return result;\n};\n\nconst restorePreviousLocation = (router: AppRouter): void => {\n let previousLocation = router.history.previousLocation;\n if (previousLocation) {\n router.navigate(previousLocation, { trigger: false, replace: true });\n } else if (router.fallbackRoute) {\n router.navigate(router.fallbackRoute, { trigger: true, replace: true });\n } else {\n logger.error('Router navigation failed, and no previous location or fallbackRoute could be restored.');\n }\n};\n","/**\n* The status of a Pipeline.\n*/\nexport const enum PipelineStatus {\n Completed = 'completed',\n Canceled = 'canceled',\n Rejected = 'rejected',\n Running = 'running'\n}\n","/**\n * A list of known router events used by the Aurelia router\n * to signal the pipeline has come to a certain state\n */\n// const enum is preserved in tsconfig\nexport const enum RouterEvent {\n Processing = 'router:navigation:processing',\n Error = 'router:navigation:error',\n Canceled = 'router:navigation:canceled',\n Complete = 'router:navigation:complete',\n Success = 'router:navigation:success',\n ChildComplete = 'router:navigation:child:complete'\n}\n","/**\n * Available pipeline slot names to insert interceptor into router pipeline\n */\n// const enum is preserved in tsconfig\nexport const enum PipelineSlotName {\n /**\n * Authorization slot. Invoked early in the pipeline,\n * before `canActivate` hook of incoming route\n */\n Authorize = 'authorize',\n /**\n * Pre-activation slot. Invoked early in the pipeline,\n * Invoked timing:\n * - after Authorization slot\n * - after canActivate hook on new view model\n * - before deactivate hook on old view model\n * - before activate hook on new view model\n */\n PreActivate = 'preActivate',\n /**\n * Pre-render slot. Invoked later in the pipeline\n * Invokcation timing:\n * - after activate hook on new view model\n * - before commit step on new navigation instruction\n */\n PreRender = 'preRender',\n /**\n * Post-render slot. Invoked last in the pipeline\n */\n PostRender = 'postRender'\n}\n"],"names":["RouteRecognizer","Container","LogManager.getLogger","tslib_1.__extends","History","EventAggregator","PipelineStatus","RouterEvent","PipelineSlotName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA;;;AAGA;IA4DE,+BAAY,IAA+B;;;;QAT3C,SAAI,GAAwC,IAAI,CAAC;QAEjD,YAAO,GAAwB,EAAE,CAAC;QAQhC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAE1B,IAAI,CAAC,MAAM,GAAG,IAAI,C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c,KAAdA,sBAAc,QAK/B;;ACRD;;;;AAIA,AACA,WAAkB,WAAW;IAC3B,0DAA2C,CAAA;IAC3C,gDAAiC,CAAA;IACjC,sDAAuC,CAAA;IACvC,sDAAuC,CAAA;IACvC,oDAAqC,CAAA;IACrC,iEAAkD,CAAA;CACnD,EAPiBC,mBAAW,KAAXA,mBAAW,QAO5B;;ACZD;;;AAGA,AACA,WAAkB,gBAAgB;;;;;IAKhC,2CAAuB,CAAA;;;;;;;;;IASvB,+CAA2B,CAAA;;;;;;;IAO3B,2CAAuB,CAAA;;;;IAIvB,6CAAyB,CAAA;CAC1B,EA1BiBC,wBAAgB,KAAhBA,wBAAgB,QA0BjC;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/es2015/aurelia-router.js b/dist/es2015/aurelia-router.js index 75892582..a7f36e18 100644 --- a/dist/es2015/aurelia-router.js +++ b/dist/es2015/aurelia-router.js @@ -5,1659 +5,1776 @@ import { RouteRecognizer } from 'aurelia-route-recognizer'; import { EventAggregator } from 'aurelia-event-aggregator'; /** -* Determines if the provided object is a navigation command. -* A navigation command is anything with a navigate method. -* -* @param obj The object to check. -*/ -function isNavigationCommand(obj) { - return obj && typeof obj.navigate === 'function'; -} -/** -* Used during the activation lifecycle to cause a redirect. -*/ -class Redirect { + * Class used to represent an instruction during a navigation. + */ +class NavigationInstruction { + constructor(init) { + /** + * Current built viewport plan of this nav instruction + */ + this.plan = null; + this.options = {}; + Object.assign(this, init); + this.params = this.params || {}; + this.viewPortInstructions = {}; + let ancestorParams = []; + let current = this; + do { + let currentParams = Object.assign({}, current.params); + if (current.config && current.config.hasChildRouter) { + // remove the param for the injected child route segment + delete currentParams[current.getWildCardName()]; + } + ancestorParams.unshift(currentParams); + current = current.parentInstruction; + } while (current); + let allParams = Object.assign({}, this.queryParams, ...ancestorParams); + this.lifecycleArgs = [allParams, this.config, this]; + } /** - * @param url The URL fragment to use as the navigation destination. - * @param options The navigation options. + * Gets an array containing this instruction and all child instructions for the current navigation. */ - constructor(url, options = {}) { - this.url = url; - this.options = Object.assign({ trigger: true, replace: true }, options); - this.shouldContinueProcessing = false; + getAllInstructions() { + let instructions = [this]; + let viewPortInstructions = this.viewPortInstructions; + for (let key in viewPortInstructions) { + let childInstruction = viewPortInstructions[key].childNavigationInstruction; + if (childInstruction) { + instructions.push(...childInstruction.getAllInstructions()); + } + } + return instructions; } /** - * Called by the activation system to set the child router. - * - * @param router The router. - */ - setRouter(router) { - this.router = router; + * Gets an array containing the instruction and all child instructions for the previous navigation. + * Previous instructions are no longer available after navigation completes. + */ + getAllPreviousInstructions() { + return this.getAllInstructions().map(c => c.previousInstruction).filter(c => c); } - /** - * Called by the navigation pipeline to navigate. - * - * @param appRouter The router to be redirected. - */ - navigate(appRouter) { - let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); - navigatingRouter.navigate(this.url, this.options); + addViewPortInstruction(nameOrInitOptions, strategy, moduleId, component) { + let viewPortInstruction; + let viewPortName = typeof nameOrInitOptions === 'string' ? nameOrInitOptions : nameOrInitOptions.name; + const lifecycleArgs = this.lifecycleArgs; + const config = Object.assign({}, lifecycleArgs[1], { currentViewPort: viewPortName }); + if (typeof nameOrInitOptions === 'string') { + viewPortInstruction = { + name: nameOrInitOptions, + strategy: strategy, + moduleId: moduleId, + component: component, + childRouter: component.childRouter, + lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] + }; + } + else { + viewPortInstruction = { + name: viewPortName, + strategy: nameOrInitOptions.strategy, + component: nameOrInitOptions.component, + moduleId: nameOrInitOptions.moduleId, + childRouter: nameOrInitOptions.component.childRouter, + lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] + }; + } + return this.viewPortInstructions[viewPortName] = viewPortInstruction; } -} -/** -* Used during the activation lifecycle to cause a redirect to a named route. -*/ -class RedirectToRoute { /** - * @param route The name of the route. - * @param params The parameters to be sent to the activation method. - * @param options The options to use for navigation. + * Gets the name of the route pattern's wildcard parameter, if applicable. */ - constructor(route, params = {}, options = {}) { - this.route = route; - this.params = params; - this.options = Object.assign({ trigger: true, replace: true }, options); - this.shouldContinueProcessing = false; + getWildCardName() { + // todo: potential issue, or at least unsafe typings + let configRoute = this.config.route; + let wildcardIndex = configRoute.lastIndexOf('*'); + return configRoute.substr(wildcardIndex + 1); } /** - * Called by the activation system to set the child router. - * - * @param router The router. - */ - setRouter(router) { - this.router = router; + * Gets the path and query string created by filling the route + * pattern's wildcard parameter with the matching param. + */ + getWildcardPath() { + let wildcardName = this.getWildCardName(); + let path = this.params[wildcardName] || ''; + let queryString = this.queryString; + if (queryString) { + path += '?' + queryString; + } + return path; } /** - * Called by the navigation pipeline to navigate. - * - * @param appRouter The router to be redirected. - */ - navigate(appRouter) { - let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); - navigatingRouter.navigateToRoute(this.route, this.params, this.options); - } -} - -/** -* The strategy to use when activating modules during navigation. -*/ -const activationStrategy = { - noChange: 'no-change', - invokeLifecycle: 'invoke-lifecycle', - replace: 'replace' -}; -/** - * Transform a navigation instruction into viewport plan record object, - * or a redirect request if user viewmodel demands - */ -class BuildNavigationPlanStep { - run(navigationInstruction, next) { - return _buildNavigationPlan(navigationInstruction) - .then(plan => { - if (plan instanceof Redirect) { - return next.cancel(plan); + * Gets the instruction's base URL, accounting for wildcard route parameters. + */ + getBaseUrl() { + let $encodeURI = encodeURI; + let fragment = decodeURI(this.fragment); + if (fragment === '') { + let nonEmptyRoute = this.router.routes.find(route => { + return route.name === this.config.name && + route.route !== ''; + }); + if (nonEmptyRoute) { + fragment = nonEmptyRoute.route; } - navigationInstruction.plan = plan; - return next(); - }) - .catch(next.cancel); + } + if (!this.params) { + return $encodeURI(fragment); + } + let wildcardName = this.getWildCardName(); + let path = this.params[wildcardName] || ''; + if (!path) { + return $encodeURI(fragment); + } + return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path))); } -} -function _buildNavigationPlan(instruction, forceLifecycleMinimum) { - let config = instruction.config; - // todo: separate and export for unit tests - if ('redirect' in config) { - const router = instruction.router; - return router - ._createNavigationInstruction(config.redirect) - .then(newInstruction => { - const params = {}; - for (let key in newInstruction.params) { - // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this } - let val = newInstruction.params[key]; - if (typeof val === 'string' && val[0] === ':') { - val = val.slice(1); - // And if that param is found on the original instruction then use it - if (val in instruction.params) { - params[key] = instruction.params[val]; - } + /** + * Finalize a viewport instruction + * @internal + */ + _commitChanges(waitToSwap) { + let router = this.router; + router.currentInstruction = this; + const previousInstruction = this.previousInstruction; + if (previousInstruction) { + previousInstruction.config.navModel.isActive = false; + } + this.config.navModel.isActive = true; + router.refreshNavigation(); + let loads = []; + let delaySwaps = []; + let viewPortInstructions = this.viewPortInstructions; + for (let viewPortName in viewPortInstructions) { + let viewPortInstruction = viewPortInstructions[viewPortName]; + let viewPort = router.viewPorts[viewPortName]; + if (!viewPort) { + throw new Error(`There was no router-view found in the view for ${viewPortInstruction.moduleId}.`); + } + let childNavInstruction = viewPortInstruction.childNavigationInstruction; + if (viewPortInstruction.strategy === "replace" /* Replace */) { + if (childNavInstruction && childNavInstruction.parentCatchHandler) { + loads.push(childNavInstruction._commitChanges(waitToSwap)); } else { - params[key] = newInstruction.params[key]; + if (waitToSwap) { + delaySwaps.push({ viewPort, viewPortInstruction }); + } + loads.push(viewPort + .process(viewPortInstruction, waitToSwap) + .then(() => childNavInstruction + ? childNavInstruction._commitChanges(waitToSwap) + : Promise.resolve())); } } - let redirectLocation = router.generate(newInstruction.config, params, instruction.options); - // Special handling for child routes - for (let key in instruction.params) { - redirectLocation = redirectLocation.replace(`:${key}`, instruction.params[key]); - } - if (instruction.queryString) { - redirectLocation += '?' + instruction.queryString; - } - return Promise.resolve(new Redirect(redirectLocation)); - }); - } - const prev = instruction.previousInstruction; - const plan = {}; - const defaults = instruction.router.viewPortDefaults; - if (prev) { - let newParams = hasDifferentParameterValues(prev, instruction); - let pending = []; - for (let viewPortName in prev.viewPortInstructions) { - const prevViewPortInstruction = prev.viewPortInstructions[viewPortName]; - let nextViewPortConfig = viewPortName in config.viewPorts ? config.viewPorts[viewPortName] : prevViewPortInstruction; - if (nextViewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) { - nextViewPortConfig = defaults[viewPortName]; - } - const viewPortPlan = plan[viewPortName] = { - name: viewPortName, - config: nextViewPortConfig, - prevComponent: prevViewPortInstruction.component, - prevModuleId: prevViewPortInstruction.moduleId - }; - if (prevViewPortInstruction.moduleId !== nextViewPortConfig.moduleId) { - viewPortPlan.strategy = activationStrategy.replace; - } - else if ('determineActivationStrategy' in prevViewPortInstruction.component.viewModel) { - viewPortPlan.strategy = prevViewPortInstruction.component.viewModel - .determineActivationStrategy(...instruction.lifecycleArgs); - } - else if (config.activationStrategy) { - viewPortPlan.strategy = config.activationStrategy; - } - else if (newParams || forceLifecycleMinimum) { - viewPortPlan.strategy = activationStrategy.invokeLifecycle; - } else { - viewPortPlan.strategy = activationStrategy.noChange; - } - if (viewPortPlan.strategy !== activationStrategy.replace && prevViewPortInstruction.childRouter) { - const path = instruction.getWildcardPath(); - const task = prevViewPortInstruction - .childRouter - ._createNavigationInstruction(path, instruction) - .then((childInstruction) => { - viewPortPlan.childNavigationInstruction = childInstruction; - return _buildNavigationPlan(childInstruction, viewPortPlan.strategy === activationStrategy.invokeLifecycle) - .then(childPlan => { - if (childPlan instanceof Redirect) { - return Promise.reject(childPlan); - } - childInstruction.plan = childPlan; - // for bluebird ? - return null; - }); - }); - pending.push(task); + if (childNavInstruction) { + loads.push(childNavInstruction._commitChanges(waitToSwap)); + } } } - return Promise.all(pending).then(() => plan); + return Promise + .all(loads) + .then(() => { + delaySwaps.forEach(x => x.viewPort.swap(x.viewPortInstruction)); + return null; + }) + .then(() => prune(this)); } - for (let viewPortName in config.viewPorts) { - let viewPortConfig = config.viewPorts[viewPortName]; - if (viewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) { - viewPortConfig = defaults[viewPortName]; + /**@internal */ + _updateTitle() { + let router = this.router; + let title = this._buildTitle(router.titleSeparator); + if (title) { + router.history.setTitle(title); } - plan[viewPortName] = { - name: viewPortName, - strategy: activationStrategy.replace, - config: viewPortConfig - }; } - return Promise.resolve(plan); -} -function hasDifferentParameterValues(prev, next) { - let prevParams = prev.params; - let nextParams = next.params; - let nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; - for (let key in nextParams) { - if (key === nextWildCardName) { - continue; + /**@internal */ + _buildTitle(separator = ' | ') { + let title = ''; + let childTitles = []; + let navModelTitle = this.config.navModel.title; + let instructionRouter = this.router; + let viewPortInstructions = this.viewPortInstructions; + if (navModelTitle) { + title = instructionRouter.transformTitle(navModelTitle); } - if (prevParams[key] !== nextParams[key]) { - return true; + for (let viewPortName in viewPortInstructions) { + let viewPortInstruction = viewPortInstructions[viewPortName]; + let child_nav_instruction = viewPortInstruction.childNavigationInstruction; + if (child_nav_instruction) { + let childTitle = child_nav_instruction._buildTitle(separator); + if (childTitle) { + childTitles.push(childTitle); + } + } } - } - for (let key in prevParams) { - if (key === nextWildCardName) { - continue; + if (childTitles.length) { + title = childTitles.join(separator) + (title ? separator : '') + title; } - if (prevParams[key] !== nextParams[key]) { - return true; + if (instructionRouter.title) { + title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title); } + return title; } - if (!next.options.compareQueryParams) { - return false; - } - let prevQueryParams = prev.queryParams; - let nextQueryParams = next.queryParams; - for (let key in nextQueryParams) { - if (prevQueryParams[key] !== nextQueryParams[key]) { - return true; - } +} +const prune = (instruction) => { + instruction.previousInstruction = null; + instruction.plan = null; +}; + +/** +* Class for storing and interacting with a route's navigation settings. +*/ +class NavModel { + constructor(router, relativeHref) { + /** + * True if this nav item is currently active. + */ + this.isActive = false; + /** + * The title. + */ + this.title = null; + /** + * This nav item's absolute href. + */ + this.href = null; + /** + * This nav item's relative href. + */ + this.relativeHref = null; + /** + * Data attached to the route at configuration time. + */ + this.settings = {}; + /** + * The route config. + */ + this.config = null; + this.router = router; + this.relativeHref = relativeHref; } - for (let key in prevQueryParams) { - if (prevQueryParams[key] !== nextQueryParams[key]) { - return true; + /** + * Sets the route's title and updates document.title. + * If the a navigation is in progress, the change will be applied + * to document.title when the navigation completes. + * + * @param title The new title. + */ + setTitle(title) { + this.title = title; + if (this.isActive) { + this.router.updateTitle(); } } - return false; } -/** - * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route - */ -class CanDeactivatePreviousStep { - run(navigationInstruction, next) { - return processDeactivatable(navigationInstruction, 'canDeactivate', next); +function _normalizeAbsolutePath(path, hasPushState, absolute = false) { + if (!hasPushState && path[0] !== '#') { + path = '#' + path; } -} -/** - * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route - */ -class CanActivateNextStep { - run(navigationInstruction, next) { - return processActivatable(navigationInstruction, 'canActivate', next); + if (hasPushState && absolute) { + path = path.substring(1, path.length); } + return path; } -/** - * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route - */ -class DeactivatePreviousStep { - run(navigationInstruction, next) { - return processDeactivatable(navigationInstruction, 'deactivate', next, true); +function _createRootedPath(fragment, baseUrl, hasPushState, absolute) { + if (isAbsoluteUrl.test(fragment)) { + return fragment; + } + let path = ''; + if (baseUrl.length && baseUrl[0] !== '/') { + path += '/'; } + path += baseUrl; + if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') { + path += '/'; + } + if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') { + path = path.substring(0, path.length - 1); + } + return _normalizeAbsolutePath(path + fragment, hasPushState, absolute); } -/** - * A pipeline step responsible for finding and activating method `activate` on a view model of a route - */ -class ActivateNextStep { - run(navigationInstruction, next) { - return processActivatable(navigationInstruction, 'activate', next, true); +function _resolveUrl(fragment, baseUrl, hasPushState) { + if (isRootedPath.test(fragment)) { + return _normalizeAbsolutePath(fragment, hasPushState); } + return _createRootedPath(fragment, baseUrl, hasPushState); } -/** - * Recursively find list of deactivate-able view models - * and invoke the either 'canDeactivate' or 'deactivate' on each - */ -const processDeactivatable = (navigationInstruction, callbackName, next, ignoreResult) => { - let plan = navigationInstruction.plan; - let infos = findDeactivatable(plan, callbackName); - let i = infos.length; // query from inside out - function inspect(val) { - if (ignoreResult || shouldContinue(val)) { - return iterate(); +function _ensureArrayWithSingleRoutePerConfig(config) { + let routeConfigs = []; + if (Array.isArray(config.route)) { + for (let i = 0, ii = config.route.length; i < ii; ++i) { + let current = Object.assign({}, config); + current.route = config.route[i]; + routeConfigs.push(current); } - return next.cancel(val); } - function iterate() { - if (i--) { - try { - let viewModel = infos[i]; - let result = viewModel[callbackName](navigationInstruction); - return processPotential(result, inspect, next.cancel); - } - catch (error) { - return next.cancel(error); - } - } - navigationInstruction.router.couldDeactivate = true; - return next(); + else { + routeConfigs.push(Object.assign({}, config)); } - return iterate(); -}; + return routeConfigs; +} +const isRootedPath = /^#?\//; +const isAbsoluteUrl = /^([a-z][a-z0-9+\-.]*:)?\/\//i; + /** - * Recursively find and returns a list of deactivate-able view models + * Class used to configure a [[Router]] instance. + * + * @constructor */ -const findDeactivatable = (plan, callbackName, list = []) => { - for (let viewPortName in plan) { - let viewPortPlan = plan[viewPortName]; - let prevComponent = viewPortPlan.prevComponent; - if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace) - && prevComponent) { - let viewModel = prevComponent.viewModel; - if (callbackName in viewModel) { - list.push(viewModel); - } - } - if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) { - addPreviousDeactivatable(prevComponent, callbackName, list); - } - else if (viewPortPlan.childNavigationInstruction) { - findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list); - } +class RouterConfiguration { + constructor() { + this.instructions = []; + this.options = {}; + this.pipelineSteps = []; } - return list; -}; -const addPreviousDeactivatable = (component, callbackName, list) => { - let childRouter = component.childRouter; - if (childRouter && childRouter.currentInstruction) { - let viewPortInstructions = childRouter.currentInstruction.viewPortInstructions; - for (let viewPortName in viewPortInstructions) { - let viewPortInstruction = viewPortInstructions[viewPortName]; - let prevComponent = viewPortInstruction.component; - let prevViewModel = prevComponent.viewModel; - if (callbackName in prevViewModel) { - list.push(prevViewModel); - } - addPreviousDeactivatable(prevComponent, callbackName, list); + /** + * Adds a step to be run during the [[Router]]'s navigation pipeline. + * + * @param name The name of the pipeline slot to insert the step into. + * @param step The pipeline step. + * @chainable + */ + addPipelineStep(name, step) { + if (step === null || step === undefined) { + throw new Error('Pipeline step cannot be null or undefined.'); } + this.pipelineSteps.push({ name, step }); + return this; } -}; -const processActivatable = (navigationInstruction, callbackName, next, ignoreResult) => { - let infos = findActivatable(navigationInstruction, callbackName); - let length = infos.length; - let i = -1; // query from top down - function inspect(val, router) { - if (ignoreResult || shouldContinue(val, router)) { - return iterate(); - } - return next.cancel(val); + /** + * Adds a step to be run during the [[Router]]'s authorize pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + addAuthorizeStep(step) { + return this.addPipelineStep("authorize" /* Authorize */, step); } - function iterate() { - i++; - if (i < length) { - try { - let current = infos[i]; - let result = current.viewModel[callbackName](...current.lifecycleArgs); - return processPotential(result, (val) => inspect(val, current.router), next.cancel); - } - catch (error) { - return next.cancel(error); - } - } - return next(); + /** + * Adds a step to be run during the [[Router]]'s preActivate pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + addPreActivateStep(step) { + return this.addPipelineStep("preActivate" /* PreActivate */, step); } - return iterate(); -}; -/** - * Find list of activatable view model and add to list (3rd parameter) - */ -const findActivatable = (navigationInstruction, callbackName, list = [], router) => { - let plan = navigationInstruction.plan; - Object - .keys(plan) - .forEach((viewPortName) => { - let viewPortPlan = plan[viewPortName]; - let viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName]; - let viewPortComponent = viewPortInstruction.component; - let viewModel = viewPortComponent.viewModel; - if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle - || viewPortPlan.strategy === activationStrategy.replace) - && callbackName in viewModel) { - list.push({ - viewModel, - lifecycleArgs: viewPortInstruction.lifecycleArgs, - router - }); - } - let childNavInstruction = viewPortPlan.childNavigationInstruction; - if (childNavInstruction) { - findActivatable(childNavInstruction, callbackName, list, viewPortComponent.childRouter || router); - } - }); - return list; -}; -const shouldContinue = (output, router) => { - if (output instanceof Error) { - return false; - } - if (isNavigationCommand(output)) { - if (typeof output.setRouter === 'function') { - output.setRouter(router); - } - return !!output.shouldContinueProcessing; - } - if (output === undefined) { - return true; + /** + * Adds a step to be run during the [[Router]]'s preRender pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + addPreRenderStep(step) { + return this.addPipelineStep("preRender" /* PreRender */, step); } - return output; -}; -/** - * wraps a subscription, allowing unsubscribe calls even if - * the first value comes synchronously - */ -class SafeSubscription { - constructor(subscriptionFunc) { - this._subscribed = true; - this._subscription = subscriptionFunc(this); - if (!this._subscribed) { - this.unsubscribe(); - } + /** + * Adds a step to be run during the [[Router]]'s postRender pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + addPostRenderStep(step) { + return this.addPipelineStep("postRender" /* PostRender */, step); } - get subscribed() { - return this._subscribed; + /** + * Configures a route that will be used if there is no previous location available on navigation cancellation. + * + * @param fragment The URL fragment to use as the navigation destination. + * @chainable + */ + fallbackRoute(fragment) { + this._fallbackRoute = fragment; + return this; } - unsubscribe() { - if (this._subscribed && this._subscription) { - this._subscription.unsubscribe(); + /** + * Maps one or more routes to be registered with the router. + * + * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map. + * @chainable + */ + map(route) { + if (Array.isArray(route)) { + route.forEach(r => this.map(r)); + return this; } - this._subscribed = false; + return this.mapRoute(route); } -} -/** - * A function to process return value from `activate`/`canActivate` steps - * Supports observable/promise - * - * For observable, resolve at first next() or on complete() - */ -const processPotential = (obj, resolve, reject) => { - // if promise like - if (obj && typeof obj.then === 'function') { - return Promise.resolve(obj).then(resolve).catch(reject); + /** + * Configures defaults to use for any view ports. + * + * @param viewPortConfig a view port configuration object to use as a + * default, of the form { viewPortName: { moduleId } }. + * @chainable + */ + useViewPortDefaults(viewPortConfig) { + this.viewPortDefaults = viewPortConfig; + return this; } - // if observable - if (obj && typeof obj.subscribe === 'function') { - let obs = obj; - return new SafeSubscription(sub => obs.subscribe({ - next() { - if (sub.subscribed) { - sub.unsubscribe(); - resolve(obj); - } - }, - error(error) { - if (sub.subscribed) { - sub.unsubscribe(); - reject(error); - } - }, - complete() { - if (sub.subscribed) { - sub.unsubscribe(); - resolve(obj); + /** + * Maps a single route to be registered with the router. + * + * @param route The [[RouteConfig]] to map. + * @chainable + */ + mapRoute(config) { + this.instructions.push(router => { + let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); + let navModel; + for (let i = 0, ii = routeConfigs.length; i < ii; ++i) { + let routeConfig = routeConfigs[i]; + routeConfig.settings = routeConfig.settings || {}; + if (!navModel) { + navModel = router.createNavModel(routeConfig); } + router.addRoute(routeConfig, navModel); } - })); + }); + return this; } - // else just resolve - try { - return resolve(obj); + /** + * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes. + * + * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the + * [[NavigationInstruction]] and selects a moduleId to load. + * @chainable + */ + mapUnknownRoutes(config) { + this.unknownRouteConfig = config; + return this; } - catch (error) { - return reject(error); + /** + * Applies the current configuration to the specified [[Router]]. + * + * @param router The [[Router]] to apply the configuration to. + */ + exportToRouter(router) { + let instructions = this.instructions; + for (let i = 0, ii = instructions.length; i < ii; ++i) { + instructions[i](router); + } + let { title, titleSeparator, unknownRouteConfig, _fallbackRoute, viewPortDefaults } = this; + if (title) { + router.title = title; + } + if (titleSeparator) { + router.titleSeparator = titleSeparator; + } + if (unknownRouteConfig) { + router.handleUnknownRoutes(unknownRouteConfig); + } + if (_fallbackRoute) { + router.fallbackRoute = _fallbackRoute; + } + if (viewPortDefaults) { + router.useViewPortDefaults(viewPortDefaults); + } + Object.assign(router.options, this.options); + let pipelineSteps = this.pipelineSteps; + let pipelineStepCount = pipelineSteps.length; + if (pipelineStepCount) { + if (!router.isRoot) { + throw new Error('Pipeline steps can only be added to the root router'); + } + let pipelineProvider = router.pipelineProvider; + for (let i = 0, ii = pipelineStepCount; i < ii; ++i) { + let { name, step } = pipelineSteps[i]; + pipelineProvider.addStep(name, step); + } + } } -}; +} /** - * A pipeline step for instructing a piepline to commit changes on a navigation instruction + * The primary class responsible for handling routing and navigation. */ -class CommitChangesStep { - run(navigationInstruction, next) { - return navigationInstruction - ._commitChanges(/*wait to swap?*/ true) - .then(() => { - navigationInstruction._updateTitle(); - return next(); - }); - } -} -/** -* Class used to represent an instruction during a navigation. -*/ -class NavigationInstruction { - constructor(init) { +class Router { + /** + * @param container The [[Container]] to use when child routers. + * @param history The [[History]] implementation to delegate navigation requests to. + */ + constructor(container, history) { /** - * Current built viewport plan of this nav instruction + * The parent router, or null if this instance is not a child router. */ - this.plan = null; + this.parent = null; this.options = {}; - Object.assign(this, init); - this.params = this.params || {}; - this.viewPortInstructions = {}; - let ancestorParams = []; - let current = this; - do { - let currentParams = Object.assign({}, current.params); - if (current.config && current.config.hasChildRouter) { - // remove the param for the injected child route segment - delete currentParams[current.getWildCardName()]; + /** + * The defaults used when a viewport lacks specified content + */ + this.viewPortDefaults = {}; + /** + * Extension point to transform the document title before it is built and displayed. + * By default, child routers delegate to the parent router, and the app router + * returns the title unchanged. + */ + this.transformTitle = (title) => { + if (this.parent) { + return this.parent.transformTitle(title); } - ancestorParams.unshift(currentParams); - current = current.parentInstruction; - } while (current); - let allParams = Object.assign({}, this.queryParams, ...ancestorParams); - this.lifecycleArgs = [allParams, this.config, this]; + return title; + }; + this.container = container; + this.history = history; + this.reset(); } /** - * Gets an array containing this instruction and all child instructions for the current navigation. - */ - getAllInstructions() { - let instructions = [this]; - let viewPortInstructions = this.viewPortInstructions; - for (let key in viewPortInstructions) { - let childInstruction = viewPortInstructions[key].childNavigationInstruction; - if (childInstruction) { - instructions.push(...childInstruction.getAllInstructions()); - } - } - return instructions; + * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. + * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. + */ + reset() { + this.viewPorts = {}; + this.routes = []; + this.baseUrl = ''; + this.isConfigured = false; + this.isNavigating = false; + this.isExplicitNavigation = false; + this.isExplicitNavigationBack = false; + this.isNavigatingFirst = false; + this.isNavigatingNew = false; + this.isNavigatingRefresh = false; + this.isNavigatingForward = false; + this.isNavigatingBack = false; + this.couldDeactivate = false; + this.navigation = []; + this.currentInstruction = null; + this.viewPortDefaults = {}; + this._fallbackOrder = 100; + this._recognizer = new RouteRecognizer(); + this._childRecognizer = new RouteRecognizer(); + this._configuredPromise = new Promise(resolve => { + this._resolveConfiguredPromise = resolve; + }); } /** - * Gets an array containing the instruction and all child instructions for the previous navigation. - * Previous instructions are no longer available after navigation completes. - */ - getAllPreviousInstructions() { - return this.getAllInstructions().map(c => c.previousInstruction).filter(c => c); + * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent. + */ + get isRoot() { + return !this.parent; } /** - * Adds a viewPort instruction. Returns the newly created instruction based on parameters - */ - addViewPortInstruction(name, strategy, moduleId, component) { - const lifecycleArgs = this.lifecycleArgs; - const config = Object.assign({}, lifecycleArgs[1], { currentViewPort: name }); - const viewportInstruction = this.viewPortInstructions[name] = { - name: name, - strategy: strategy, - moduleId: moduleId, - component: component, - childRouter: component.childRouter, - lifecycleArgs: [].concat(lifecycleArgs[0], config, lifecycleArgs[2]) - }; - return viewportInstruction; - } - /** - * Gets the name of the route pattern's wildcard parameter, if applicable. - */ - getWildCardName() { - // todo: potential issue, or at least unsafe typings - let configRoute = this.config.route; - let wildcardIndex = configRoute.lastIndexOf('*'); - return configRoute.substr(wildcardIndex + 1); + * Registers a viewPort to be used as a rendering target for activated routes. + * + * @param viewPort The viewPort. + * @param name The name of the viewPort. 'default' if unspecified. + */ + registerViewPort(viewPort, name) { + name = name || 'default'; + this.viewPorts[name] = viewPort; } /** - * Gets the path and query string created by filling the route - * pattern's wildcard parameter with the matching param. - */ - getWildcardPath() { - let wildcardName = this.getWildCardName(); - let path = this.params[wildcardName] || ''; - let queryString = this.queryString; - if (queryString) { - path += '?' + queryString; - } - return path; + * Returns a Promise that resolves when the router is configured. + */ + ensureConfigured() { + return this._configuredPromise; } /** - * Gets the instruction's base URL, accounting for wildcard route parameters. - */ - getBaseUrl() { - let $encodeURI = encodeURI; - let fragment = decodeURI(this.fragment); - if (fragment === '') { - let nonEmptyRoute = this.router.routes.find(route => { - return route.name === this.config.name && - route.route !== ''; - }); - if (nonEmptyRoute) { - fragment = nonEmptyRoute.route; - } - } - if (!this.params) { - return $encodeURI(fragment); - } - let wildcardName = this.getWildCardName(); - let path = this.params[wildcardName] || ''; - if (!path) { - return $encodeURI(fragment); - } - return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path))); - } - /**@internal */ - _commitChanges(waitToSwap) { - let router = this.router; - router.currentInstruction = this; - const previousInstruction = this.previousInstruction; - if (previousInstruction) { - previousInstruction.config.navModel.isActive = false; - } - this.config.navModel.isActive = true; - router.refreshNavigation(); - let loads = []; - let delaySwaps = []; - let viewPortInstructions = this.viewPortInstructions; - for (let viewPortName in viewPortInstructions) { - let viewPortInstruction = viewPortInstructions[viewPortName]; - let viewPort = router.viewPorts[viewPortName]; - if (!viewPort) { - throw new Error(`There was no router-view found in the view for ${viewPortInstruction.moduleId}.`); - } - let child_nav_instruction = viewPortInstruction.childNavigationInstruction; - if (viewPortInstruction.strategy === activationStrategy.replace) { - if (child_nav_instruction && child_nav_instruction.parentCatchHandler) { - loads.push(child_nav_instruction._commitChanges(waitToSwap)); - } - else { - if (waitToSwap) { - delaySwaps.push({ viewPort, viewPortInstruction }); - } - loads.push(viewPort - .process(viewPortInstruction, waitToSwap) - .then(() => child_nav_instruction - ? child_nav_instruction._commitChanges(waitToSwap) - : Promise.resolve())); - } - } - else { - if (child_nav_instruction) { - loads.push(child_nav_instruction._commitChanges(waitToSwap)); - } - } + * Configures the router. + * + * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]]. + */ + configure(callbackOrConfig) { + this.isConfigured = true; + let result = callbackOrConfig; + let config; + if (typeof callbackOrConfig === 'function') { + config = new RouterConfiguration(); + result = callbackOrConfig(config); } return Promise - .all(loads) - .then(() => { - delaySwaps.forEach(x => x.viewPort.swap(x.viewPortInstruction)); - return null; - }) - .then(() => prune(this)); - } - /**@internal */ - _updateTitle() { - let router = this.router; - let title = this._buildTitle(router.titleSeparator); - if (title) { - router.history.setTitle(title); - } - } - /**@internal */ - _buildTitle(separator = ' | ') { - let title = ''; - let childTitles = []; - let navModelTitle = this.config.navModel.title; - let instructionRouter = this.router; - let viewPortInstructions = this.viewPortInstructions; - if (navModelTitle) { - title = instructionRouter.transformTitle(navModelTitle); - } - for (let viewPortName in viewPortInstructions) { - let viewPortInstruction = viewPortInstructions[viewPortName]; - let child_nav_instruction = viewPortInstruction.childNavigationInstruction; - if (child_nav_instruction) { - let childTitle = child_nav_instruction._buildTitle(separator); - if (childTitle) { - childTitles.push(childTitle); - } + .resolve(result) + .then((c) => { + if (c && c.exportToRouter) { + config = c; } - } - if (childTitles.length) { - title = childTitles.join(separator) + (title ? separator : '') + title; - } - if (instructionRouter.title) { - title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title); - } - return title; - } -} -const prune = (instruction) => { - instruction.previousInstruction = null; - instruction.plan = null; -}; - -/** -* Class for storing and interacting with a route's navigation settings. -*/ -class NavModel { - constructor(router, relativeHref) { - /** - * True if this nav item is currently active. - */ - this.isActive = false; - /** - * The title. - */ - this.title = null; - /** - * This nav item's absolute href. - */ - this.href = null; - /** - * This nav item's relative href. - */ - this.relativeHref = null; - /** - * Data attached to the route at configuration time. - */ - this.settings = {}; - /** - * The route config. - */ - this.config = null; - this.router = router; - this.relativeHref = relativeHref; + config.exportToRouter(this); + this.isConfigured = true; + this._resolveConfiguredPromise(); + }); } /** - * Sets the route's title and updates document.title. - * If the a navigation is in progress, the change will be applied - * to document.title when the navigation completes. - * - * @param title The new title. - */ - setTitle(title) { - this.title = title; - if (this.isActive) { - this.router.updateTitle(); - } - } -} - -function _normalizeAbsolutePath(path, hasPushState, absolute = false) { - if (!hasPushState && path[0] !== '#') { - path = '#' + path; - } - if (hasPushState && absolute) { - path = path.substring(1, path.length); - } - return path; -} -function _createRootedPath(fragment, baseUrl, hasPushState, absolute) { - if (isAbsoluteUrl.test(fragment)) { - return fragment; - } - let path = ''; - if (baseUrl.length && baseUrl[0] !== '/') { - path += '/'; - } - path += baseUrl; - if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') { - path += '/'; - } - if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') { - path = path.substring(0, path.length - 1); - } - return _normalizeAbsolutePath(path + fragment, hasPushState, absolute); -} -function _resolveUrl(fragment, baseUrl, hasPushState) { - if (isRootedPath.test(fragment)) { - return _normalizeAbsolutePath(fragment, hasPushState); - } - return _createRootedPath(fragment, baseUrl, hasPushState); -} -function _ensureArrayWithSingleRoutePerConfig(config) { - let routeConfigs = []; - if (Array.isArray(config.route)) { - for (let i = 0, ii = config.route.length; i < ii; ++i) { - let current = Object.assign({}, config); - current.route = config.route[i]; - routeConfigs.push(current); + * Navigates to a new location. + * + * @param fragment The URL fragment to use as the navigation destination. + * @param options The navigation options. + */ + navigate(fragment, options) { + if (!this.isConfigured && this.parent) { + return this.parent.navigate(fragment, options); } + this.isExplicitNavigation = true; + return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options); } - else { - routeConfigs.push(Object.assign({}, config)); - } - return routeConfigs; -} -const isRootedPath = /^#?\//; -const isAbsoluteUrl = /^([a-z][a-z0-9+\-.]*:)?\/\//i; - -/** - * Class used to configure a [[Router]] instance. - * - * @constructor - */ -class RouterConfiguration { - constructor() { - this.instructions = []; - this.options = {}; - this.pipelineSteps = []; + /** + * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed + * by [[Router.navigate]]. + * + * @param route The name of the route to use when generating the navigation location. + * @param params The route parameters to be used when populating the route pattern. + * @param options The navigation options. + */ + navigateToRoute(route, params, options) { + let path = this.generate(route, params); + return this.navigate(path, options); } /** - * Adds a step to be run during the [[Router]]'s navigation pipeline. - * - * @param name The name of the pipeline slot to insert the step into. - * @param step The pipeline step. - * @chainable - */ - addPipelineStep(name, step) { - if (step === null || step === undefined) { - throw new Error('Pipeline step cannot be null or undefined.'); - } - this.pipelineSteps.push({ name, step }); - return this; + * Navigates back to the most recent location in history. + */ + navigateBack() { + this.isExplicitNavigationBack = true; + this.history.navigateBack(); } /** - * Adds a step to be run during the [[Router]]'s authorize pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - addAuthorizeStep(step) { - return this.addPipelineStep("authorize" /* Authorize */, step); + * Creates a child router of the current router. + * + * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified. + * @returns {Router} The new child Router. + */ + createChild(container) { + let childRouter = new Router(container || this.container.createChild(), this.history); + childRouter.parent = this; + return childRouter; } /** - * Adds a step to be run during the [[Router]]'s preActivate pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - addPreActivateStep(step) { - return this.addPipelineStep("preActivate" /* PreActivate */, step); + * Generates a URL fragment matching the specified route pattern. + * + * @param name The name of the route whose pattern should be used to generate the fragment. + * @param params The route params to be used to populate the route pattern. + * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url. + * @returns {string} A string containing the generated URL fragment. + */ + generate(nameOrRoute, params = {}, options = {}) { + // A child recognizer generates routes for potential child routes. Any potential child route is added + // to the childRoute property of params for the childRouter to recognize. When generating routes, we + // use the childRecognizer when childRoute params are available to generate a child router enabled route. + let recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer; + let hasRoute = recognizer.hasRoute(nameOrRoute); + if (!hasRoute) { + if (this.parent) { + return this.parent.generate(nameOrRoute, params, options); + } + throw new Error(`A route with name '${nameOrRoute}' could not be found. Check that \`name: '${nameOrRoute}'\` was specified in the route's config.`); + } + let path = recognizer.generate(nameOrRoute, params); + let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute); + return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath; } /** - * Adds a step to be run during the [[Router]]'s preRender pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - addPreRenderStep(step) { - return this.addPipelineStep("preRender" /* PreRender */, step); + * Creates a [[NavModel]] for the specified route config. + * + * @param config The route config. + */ + createNavModel(config) { + let navModel = new NavModel(this, 'href' in config + ? config.href + // potential error when config.route is a string[] ? + : config.route); + navModel.title = config.title; + navModel.order = config.nav; + navModel.href = config.href; + navModel.settings = config.settings; + navModel.config = config; + return navModel; } /** - * Adds a step to be run during the [[Router]]'s postRender pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - addPostRenderStep(step) { - return this.addPipelineStep("postRender" /* PostRender */, step); + * Registers a new route with the router. + * + * @param config The [[RouteConfig]]. + * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes. + */ + addRoute(config, navModel) { + if (Array.isArray(config.route)) { + let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); + // the following is wrong. todo: fix this after TS refactoring release + routeConfigs.forEach(this.addRoute.bind(this)); + return; + } + validateRouteConfig(config); + if (!('viewPorts' in config) && !config.navigationStrategy) { + config.viewPorts = { + 'default': { + moduleId: config.moduleId, + view: config.view + } + }; + } + if (!navModel) { + navModel = this.createNavModel(config); + } + this.routes.push(config); + let path = config.route; + if (path.charAt(0) === '/') { + path = path.substr(1); + } + let caseSensitive = config.caseSensitive === true; + let state = this._recognizer.add({ + path: path, + handler: config, + caseSensitive: caseSensitive + }); + if (path) { + let settings = config.settings; + delete config.settings; + let withChild = JSON.parse(JSON.stringify(config)); + config.settings = settings; + withChild.route = `${path}/*childRoute`; + withChild.hasChildRouter = true; + this._childRecognizer.add({ + path: withChild.route, + handler: withChild, + caseSensitive: caseSensitive + }); + withChild.navModel = navModel; + withChild.settings = config.settings; + withChild.navigationStrategy = config.navigationStrategy; + } + config.navModel = navModel; + let navigation = this.navigation; + if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) { + if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) { + throw new Error('Invalid route config for "' + config.route + '" : dynamic routes must specify an "href:" to be included in the navigation model.'); + } + if (typeof navModel.order !== 'number') { + navModel.order = ++this._fallbackOrder; + } + navigation.push(navModel); + // this is a potential error / inconsistency between browsers + // + // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort + // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, + // but sorted with respect to all different elements. + // Note: the ECMAscript standard does not guarantee this behaviour, + // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this. + navigation.sort((a, b) => a.order - b.order); + } } /** - * Configures a route that will be used if there is no previous location available on navigation cancellation. - * - * @param fragment The URL fragment to use as the navigation destination. - * @chainable - */ - fallbackRoute(fragment) { - this._fallbackRoute = fragment; - return this; + * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name. + * + * @param name The name of the route to check. + */ + hasRoute(name) { + return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name)); } /** - * Maps one or more routes to be registered with the router. - * - * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map. - * @chainable - */ - map(route) { - if (Array.isArray(route)) { - route.forEach(this.map.bind(this)); - return this; - } - return this.mapRoute(route); + * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name. + * + * @param name The name of the route to check. + */ + hasOwnRoute(name) { + return this._recognizer.hasRoute(name); } /** - * Configures defaults to use for any view ports. + * Register a handler to use when the incoming URL fragment doesn't match any registered routes. * - * @param viewPortConfig a view port configuration object to use as a - * default, of the form { viewPortName: { moduleId } }. - * @chainable + * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]]. */ - useViewPortDefaults(viewPortConfig) { - this.viewPortDefaults = viewPortConfig; - return this; + handleUnknownRoutes(config) { + if (!config) { + throw new Error('Invalid unknown route handler'); + } + this.catchAllHandler = instruction => { + return this + ._createRouteConfig(config, instruction) + .then(c => { + instruction.config = c; + return instruction; + }); + }; } /** - * Maps a single route to be registered with the router. - * - * @param route The [[RouteConfig]] to map. - * @chainable - */ - mapRoute(config) { - this.instructions.push(router => { - let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); - let navModel; - for (let i = 0, ii = routeConfigs.length; i < ii; ++i) { - let routeConfig = routeConfigs[i]; - routeConfig.settings = routeConfig.settings || {}; - if (!navModel) { - navModel = router.createNavModel(routeConfig); - } - router.addRoute(routeConfig, navModel); - } - }); - return this; + * Updates the document title using the current navigation instruction. + */ + updateTitle() { + let parentRouter = this.parent; + if (parentRouter) { + return parentRouter.updateTitle(); + } + let currentInstruction = this.currentInstruction; + if (currentInstruction) { + currentInstruction._updateTitle(); + } + return undefined; } /** - * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes. - * - * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the - * [[NavigationInstruction]] and selects a moduleId to load. - * @chainable - */ - mapUnknownRoutes(config) { - this.unknownRouteConfig = config; - return this; + * Updates the navigation routes with hrefs relative to the current location. + * Note: This method will likely move to a plugin in a future release. + */ + refreshNavigation() { + let nav = this.navigation; + for (let i = 0, length = nav.length; i < length; i++) { + let current = nav[i]; + if (!current.config.href) { + current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState); + } + else { + current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState); + } + } } /** - * Applies the current configuration to the specified [[Router]]. - * - * @param router The [[Router]] to apply the configuration to. - */ - exportToRouter(router) { - let instructions = this.instructions; - for (let i = 0, ii = instructions.length; i < ii; ++i) { - instructions[i](router); + * Sets the default configuration for the view ports. This specifies how to + * populate a view port for which no module is specified. The default is + * an empty view/view-model pair. + */ + useViewPortDefaults($viewPortDefaults) { + // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction + let viewPortDefaults = $viewPortDefaults; + for (let viewPortName in viewPortDefaults) { + let viewPortConfig = viewPortDefaults[viewPortName]; + this.viewPortDefaults[viewPortName] = { + moduleId: viewPortConfig.moduleId + }; } - if (this.title) { - router.title = this.title; + } + /**@internal */ + _refreshBaseUrl() { + let parentRouter = this.parent; + if (parentRouter) { + this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction); } - if (this.titleSeparator) { - router.titleSeparator = this.titleSeparator; + } + /**@internal */ + _createNavigationInstruction(url = '', parentInstruction = null) { + let fragment = url; + let queryString = ''; + let queryIndex = url.indexOf('?'); + if (queryIndex !== -1) { + fragment = url.substr(0, queryIndex); + queryString = url.substr(queryIndex + 1); } - if (this.unknownRouteConfig) { - router.handleUnknownRoutes(this.unknownRouteConfig); + let urlRecognizationResults = this._recognizer.recognize(url); + if (!urlRecognizationResults || !urlRecognizationResults.length) { + urlRecognizationResults = this._childRecognizer.recognize(url); } - if (this._fallbackRoute) { - router.fallbackRoute = this._fallbackRoute; + let instructionInit = { + fragment, + queryString, + config: null, + parentInstruction, + previousInstruction: this.currentInstruction, + router: this, + options: { + compareQueryParams: this.options.compareQueryParams + } + }; + let result; + if (urlRecognizationResults && urlRecognizationResults.length) { + let first = urlRecognizationResults[0]; + let instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: first.params, + queryParams: first.queryParams || urlRecognizationResults.queryParams, + config: first.config || first.handler + })); + if (typeof first.handler === 'function') { + result = evaluateNavigationStrategy(instruction, first.handler, first); + } + else if (first.handler && typeof first.handler.navigationStrategy === 'function') { + result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); + } + else { + result = Promise.resolve(instruction); + } } - if (this.viewPortDefaults) { - router.useViewPortDefaults(this.viewPortDefaults); + else if (this.catchAllHandler) { + let instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: { path: fragment }, + queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, + config: null // config will be created by the catchAllHandler + })); + result = evaluateNavigationStrategy(instruction, this.catchAllHandler); } - Object.assign(router.options, this.options); - let pipelineSteps = this.pipelineSteps; - if (pipelineSteps.length) { - if (!router.isRoot) { - throw new Error('Pipeline steps can only be added to the root router'); - } - let pipelineProvider = router.pipelineProvider; - for (let i = 0, ii = pipelineSteps.length; i < ii; ++i) { - let { name, step } = pipelineSteps[i]; - pipelineProvider.addStep(name, step); + else if (this.parent) { + let router = this._parentCatchAllHandler(this.parent); + if (router) { + let newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction); + let instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: { path: fragment }, + queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, + router: router, + parentInstruction: newParentInstruction, + parentCatchHandler: true, + config: null // config will be created by the chained parent catchAllHandler + })); + result = evaluateNavigationStrategy(instruction, router.catchAllHandler); } } + if (result && parentInstruction) { + this.baseUrl = generateBaseUrl(this.parent, parentInstruction); + } + return result || Promise.reject(new Error(`Route not found: ${url}`)); } -} - -/** - * The primary class responsible for handling routing and navigation. - */ -class Router { - /** - * @param container The [[Container]] to use when child routers. - * @param history The [[History]] implementation to delegate navigation requests to. - */ - constructor(container, history) { - /** - * The parent router, or null if this instance is not a child router. - */ - this.parent = null; - this.options = {}; - /** - * The defaults used when a viewport lacks specified content - */ - this.viewPortDefaults = {}; - /** - * Extension point to transform the document title before it is built and displayed. - * By default, child routers delegate to the parent router, and the app router - * returns the title unchanged. - */ - this.transformTitle = (title) => { - if (this.parent) { - return this.parent.transformTitle(title); - } - return title; - }; - this.container = container; - this.history = history; - this.reset(); + /**@internal */ + _findParentInstructionFromRouter(router, instruction) { + if (instruction.router === router) { + instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId + return instruction; + } + else if (instruction.parentInstruction) { + return this._findParentInstructionFromRouter(router, instruction.parentInstruction); + } + return undefined; + } + /**@internal */ + _parentCatchAllHandler(router) { + if (router.catchAllHandler) { + return router; + } + else if (router.parent) { + return this._parentCatchAllHandler(router.parent); + } + return false; } /** - * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. - * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. - */ - reset() { - this.viewPorts = {}; - this.routes = []; - this.baseUrl = ''; - this.isConfigured = false; - this.isNavigating = false; - this.isExplicitNavigation = false; - this.isExplicitNavigationBack = false; - this.isNavigatingFirst = false; - this.isNavigatingNew = false; - this.isNavigatingRefresh = false; - this.isNavigatingForward = false; - this.isNavigatingBack = false; - this.couldDeactivate = false; - this.navigation = []; - this.currentInstruction = null; - this.viewPortDefaults = {}; - this._fallbackOrder = 100; - this._recognizer = new RouteRecognizer(); - this._childRecognizer = new RouteRecognizer(); - this._configuredPromise = new Promise(resolve => { - this._resolveConfiguredPromise = resolve; + * @internal + */ + _createRouteConfig(config, instruction) { + return Promise + .resolve(config) + .then((c) => { + if (typeof c === 'string') { + return { moduleId: c }; + } + else if (typeof c === 'function') { + return c(instruction); + } + return c; + }) + // typing here could be either RouteConfig or RedirectConfig + // but temporarily treat both as RouteConfig + // todo: improve typings precision + .then((c) => typeof c === 'string' ? { moduleId: c } : c) + .then((c) => { + c.route = instruction.params.path; + validateRouteConfig(c); + if (!c.navModel) { + c.navModel = this.createNavModel(c); + } + return c; }); } - /** - * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent. - */ - get isRoot() { - return !this.parent; +} +/* @internal exported for unit testing */ +const generateBaseUrl = (router, instruction) => { + return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`; +}; +/* @internal exported for unit testing */ +const validateRouteConfig = (config) => { + if (typeof config !== 'object') { + throw new Error('Invalid Route Config'); } - /** - * Registers a viewPort to be used as a rendering target for activated routes. - * - * @param viewPort The viewPort. - * @param name The name of the viewPort. 'default' if unspecified. - */ - registerViewPort(viewPort, name) { - name = name || 'default'; - this.viewPorts[name] = viewPort; + if (typeof config.route !== 'string') { + let name = config.name || '(no name)'; + throw new Error('Invalid Route Config for "' + name + '": You must specify a "route:" pattern.'); } - /** - * Returns a Promise that resolves when the router is configured. - */ - ensureConfigured() { - return this._configuredPromise; + if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) { + throw new Error('Invalid Route Config for "' + config.route + '": You must specify a "moduleId:", "redirect:", "navigationStrategy:", or "viewPorts:".'); + } +}; +/* @internal exported for unit testing */ +const evaluateNavigationStrategy = (instruction, evaluator, context) => { + return Promise + .resolve(evaluator.call(context, instruction)) + .then(() => { + if (!('viewPorts' in instruction.config)) { + instruction.config.viewPorts = { + 'default': { + moduleId: instruction.config.moduleId + } + }; + } + return instruction; + }); +}; + +/**@internal exported for unit testing */ +const createNextFn = (instruction, steps) => { + let index = -1; + const next = function () { + index++; + if (index < steps.length) { + let currentStep = steps[index]; + try { + return currentStep(instruction, next); + } + catch (e) { + return next.reject(e); + } + } + else { + return next.complete(); + } + }; + next.complete = createCompletionHandler(next, "completed" /* Completed */); + next.cancel = createCompletionHandler(next, "canceled" /* Canceled */); + next.reject = createCompletionHandler(next, "rejected" /* Rejected */); + return next; +}; +/**@internal exported for unit testing */ +const createCompletionHandler = (next, status) => { + return (output) => Promise + .resolve({ + status, + output, + completed: status === "completed" /* Completed */ + }); +}; + +/** + * The class responsible for managing and processing the navigation pipeline. + */ +class Pipeline { + constructor() { + /** + * The pipeline steps. And steps added via addStep will be converted to a function + * The actualy running functions with correct step contexts of this pipeline + */ + this.steps = []; } /** - * Configures the router. - * - * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]]. - */ - configure(callbackOrConfig) { - this.isConfigured = true; - let result = callbackOrConfig; - let config; - if (typeof callbackOrConfig === 'function') { - config = new RouterConfiguration(); - result = callbackOrConfig(config); + * Adds a step to the pipeline. + * + * @param step The pipeline step. + */ + addStep(step) { + let run; + if (typeof step === 'function') { + run = step; } - return Promise - .resolve(result) - .then((c) => { - if (c && c.exportToRouter) { - config = c; + else if (typeof step.getSteps === 'function') { + // getSteps is to enable support open slots + // where devs can add multiple steps into the same slot name + let steps = step.getSteps(); + for (let i = 0, l = steps.length; i < l; i++) { + this.addStep(steps[i]); } - config.exportToRouter(this); - this.isConfigured = true; - this._resolveConfiguredPromise(); - }); + return this; + } + else { + run = step.run.bind(step); + } + this.steps.push(run); + return this; } /** - * Navigates to a new location. - * - * @param fragment The URL fragment to use as the navigation destination. - * @param options The navigation options. - */ - navigate(fragment, options) { - if (!this.isConfigured && this.parent) { - return this.parent.navigate(fragment, options); - } - this.isExplicitNavigation = true; - return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options); + * Runs the pipeline. + * + * @param instruction The navigation instruction to process. + */ + run(instruction) { + const nextFn = createNextFn(instruction, this.steps); + return nextFn(); } +} + +/** +* Determines if the provided object is a navigation command. +* A navigation command is anything with a navigate method. +* +* @param obj The object to check. +*/ +function isNavigationCommand(obj) { + return obj && typeof obj.navigate === 'function'; +} +/** +* Used during the activation lifecycle to cause a redirect. +*/ +class Redirect { /** - * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed - * by [[Router.navigate]]. - * - * @param route The name of the route to use when generating the navigation location. - * @param params The route parameters to be used when populating the route pattern. - * @param options The navigation options. - */ - navigateToRoute(route, params, options) { - let path = this.generate(route, params); - return this.navigate(path, options); + * @param url The URL fragment to use as the navigation destination. + * @param options The navigation options. + */ + constructor(url, options = {}) { + this.url = url; + this.options = Object.assign({ trigger: true, replace: true }, options); + this.shouldContinueProcessing = false; } /** - * Navigates back to the most recent location in history. - */ - navigateBack() { - this.isExplicitNavigationBack = true; - this.history.navigateBack(); + * Called by the activation system to set the child router. + * + * @param router The router. + */ + setRouter(router) { + this.router = router; } /** - * Creates a child router of the current router. + * Called by the navigation pipeline to navigate. * - * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified. - * @returns {Router} The new child Router. + * @param appRouter The router to be redirected. */ - createChild(container) { - let childRouter = new Router(container || this.container.createChild(), this.history); - childRouter.parent = this; - return childRouter; + navigate(appRouter) { + let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); + navigatingRouter.navigate(this.url, this.options); } +} +/** + * Used during the activation lifecycle to cause a redirect to a named route. + */ +class RedirectToRoute { /** - * Generates a URL fragment matching the specified route pattern. - * - * @param name The name of the route whose pattern should be used to generate the fragment. - * @param params The route params to be used to populate the route pattern. - * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url. - * @returns {string} A string containing the generated URL fragment. - */ - generate(nameOrRoute, params = {}, options = {}) { - // A child recognizer generates routes for potential child routes. Any potential child route is added - // to the childRoute property of params for the childRouter to recognize. When generating routes, we - // use the childRecognizer when childRoute params are available to generate a child router enabled route. - let recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer; - let hasRoute = recognizer.hasRoute(nameOrRoute); - if (!hasRoute) { - if (this.parent) { - return this.parent.generate(nameOrRoute, params, options); - } - throw new Error(`A route with name '${nameOrRoute}' could not be found. Check that \`name: '${nameOrRoute}'\` was specified in the route's config.`); - } - let path = recognizer.generate(nameOrRoute, params); - let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute); - return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath; + * @param route The name of the route. + * @param params The parameters to be sent to the activation method. + * @param options The options to use for navigation. + */ + constructor(route, params = {}, options = {}) { + this.route = route; + this.params = params; + this.options = Object.assign({ trigger: true, replace: true }, options); + this.shouldContinueProcessing = false; } /** - * Creates a [[NavModel]] for the specified route config. - * - * @param config The route config. - */ - createNavModel(config) { - let navModel = new NavModel(this, 'href' in config - ? config.href - // potential error when config.route is a string[] ? - : config.route); - navModel.title = config.title; - navModel.order = config.nav; - navModel.href = config.href; - navModel.settings = config.settings; - navModel.config = config; - return navModel; + * Called by the activation system to set the child router. + * + * @param router The router. + */ + setRouter(router) { + this.router = router; } /** - * Registers a new route with the router. - * - * @param config The [[RouteConfig]]. - * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes. - */ - addRoute(config, navModel) { - if (Array.isArray(config.route)) { - let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); - // the following is wrong. todo: fix this after TS refactoring release - routeConfigs.forEach(this.addRoute.bind(this)); - return; - } - validateRouteConfig(config); - if (!('viewPorts' in config) && !config.navigationStrategy) { - config.viewPorts = { - 'default': { - moduleId: config.moduleId, - view: config.view + * Called by the navigation pipeline to navigate. + * + * @param appRouter The router to be redirected. + */ + navigate(appRouter) { + let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); + navigatingRouter.navigateToRoute(this.route, this.params, this.options); + } +} + +/** + * @internal exported for unit testing + */ +function _buildNavigationPlan(instruction, forceLifecycleMinimum) { + let config = instruction.config; + if ('redirect' in config) { + return buildRedirectPlan(instruction); + } + const prevInstruction = instruction.previousInstruction; + const defaultViewPortConfigs = instruction.router.viewPortDefaults; + if (prevInstruction) { + return buildTransitionPlans(instruction, prevInstruction, defaultViewPortConfigs, forceLifecycleMinimum); + } + // first navigation, only need to prepare a few information for each viewport plan + const viewPortPlans = {}; + let viewPortConfigs = config.viewPorts; + for (let viewPortName in viewPortConfigs) { + let viewPortConfig = viewPortConfigs[viewPortName]; + if (viewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) { + viewPortConfig = defaultViewPortConfigs[viewPortName]; + } + viewPortPlans[viewPortName] = { + name: viewPortName, + strategy: "replace" /* Replace */, + config: viewPortConfig + }; + } + return Promise.resolve(viewPortPlans); +} +/** + * Build redirect plan based on config of a navigation instruction + * @internal exported for unit testing + */ +const buildRedirectPlan = (instruction) => { + const config = instruction.config; + const router = instruction.router; + return router + ._createNavigationInstruction(config.redirect) + .then(redirectInstruction => { + const params = {}; + const originalInstructionParams = instruction.params; + const redirectInstructionParams = redirectInstruction.params; + for (let key in redirectInstructionParams) { + // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this } + let val = redirectInstructionParams[key]; + if (typeof val === 'string' && val[0] === ':') { + val = val.slice(1); + // And if that param is found on the original instruction then use it + if (val in originalInstructionParams) { + params[key] = originalInstructionParams[val]; } - }; - } - if (!navModel) { - navModel = this.createNavModel(config); + } + else { + params[key] = redirectInstructionParams[key]; + } } - this.routes.push(config); - let path = config.route; - if (path.charAt(0) === '/') { - path = path.substr(1); + let redirectLocation = router.generate(redirectInstruction.config, params, instruction.options); + // Special handling for child routes + for (let key in originalInstructionParams) { + redirectLocation = redirectLocation.replace(`:${key}`, originalInstructionParams[key]); } - let caseSensitive = config.caseSensitive === true; - let state = this._recognizer.add({ - path: path, - handler: config, - caseSensitive: caseSensitive - }); - if (path) { - let settings = config.settings; - delete config.settings; - let withChild = JSON.parse(JSON.stringify(config)); - config.settings = settings; - withChild.route = `${path}/*childRoute`; - withChild.hasChildRouter = true; - this._childRecognizer.add({ - path: withChild.route, - handler: withChild, - caseSensitive: caseSensitive - }); - withChild.navModel = navModel; - withChild.settings = config.settings; - withChild.navigationStrategy = config.navigationStrategy; + let queryString = instruction.queryString; + if (queryString) { + redirectLocation += '?' + queryString; } - config.navModel = navModel; - let navigation = this.navigation; - if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) { - if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) { - throw new Error('Invalid route config for "' + config.route + '" : dynamic routes must specify an "href:" to be included in the navigation model.'); - } - if (typeof navModel.order !== 'number') { - navModel.order = ++this._fallbackOrder; - } - navigation.push(navModel); - // this is a potential error / inconsistency between browsers - // - // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort - // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, - // but sorted with respect to all different elements. - // Note: the ECMAscript standard does not guarantee this behaviour, - // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this. - navigation.sort((a, b) => a.order - b.order); + return Promise.resolve(new Redirect(redirectLocation)); + }); +}; +/** + * @param viewPortPlans the Plan record that holds information about built plans + * @internal exported for unit testing + */ +const buildTransitionPlans = (currentInstruction, previousInstruction, defaultViewPortConfigs, forceLifecycleMinimum) => { + let viewPortPlans = {}; + let newInstructionConfig = currentInstruction.config; + let hasNewParams = hasDifferentParameterValues(previousInstruction, currentInstruction); + let pending = []; + let previousViewPortInstructions = previousInstruction.viewPortInstructions; + for (let viewPortName in previousViewPortInstructions) { + const prevViewPortInstruction = previousViewPortInstructions[viewPortName]; + const prevViewPortComponent = prevViewPortInstruction.component; + const newInstructionViewPortConfigs = newInstructionConfig.viewPorts; + // if this is invoked on a viewport without any changes, based on new url, + // newViewPortConfig will be the existing viewport instruction + let nextViewPortConfig = viewPortName in newInstructionViewPortConfigs + ? newInstructionViewPortConfigs[viewPortName] + : prevViewPortInstruction; + if (nextViewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) { + nextViewPortConfig = defaultViewPortConfigs[viewPortName]; + } + const viewPortActivationStrategy = determineActivationStrategy(currentInstruction, prevViewPortInstruction, nextViewPortConfig, hasNewParams, forceLifecycleMinimum); + const viewPortPlan = viewPortPlans[viewPortName] = { + name: viewPortName, + // ViewPortInstruction can quack like a RouteConfig + config: nextViewPortConfig, + prevComponent: prevViewPortComponent, + prevModuleId: prevViewPortInstruction.moduleId, + strategy: viewPortActivationStrategy + }; + // recursively build nav plans for all existing child routers/viewports of this viewport + // this is possible because existing child viewports and routers already have necessary information + // to process the wildcard path from parent instruction + if (viewPortActivationStrategy !== "replace" /* Replace */ && prevViewPortInstruction.childRouter) { + const path = currentInstruction.getWildcardPath(); + const task = prevViewPortInstruction + .childRouter + ._createNavigationInstruction(path, currentInstruction) + .then((childInstruction) => { + viewPortPlan.childNavigationInstruction = childInstruction; + return _buildNavigationPlan(childInstruction, + // is it safe to assume viewPortPlan has not been changed from previous assignment? + // if so, can just use local variable viewPortPlanStrategy + // there could be user code modifying viewport plan during _createNavigationInstruction? + viewPortPlan.strategy === "invoke-lifecycle" /* InvokeLifecycle */) + .then(childPlan => { + if (childPlan instanceof Redirect) { + return Promise.reject(childPlan); + } + childInstruction.plan = childPlan; + // for bluebird ? + return null; + }); + }); + pending.push(task); } } - /** - * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name. - * - * @param name The name of the route to check. - */ - hasRoute(name) { - return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name)); + return Promise.all(pending).then(() => viewPortPlans); +}; +/** + * @param newViewPortConfig if this is invoked on a viewport without any changes, based on new url, newViewPortConfig will be the existing viewport instruction + * @internal exported for unit testing + */ +const determineActivationStrategy = (currentNavInstruction, prevViewPortInstruction, newViewPortConfig, +// indicates whether there is difference between old and new url params +hasNewParams, forceLifecycleMinimum) => { + let newInstructionConfig = currentNavInstruction.config; + let prevViewPortViewModel = prevViewPortInstruction.component.viewModel; + let viewPortPlanStrategy; + if (prevViewPortInstruction.moduleId !== newViewPortConfig.moduleId) { + viewPortPlanStrategy = "replace" /* Replace */; } - /** - * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name. - * - * @param name The name of the route to check. - */ - hasOwnRoute(name) { - return this._recognizer.hasRoute(name); + else if ('determineActivationStrategy' in prevViewPortViewModel) { + viewPortPlanStrategy = prevViewPortViewModel.determineActivationStrategy(...currentNavInstruction.lifecycleArgs); } - /** - * Register a handler to use when the incoming URL fragment doesn't match any registered routes. - * - * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]]. - */ - handleUnknownRoutes(config) { - if (!config) { - throw new Error('Invalid unknown route handler'); + else if (newInstructionConfig.activationStrategy) { + viewPortPlanStrategy = newInstructionConfig.activationStrategy; + } + else if (hasNewParams || forceLifecycleMinimum) { + viewPortPlanStrategy = "invoke-lifecycle" /* InvokeLifecycle */; + } + else { + viewPortPlanStrategy = "no-change" /* NoChange */; + } + return viewPortPlanStrategy; +}; +/**@internal exported for unit testing */ +const hasDifferentParameterValues = (prev, next) => { + let prevParams = prev.params; + let nextParams = next.params; + let nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; + for (let key in nextParams) { + if (key === nextWildCardName) { + continue; + } + if (prevParams[key] !== nextParams[key]) { + return true; } - this.catchAllHandler = instruction => { - return this - ._createRouteConfig(config, instruction) - .then(c => { - instruction.config = c; - return instruction; - }); - }; } - /** - * Updates the document title using the current navigation instruction. - */ - updateTitle() { - let parentRouter = this.parent; - if (parentRouter) { - return parentRouter.updateTitle(); + for (let key in prevParams) { + if (key === nextWildCardName) { + continue; } - let currentInstruction = this.currentInstruction; - if (currentInstruction) { - currentInstruction._updateTitle(); + if (prevParams[key] !== nextParams[key]) { + return true; } - return undefined; } - /** - * Updates the navigation routes with hrefs relative to the current location. - * Note: This method will likely move to a plugin in a future release. - */ - refreshNavigation() { - let nav = this.navigation; - for (let i = 0, length = nav.length; i < length; i++) { - let current = nav[i]; - if (!current.config.href) { - current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState); + if (!next.options.compareQueryParams) { + return false; + } + let prevQueryParams = prev.queryParams; + let nextQueryParams = next.queryParams; + for (let key in nextQueryParams) { + if (prevQueryParams[key] !== nextQueryParams[key]) { + return true; + } + } + for (let key in prevQueryParams) { + if (prevQueryParams[key] !== nextQueryParams[key]) { + return true; + } + } + return false; +}; + +/** + * Transform a navigation instruction into viewport plan record object, + * or a redirect request if user viewmodel demands + */ +class BuildNavigationPlanStep { + run(navigationInstruction, next) { + return _buildNavigationPlan(navigationInstruction) + .then(plan => { + if (plan instanceof Redirect) { + return next.cancel(plan); } - else { - current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState); + navigationInstruction.plan = plan; + return next(); + }) + .catch(next.cancel); + } +} + +/** + * @internal Exported for unit testing + */ +const loadNewRoute = (routeLoader, navigationInstruction) => { + let loadingPlans = determineLoadingPlans(navigationInstruction); + let loadPromises = loadingPlans.map((loadingPlan) => loadRoute(routeLoader, loadingPlan.navigationInstruction, loadingPlan.viewPortPlan)); + return Promise.all(loadPromises); +}; +/** + * @internal Exported for unit testing + */ +const determineLoadingPlans = (navigationInstruction, loadingPlans = []) => { + let viewPortPlans = navigationInstruction.plan; + for (let viewPortName in viewPortPlans) { + let viewPortPlan = viewPortPlans[viewPortName]; + let childNavInstruction = viewPortPlan.childNavigationInstruction; + if (viewPortPlan.strategy === "replace" /* Replace */) { + loadingPlans.push({ viewPortPlan, navigationInstruction }); + if (childNavInstruction) { + determineLoadingPlans(childNavInstruction, loadingPlans); + } + } + else { + let viewPortInstruction = navigationInstruction.addViewPortInstruction({ + name: viewPortName, + strategy: viewPortPlan.strategy, + moduleId: viewPortPlan.prevModuleId, + component: viewPortPlan.prevComponent + }); + if (childNavInstruction) { + viewPortInstruction.childNavigationInstruction = childNavInstruction; + determineLoadingPlans(childNavInstruction, loadingPlans); } } } + return loadingPlans; +}; +/** + * @internal Exported for unit testing + */ +const loadRoute = (routeLoader, navigationInstruction, viewPortPlan) => { + let planConfig = viewPortPlan.config; + let moduleId = planConfig ? planConfig.moduleId : null; + return loadComponent(routeLoader, navigationInstruction, planConfig) + .then((component) => { + let viewPortInstruction = navigationInstruction.addViewPortInstruction({ + name: viewPortPlan.name, + strategy: viewPortPlan.strategy, + moduleId: moduleId, + component: component + }); + let childRouter = component.childRouter; + if (childRouter) { + let path = navigationInstruction.getWildcardPath(); + return childRouter + ._createNavigationInstruction(path, navigationInstruction) + .then((childInstruction) => { + viewPortPlan.childNavigationInstruction = childInstruction; + return _buildNavigationPlan(childInstruction) + .then((childPlan) => { + if (childPlan instanceof Redirect) { + return Promise.reject(childPlan); + } + childInstruction.plan = childPlan; + viewPortInstruction.childNavigationInstruction = childInstruction; + return loadNewRoute(routeLoader, childInstruction); + }); + }); + } + // ts complains without this, though they are same + return void 0; + }); +}; +/** + * Load a routed-component based on navigation instruction and route config + * @internal exported for unit testing only + */ +const loadComponent = (routeLoader, navigationInstruction, config) => { + let router = navigationInstruction.router; + let lifecycleArgs = navigationInstruction.lifecycleArgs; + return Promise.resolve() + .then(() => routeLoader.loadRoute(router, config, navigationInstruction)) + .then( /** - * Sets the default configuration for the view ports. This specifies how to - * populate a view port for which no module is specified. The default is - * an empty view/view-model pair. + * @param component an object carrying information about loaded route + * typically contains information about view model, childContainer, view and router */ - useViewPortDefaults($viewPortDefaults) { - // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction - let viewPortDefaults = $viewPortDefaults; - for (let viewPortName in viewPortDefaults) { - let viewPortConfig = viewPortDefaults[viewPortName]; - this.viewPortDefaults[viewPortName] = { - moduleId: viewPortConfig.moduleId - }; + (component) => { + let { viewModel, childContainer } = component; + component.router = router; + component.config = config; + if ('configureRouter' in viewModel) { + let childRouter = childContainer.getChildRouter(); + component.childRouter = childRouter; + return childRouter + .configure(c => viewModel.configureRouter(c, childRouter, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2])) + .then(() => component); } + return component; + }); +}; + +/** + * Abstract class that is responsible for loading view / view model from a route config + * The default implementation can be found in `aurelia-templating-router` + */ +class RouteLoader { + /** + * Load a route config based on its viewmodel / view configuration + */ + // return typing: return typings used to be never + // as it was a throw. Changing it to Promise should not cause any issues + loadRoute(router, config, navigationInstruction) { + throw new Error('Route loaders must implement "loadRoute(router, config, navigationInstruction)".'); } +} + +/** + * A pipeline step responsible for loading a route config of a navigation instruction + */ +class LoadRouteStep { /**@internal */ - _refreshBaseUrl() { - let parentRouter = this.parent; - if (parentRouter) { - this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction); + static inject() { return [RouteLoader]; } + constructor(routeLoader) { + this.routeLoader = routeLoader; + } + /** + * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline + */ + run(navigationInstruction, next) { + return loadNewRoute(this.routeLoader, navigationInstruction) + .then(next, next.cancel); + } +} + +/** + * A pipeline step for instructing a piepline to commit changes on a navigation instruction + */ +class CommitChangesStep { + run(navigationInstruction, next) { + return navigationInstruction + ._commitChanges(/*wait to swap?*/ true) + .then(() => { + navigationInstruction._updateTitle(); + return next(); + }); + } +} + +/** + * An optional interface describing the available activation strategies. + * @internal Used internally. + */ +var InternalActivationStrategy; +(function (InternalActivationStrategy) { + /** + * Reuse the existing view model, without invoking Router lifecycle hooks. + */ + InternalActivationStrategy["NoChange"] = "no-change"; + /** + * Reuse the existing view model, invoking Router lifecycle hooks. + */ + InternalActivationStrategy["InvokeLifecycle"] = "invoke-lifecycle"; + /** + * Replace the existing view model, invoking Router lifecycle hooks. + */ + InternalActivationStrategy["Replace"] = "replace"; +})(InternalActivationStrategy || (InternalActivationStrategy = {})); +/** + * The strategy to use when activating modules during navigation. + */ +// kept for compat reason +const activationStrategy = { + noChange: "no-change" /* NoChange */, + invokeLifecycle: "invoke-lifecycle" /* InvokeLifecycle */, + replace: "replace" /* Replace */ +}; + +/** + * Recursively find list of deactivate-able view models + * and invoke the either 'canDeactivate' or 'deactivate' on each + * @internal exported for unit testing + */ +const processDeactivatable = (navigationInstruction, callbackName, next, ignoreResult) => { + let plan = navigationInstruction.plan; + let infos = findDeactivatable(plan, callbackName); + let i = infos.length; // query from inside out + function inspect(val) { + if (ignoreResult || shouldContinue(val)) { + return iterate(); } + return next.cancel(val); } - /**@internal */ - _createNavigationInstruction(url = '', parentInstruction = null) { - let fragment = url; - let queryString = ''; - let queryIndex = url.indexOf('?'); - if (queryIndex !== -1) { - fragment = url.substr(0, queryIndex); - queryString = url.substr(queryIndex + 1); - } - let urlRecognizationResults = this._recognizer.recognize(url); - if (!urlRecognizationResults || !urlRecognizationResults.length) { - urlRecognizationResults = this._childRecognizer.recognize(url); - } - let instructionInit = { - fragment, - queryString, - config: null, - parentInstruction, - previousInstruction: this.currentInstruction, - router: this, - options: { - compareQueryParams: this.options.compareQueryParams - } - }; - let result; - if (urlRecognizationResults && urlRecognizationResults.length) { - let first = urlRecognizationResults[0]; - let instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: first.params, - queryParams: first.queryParams || urlRecognizationResults.queryParams, - config: first.config || first.handler - })); - if (typeof first.handler === 'function') { - result = evaluateNavigationStrategy(instruction, first.handler, first); - } - else if (first.handler && typeof first.handler.navigationStrategy === 'function') { - result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); + function iterate() { + if (i--) { + try { + let viewModel = infos[i]; + let result = viewModel[callbackName](navigationInstruction); + return processPotential(result, inspect, next.cancel); } - else { - result = Promise.resolve(instruction); + catch (error) { + return next.cancel(error); } } - else if (this.catchAllHandler) { - let instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: { path: fragment }, - queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, - config: null // config will be created by the catchAllHandler - })); - result = evaluateNavigationStrategy(instruction, this.catchAllHandler); - } - else if (this.parent) { - let router = this._parentCatchAllHandler(this.parent); - if (router) { - let newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction); - let instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: { path: fragment }, - queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, - router: router, - parentInstruction: newParentInstruction, - parentCatchHandler: true, - config: null // config will be created by the chained parent catchAllHandler - })); - result = evaluateNavigationStrategy(instruction, router.catchAllHandler); + navigationInstruction.router.couldDeactivate = true; + return next(); + } + return iterate(); +}; +/** + * Recursively find and returns a list of deactivate-able view models + * @internal exported for unit testing + */ +const findDeactivatable = (plan, callbackName, list = []) => { + for (let viewPortName in plan) { + let viewPortPlan = plan[viewPortName]; + let prevComponent = viewPortPlan.prevComponent; + if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace) + && prevComponent) { + let viewModel = prevComponent.viewModel; + if (callbackName in viewModel) { + list.push(viewModel); } } - if (result && parentInstruction) { - this.baseUrl = generateBaseUrl(this.parent, parentInstruction); - } - return result || Promise.reject(new Error(`Route not found: ${url}`)); - } - /**@internal */ - _findParentInstructionFromRouter(router, instruction) { - if (instruction.router === router) { - instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId - return instruction; + if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) { + addPreviousDeactivatable(prevComponent, callbackName, list); } - else if (instruction.parentInstruction) { - return this._findParentInstructionFromRouter(router, instruction.parentInstruction); + else if (viewPortPlan.childNavigationInstruction) { + findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list); } - return undefined; } - /**@internal */ - _parentCatchAllHandler(router) { - if (router.catchAllHandler) { - return router; + return list; +}; +/** + * @internal exported for unit testing + */ +const addPreviousDeactivatable = (component, callbackName, list) => { + let childRouter = component.childRouter; + if (childRouter && childRouter.currentInstruction) { + let viewPortInstructions = childRouter.currentInstruction.viewPortInstructions; + for (let viewPortName in viewPortInstructions) { + let viewPortInstruction = viewPortInstructions[viewPortName]; + let prevComponent = viewPortInstruction.component; + let prevViewModel = prevComponent.viewModel; + if (callbackName in prevViewModel) { + list.push(prevViewModel); + } + addPreviousDeactivatable(prevComponent, callbackName, list); } - else if (router.parent) { - return this._parentCatchAllHandler(router.parent); + } +}; +/** + * @internal exported for unit testing + */ +const processActivatable = (navigationInstruction, callbackName, next, ignoreResult) => { + let infos = findActivatable(navigationInstruction, callbackName); + let length = infos.length; + let i = -1; // query from top down + function inspect(val, router) { + if (ignoreResult || shouldContinue(val, router)) { + return iterate(); } - return false; + return next.cancel(val); } - /** - * @internal - */ - _createRouteConfig(config, instruction) { - return Promise - .resolve(config) - .then((c) => { - if (typeof c === 'string') { - return { moduleId: c }; - } - else if (typeof c === 'function') { - return c(instruction); + function iterate() { + i++; + if (i < length) { + try { + let current = infos[i]; + let result = current.viewModel[callbackName](...current.lifecycleArgs); + return processPotential(result, (val) => inspect(val, current.router), next.cancel); } - return c; - }) - // typing here could be either RouteConfig or RedirectConfig - // but temporarily treat both as RouteConfig - // todo: improve typings precision - .then((c) => typeof c === 'string' ? { moduleId: c } : c) - .then((c) => { - c.route = instruction.params.path; - validateRouteConfig(c); - if (!c.navModel) { - c.navModel = this.createNavModel(c); + catch (error) { + return next.cancel(error); } - return c; - }); - } -} -/* @internal exported for unit testing */ -const generateBaseUrl = (router, instruction) => { - return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`; -}; -/* @internal exported for unit testing */ -const validateRouteConfig = (config) => { - if (typeof config !== 'object') { - throw new Error('Invalid Route Config'); - } - if (typeof config.route !== 'string') { - let name = config.name || '(no name)'; - throw new Error('Invalid Route Config for "' + name + '": You must specify a "route:" pattern.'); - } - if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) { - throw new Error('Invalid Route Config for "' + config.route + '": You must specify a "moduleId:", "redirect:", "navigationStrategy:", or "viewPorts:".'); + } + return next(); } + return iterate(); }; -/* @internal exported for unit testing */ -const evaluateNavigationStrategy = (instruction, evaluator, context) => { - return Promise.resolve(evaluator.call(context, instruction)).then(() => { - if (!('viewPorts' in instruction.config)) { - instruction.config.viewPorts = { - 'default': { - moduleId: instruction.config.moduleId - } - }; +/** + * Find list of activatable view model and add to list (3rd parameter) + * @internal exported for unit testing + */ +const findActivatable = (navigationInstruction, callbackName, list = [], router) => { + let plan = navigationInstruction.plan; + Object + .keys(plan) + .forEach((viewPortName) => { + let viewPortPlan = plan[viewPortName]; + let viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName]; + let viewPortComponent = viewPortInstruction.component; + let viewModel = viewPortComponent.viewModel; + if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle + || viewPortPlan.strategy === activationStrategy.replace) + && callbackName in viewModel) { + list.push({ + viewModel, + lifecycleArgs: viewPortInstruction.lifecycleArgs, + router + }); } - return instruction; - }); -}; - -/**@internal exported for unit testing */ -const createNextFn = (instruction, steps) => { - let index = -1; - const next = function () { - index++; - if (index < steps.length) { - let currentStep = steps[index]; - try { - return currentStep(instruction, next); - } - catch (e) { - return next.reject(e); - } + let childNavInstruction = viewPortPlan.childNavigationInstruction; + if (childNavInstruction) { + findActivatable(childNavInstruction, callbackName, list, viewPortComponent.childRouter || router); } - else { - return next.complete(); + }); + return list; +}; +const shouldContinue = (output, router) => { + if (output instanceof Error) { + return false; + } + if (isNavigationCommand(output)) { + if (typeof output.setRouter === 'function') { + output.setRouter(router); } - }; - next.complete = createCompletionHandler(next, "completed" /* Completed */); - next.cancel = createCompletionHandler(next, "canceled" /* Canceled */); - next.reject = createCompletionHandler(next, "rejected" /* Rejected */); - return next; + return !!output.shouldContinueProcessing; + } + if (output === undefined) { + return true; + } + return output; }; -/**@internal exported for unit testing */ -const createCompletionHandler = (next, status) => { - return (output) => Promise - .resolve({ - status, - output, - completed: status === "completed" /* Completed */ - }); -}; - /** -* The class responsible for managing and processing the navigation pipeline. -*/ -class Pipeline { - constructor() { - /** - * The pipeline steps. And steps added via addStep will be converted to a function - * The actualy running functions with correct step contexts of this pipeline - */ - this.steps = []; + * wraps a subscription, allowing unsubscribe calls even if + * the first value comes synchronously + */ +class SafeSubscription { + constructor(subscriptionFunc) { + this._subscribed = true; + this._subscription = subscriptionFunc(this); + if (!this._subscribed) { + this.unsubscribe(); + } } - /** - * Adds a step to the pipeline. - * - * @param step The pipeline step. - */ - addStep(step) { - let run; - if (typeof step === 'function') { - run = step; + get subscribed() { + return this._subscribed; + } + unsubscribe() { + if (this._subscribed && this._subscription) { + this._subscription.unsubscribe(); } - else if (typeof step.getSteps === 'function') { - // getSteps is to enable support open slots - // where devs can add multiple steps into the same slot name - let steps = step.getSteps(); - for (let i = 0, l = steps.length; i < l; i++) { - this.addStep(steps[i]); + this._subscribed = false; + } +} +/** + * A function to process return value from `activate`/`canActivate` steps + * Supports observable/promise + * + * For observable, resolve at first next() or on complete() + */ +const processPotential = (obj, resolve, reject) => { + // if promise like + if (obj && typeof obj.then === 'function') { + return Promise.resolve(obj).then(resolve).catch(reject); + } + // if observable + if (obj && typeof obj.subscribe === 'function') { + let obs = obj; + return new SafeSubscription(sub => obs.subscribe({ + next() { + if (sub.subscribed) { + sub.unsubscribe(); + resolve(obj); + } + }, + error(error) { + if (sub.subscribed) { + sub.unsubscribe(); + reject(error); + } + }, + complete() { + if (sub.subscribed) { + sub.unsubscribe(); + resolve(obj); + } } - return this; - } - else { - run = step.run.bind(step); - } - this.steps.push(run); - return this; + })); } - /** - * Runs the pipeline. - * - * @param instruction The navigation instruction to process. - */ - run(instruction) { - const nextFn = createNextFn(instruction, this.steps); - return nextFn(); + // else just resolve + try { + return resolve(obj); } -} + catch (error) { + return reject(error); + } +}; /** - * Abstract class that is responsible for loading view / view model from a route config - * The default implementation can be found in `aurelia-templating-router` + * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route */ -class RouteLoader { - /** - * Load a route config based on its viewmodel / view configuration - */ - // return typing: return typings used to be never - // as it was a throw. Changing it to Promise should not cause any issues - loadRoute(router, config, navigationInstruction) { - throw new Error('Route loaders must implement "loadRoute(router, config, navigationInstruction)".'); +class CanDeactivatePreviousStep { + run(navigationInstruction, next) { + return processDeactivatable(navigationInstruction, 'canDeactivate', next); } } /** - * A pipeline step responsible for loading a route config of a navigation instruction + * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route */ -class LoadRouteStep { - /**@internal */ - static inject() { return [RouteLoader]; } - constructor(routeLoader) { - this.routeLoader = routeLoader; - } - /** - * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline - */ +class CanActivateNextStep { run(navigationInstruction, next) { - return loadNewRoute(this.routeLoader, navigationInstruction) - .then(next, next.cancel); + return processActivatable(navigationInstruction, 'canActivate', next); } } /** - * @internal Exported for unit testing - */ -const loadNewRoute = (routeLoader, navigationInstruction) => { - let toLoad = determineWhatToLoad(navigationInstruction); - let loadPromises = toLoad.map((loadingPlan) => loadRoute(routeLoader, loadingPlan.navigationInstruction, loadingPlan.viewPortPlan)); - return Promise.all(loadPromises); -}; -/** - * @internal Exported for unit testing + * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route */ -const determineWhatToLoad = (navigationInstruction, toLoad = []) => { - let plan = navigationInstruction.plan; - for (let viewPortName in plan) { - let viewPortPlan = plan[viewPortName]; - let child_nav_instruction = viewPortPlan.childNavigationInstruction; - if (viewPortPlan.strategy === activationStrategy.replace) { - toLoad.push({ viewPortPlan, navigationInstruction }); - if (child_nav_instruction) { - determineWhatToLoad(child_nav_instruction, toLoad); - } - } - else { - let viewPortInstruction = navigationInstruction.addViewPortInstruction(viewPortName, viewPortPlan.strategy, viewPortPlan.prevModuleId, viewPortPlan.prevComponent); - if (child_nav_instruction) { - viewPortInstruction.childNavigationInstruction = child_nav_instruction; - determineWhatToLoad(child_nav_instruction, toLoad); - } - } +class DeactivatePreviousStep { + run(navigationInstruction, next) { + return processDeactivatable(navigationInstruction, 'deactivate', next, true); } - return toLoad; -}; -/** - * @internal Exported for unit testing - */ -const loadRoute = (routeLoader, navigationInstruction, viewPortPlan) => { - let moduleId = viewPortPlan.config ? viewPortPlan.config.moduleId : null; - return loadComponent(routeLoader, navigationInstruction, viewPortPlan.config) - .then((component) => { - let viewPortInstruction = navigationInstruction.addViewPortInstruction(viewPortPlan.name, viewPortPlan.strategy, moduleId, component); - let childRouter = component.childRouter; - if (childRouter) { - let path = navigationInstruction.getWildcardPath(); - return childRouter - ._createNavigationInstruction(path, navigationInstruction) - .then((childInstruction) => { - viewPortPlan.childNavigationInstruction = childInstruction; - return _buildNavigationPlan(childInstruction) - .then((childPlan) => { - if (childPlan instanceof Redirect) { - return Promise.reject(childPlan); - } - childInstruction.plan = childPlan; - viewPortInstruction.childNavigationInstruction = childInstruction; - return loadNewRoute(routeLoader, childInstruction); - }); - }); - } - // ts complains without this, though they are same - return void 0; - }); -}; +} /** - * Load a routed-component based on navigation instruction and route config - * @internal exported for unit testing only + * A pipeline step responsible for finding and activating method `activate` on a view model of a route */ -const loadComponent = (routeLoader, navigationInstruction, config) => { - let router = navigationInstruction.router; - let lifecycleArgs = navigationInstruction.lifecycleArgs; - return Promise.resolve() - .then(() => routeLoader.loadRoute(router, config, navigationInstruction)) - .then( - /** - * @param component an object carrying information about loaded route - * typically contains information about view model, childContainer, view and router - */ - (component) => { - let { viewModel, childContainer } = component; - component.router = router; - component.config = config; - if ('configureRouter' in viewModel) { - let childRouter = childContainer.getChildRouter(); - component.childRouter = childRouter; - return childRouter - .configure(c => viewModel.configureRouter(c, childRouter, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2])) - .then(() => component); - } - return component; - }); -}; +class ActivateNextStep { + run(navigationInstruction, next) { + return processActivatable(navigationInstruction, 'activate', next, true); + } +} /** * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution @@ -1674,8 +1791,8 @@ class PipelineSlot { } } /** -* Class responsible for creating the navigation pipeline. -*/ + * Class responsible for creating the navigation pipeline. + */ class PipelineProvider { /**@internal */ static inject() { return [Container]; } @@ -1685,20 +1802,20 @@ class PipelineProvider { BuildNavigationPlanStep, CanDeactivatePreviousStep, LoadRouteStep, - this._createPipelineSlot("authorize" /* Authorize */), + createPipelineSlot(container, "authorize" /* Authorize */), CanActivateNextStep, - this._createPipelineSlot("preActivate" /* PreActivate */, 'modelbind'), + createPipelineSlot(container, "preActivate" /* PreActivate */, 'modelbind'), // NOTE: app state changes start below - point of no return DeactivatePreviousStep, ActivateNextStep, - this._createPipelineSlot("preRender" /* PreRender */, 'precommit'), + createPipelineSlot(container, "preRender" /* PreRender */, 'precommit'), CommitChangesStep, - this._createPipelineSlot("postRender" /* PostRender */, 'postcomplete') + createPipelineSlot(container, "postRender" /* PostRender */, 'postcomplete') ]; } /** - * Create the navigation pipeline. - */ + * Create the navigation pipeline. + */ createPipeline(useCanDeactivateStep = true) { let pipeline = new Pipeline(); this.steps.forEach(step => { @@ -1714,14 +1831,15 @@ class PipelineProvider { return this.steps.find(x => x.slotName === name || x.slotAlias === name); } /** - * Adds a step into the pipeline at a known slot location. - */ + * Adds a step into the pipeline at a known slot location. + */ addStep(name, step) { let found = this._findStep(name); if (found) { + let slotSteps = found.steps; // prevent duplicates - if (!found.steps.includes(step)) { - found.steps.push(step); + if (!slotSteps.includes(step)) { + slotSteps.push(step); } } else { @@ -1734,13 +1852,13 @@ class PipelineProvider { removeStep(name, step) { let slot = this._findStep(name); if (slot) { - let steps = slot.steps; - steps.splice(steps.indexOf(step), 1); + let slotSteps = slot.steps; + slotSteps.splice(slotSteps.indexOf(step), 1); } } /** - * @internal * Clears all steps from a slot in the pipeline + * @internal */ _clearSteps(name = '') { let slot = this._findStep(name); @@ -1752,21 +1870,21 @@ class PipelineProvider { * Resets all pipeline slots */ reset() { - this._clearSteps('authorize'); - this._clearSteps('preActivate'); - this._clearSteps('preRender'); - this._clearSteps('postRender'); - } - /**@internal */ - _createPipelineSlot(name, alias) { - return new PipelineSlot(this.container, name, alias); + this._clearSteps("authorize" /* Authorize */); + this._clearSteps("preActivate" /* PreActivate */); + this._clearSteps("preRender" /* PreRender */); + this._clearSteps("postRender" /* PostRender */); } -} +} +/**@internal */ +const createPipelineSlot = (container, name, alias) => { + return new PipelineSlot(container, name, alias); +}; const logger = getLogger('app-router'); /** -* The main application router. -*/ + * The main application router. + */ class AppRouter extends Router { /**@internal */ static inject() { return [Container, History, PipelineProvider, EventAggregator]; } @@ -1776,9 +1894,9 @@ class AppRouter extends Router { this.events = events; } /** - * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. - * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. - */ + * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. + * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. + */ reset() { super.reset(); this.maxInstructionCount = 10; @@ -1790,10 +1908,10 @@ class AppRouter extends Router { } } /** - * Loads the specified URL. - * - * @param url The URL fragment to load. - */ + * Loads the specified URL. + * + * @param url The URL fragment to load. + */ loadUrl(url) { return this ._createNavigationInstruction(url) @@ -1804,11 +1922,11 @@ class AppRouter extends Router { }); } /** - * Registers a viewPort to be used as a rendering target for activated routes. - * - * @param viewPort The viewPort. This is typically a element in Aurelia default impl - * @param name The name of the viewPort. 'default' if unspecified. - */ + * Registers a viewPort to be used as a rendering target for activated routes. + * + * @param viewPort The viewPort. This is typically a element in Aurelia default impl + * @param name The name of the viewPort. 'default' if unspecified. + */ registerViewPort(viewPort, name) { // having strong typing without changing public API const $viewPort = viewPort; @@ -1851,10 +1969,10 @@ class AppRouter extends Router { return Promise.resolve(); } /** - * Activates the router. This instructs the router to begin listening for history changes and processing instructions. - * - * @params options The set of options to activate the router with. - */ + * Activates the router. This instructs the router to begin listening for history changes and processing instructions. + * + * @params options The set of options to activate the router with. + */ activate(options) { if (this.isActive) { return; @@ -1867,8 +1985,8 @@ class AppRouter extends Router { this._dequeueInstruction(); } /** - * Deactivates the router. - */ + * Deactivates the router. + */ deactivate() { this.isActive = false; this.history.deactivate(); @@ -1896,20 +2014,21 @@ class AppRouter extends Router { } this.isNavigating = true; let navtracker = this.history.getState('NavigationTracker'); - if (!navtracker && !this.currentNavigationTracker) { + let currentNavTracker = this.currentNavigationTracker; + if (!navtracker && !currentNavTracker) { this.isNavigatingFirst = true; this.isNavigatingNew = true; } else if (!navtracker) { this.isNavigatingNew = true; } - else if (!this.currentNavigationTracker) { + else if (!currentNavTracker) { this.isNavigatingRefresh = true; } - else if (this.currentNavigationTracker < navtracker) { + else if (currentNavTracker < navtracker) { this.isNavigatingForward = true; } - else if (this.currentNavigationTracker > navtracker) { + else if (currentNavTracker > navtracker) { this.isNavigatingBack = true; } if (!navtracker) { @@ -1918,15 +2037,16 @@ class AppRouter extends Router { } this.currentNavigationTracker = navtracker; instruction.previousInstruction = this.currentInstruction; + let maxInstructionCount = this.maxInstructionCount; if (!instructionCount) { this.events.publish("router:navigation:processing" /* Processing */, { instruction }); } - else if (instructionCount === this.maxInstructionCount - 1) { + else if (instructionCount === maxInstructionCount - 1) { logger.error(`${instructionCount + 1} navigation instructions have been attempted without success. Restoring last known good location.`); restorePreviousLocation(this); return this._dequeueInstruction(instructionCount + 1); } - else if (instructionCount > this.maxInstructionCount) { + else if (instructionCount > maxInstructionCount) { throw new Error('Maximum navigation attempts exceeded. Giving up.'); } let pipeline = this.pipelineProvider.createPipeline(!this.couldDeactivate); @@ -1982,6 +2102,7 @@ const processResult = (instruction, result, instructionCount, router) => { }; const resolveInstruction = (instruction, result, isInnerInstruction, router) => { instruction.resolve(result); + let eventAggregator = router.events; let eventArgs = { instruction, result }; if (!isInnerInstruction) { router.isNavigating = false; @@ -2005,18 +2126,18 @@ const resolveInstruction = (instruction, result, isInnerInstruction, router) => router.history.previousLocation = instruction.fragment + queryString; eventName = "router:navigation:success" /* Success */; } - router.events.publish(eventName, eventArgs); - router.events.publish("router:navigation:complete" /* Complete */, eventArgs); + eventAggregator.publish(eventName, eventArgs); + eventAggregator.publish("router:navigation:complete" /* Complete */, eventArgs); } else { - router.events.publish("router:navigation:child:complete" /* ChildComplete */, eventArgs); + eventAggregator.publish("router:navigation:child:complete" /* ChildComplete */, eventArgs); } return result; }; const restorePreviousLocation = (router) => { let previousLocation = router.history.previousLocation; if (previousLocation) { - router.navigate(router.history.previousLocation, { trigger: false, replace: true }); + router.navigate(previousLocation, { trigger: false, replace: true }); } else if (router.fallbackRoute) { router.navigate(router.fallbackRoute, { trigger: true, replace: true }); diff --git a/dist/es2015/aurelia-router.js.map b/dist/es2015/aurelia-router.js.map index 26c7cad8..229c07f0 100644 --- a/dist/es2015/aurelia-router.js.map +++ b/dist/es2015/aurelia-router.js.map @@ -1 +1 @@ -{"version":3,"file":"aurelia-router.js","sources":["../../src/navigation-commands.ts","../../src/navigation-plan.ts","../../src/activation.ts","../../src/navigation-instruction.ts","../../src/nav-model.ts","../../src/util.ts","../../src/router-configuration.ts","../../src/router.ts","../../src/next.ts","../../src/pipeline.ts","../../src/route-loading.ts","../../src/pipeline-provider.ts","../../src/app-router.ts","../../src/pipeline-status.ts","../../src/router-event.ts","../../src/pipeline-slot-name.ts"],"sourcesContent":["import { NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface NavigationOptions {\n useAppRouter?: boolean;\n }\n}\n\n/**\n* When a navigation command is encountered, the current navigation\n* will be cancelled and control will be passed to the navigation\n* command so it can determine the correct action.\n*/\nexport interface NavigationCommand {\n navigate: (router: Router) => void;\n /**@internal */\n shouldContinueProcessing?: boolean;\n /**@internal */\n setRouter?: (router: Router) => void;\n}\n\n/**\n* Determines if the provided object is a navigation command.\n* A navigation command is anything with a navigate method.\n*\n* @param obj The object to check.\n*/\nexport function isNavigationCommand(obj: any): obj is NavigationCommand {\n return obj && typeof obj.navigate === 'function';\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect.\n*/\nexport class Redirect implements NavigationCommand {\n\n url: string;\n /**@internal */\n options: NavigationOptions;\n /**@internal */\n shouldContinueProcessing: boolean;\n\n private router: Router;\n\n /**\n * @param url The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n constructor(url: string, options: NavigationOptions = {}) {\n this.url = url;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigate(this.url, this.options);\n }\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect to a named route.\n*/\nexport class RedirectToRoute implements NavigationCommand {\n\n route: string;\n params: any;\n /**@internal */\n options: NavigationOptions;\n\n /**@internal */\n shouldContinueProcessing: boolean;\n\n /**@internal */\n router: Router;\n\n /**\n * @param route The name of the route.\n * @param params The parameters to be sent to the activation method.\n * @param options The options to use for navigation.\n */\n constructor(route: string, params: any = {}, options: NavigationOptions = {}) {\n this.route = route;\n this.params = params;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigateToRoute(this.route, this.params, this.options);\n }\n}\n","import { ActivationStrategy, Next, ViewPortPlan } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\n\n/**\n* The strategy to use when activating modules during navigation.\n*/\nexport const activationStrategy: ActivationStrategy = {\n noChange: 'no-change',\n invokeLifecycle: 'invoke-lifecycle',\n replace: 'replace'\n};\n\n/**\n * Transform a navigation instruction into viewport plan record object,\n * or a redirect request if user viewmodel demands\n */\nexport class BuildNavigationPlanStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return _buildNavigationPlan(navigationInstruction)\n .then(plan => {\n if (plan instanceof Redirect) {\n return next.cancel(plan);\n }\n navigationInstruction.plan = plan;\n return next();\n })\n .catch(next.cancel);\n }\n}\n\nexport function _buildNavigationPlan(\n instruction: NavigationInstruction,\n forceLifecycleMinimum?: boolean\n): Promise | Redirect> {\n let config = instruction.config;\n\n // todo: separate and export for unit tests\n if ('redirect' in config) {\n const router = instruction.router;\n return router\n ._createNavigationInstruction(config.redirect)\n .then(newInstruction => {\n const params: Record = {};\n for (let key in newInstruction.params) {\n // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this }\n let val = newInstruction.params[key];\n if (typeof val === 'string' && val[0] === ':') {\n val = val.slice(1);\n // And if that param is found on the original instruction then use it\n if (val in instruction.params) {\n params[key] = instruction.params[val];\n }\n } else {\n params[key] = newInstruction.params[key];\n }\n }\n let redirectLocation = router.generate(newInstruction.config, params, instruction.options);\n\n // Special handling for child routes\n for (let key in instruction.params) {\n redirectLocation = redirectLocation.replace(`:${key}`, instruction.params[key]);\n }\n\n if (instruction.queryString) {\n redirectLocation += '?' + instruction.queryString;\n }\n\n return Promise.resolve(new Redirect(redirectLocation));\n });\n }\n\n const prev = instruction.previousInstruction;\n const plan: Record = {};\n const defaults = instruction.router.viewPortDefaults;\n\n if (prev) {\n let newParams = hasDifferentParameterValues(prev, instruction);\n let pending: Promise[] = [];\n\n for (let viewPortName in prev.viewPortInstructions) {\n const prevViewPortInstruction = prev.viewPortInstructions[viewPortName];\n let nextViewPortConfig = viewPortName in config.viewPorts ? config.viewPorts[viewPortName] : prevViewPortInstruction;\n if (nextViewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) {\n nextViewPortConfig = defaults[viewPortName];\n }\n\n const viewPortPlan = plan[viewPortName] = {\n name: viewPortName,\n config: nextViewPortConfig,\n prevComponent: prevViewPortInstruction.component,\n prevModuleId: prevViewPortInstruction.moduleId\n } as ViewPortPlan;\n\n if (prevViewPortInstruction.moduleId !== nextViewPortConfig.moduleId) {\n viewPortPlan.strategy = activationStrategy.replace;\n } else if ('determineActivationStrategy' in prevViewPortInstruction.component.viewModel) {\n viewPortPlan.strategy = prevViewPortInstruction.component.viewModel\n .determineActivationStrategy(...instruction.lifecycleArgs);\n } else if (config.activationStrategy) {\n viewPortPlan.strategy = config.activationStrategy;\n } else if (newParams || forceLifecycleMinimum) {\n viewPortPlan.strategy = activationStrategy.invokeLifecycle;\n } else {\n viewPortPlan.strategy = activationStrategy.noChange;\n }\n\n if (viewPortPlan.strategy !== activationStrategy.replace && prevViewPortInstruction.childRouter) {\n const path = instruction.getWildcardPath();\n const task: Promise = prevViewPortInstruction\n .childRouter\n ._createNavigationInstruction(path, instruction)\n .then((childInstruction: any) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(\n childInstruction,\n viewPortPlan.strategy === activationStrategy.invokeLifecycle\n )\n .then(childPlan => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n // for bluebird ?\n return null;\n });\n });\n\n pending.push(task);\n }\n }\n\n return Promise.all(pending).then(() => plan);\n }\n\n for (let viewPortName in config.viewPorts) {\n let viewPortConfig = config.viewPorts[viewPortName];\n if (viewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) {\n viewPortConfig = defaults[viewPortName];\n }\n plan[viewPortName] = {\n name: viewPortName,\n strategy: activationStrategy.replace,\n config: viewPortConfig\n };\n }\n\n return Promise.resolve(plan);\n}\n\nfunction hasDifferentParameterValues(prev: NavigationInstruction, next: NavigationInstruction): boolean {\n let prevParams = prev.params;\n let nextParams = next.params;\n let nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null;\n\n for (let key in nextParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n for (let key in prevParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n if (!next.options.compareQueryParams) {\n return false;\n }\n\n let prevQueryParams = prev.queryParams;\n let nextQueryParams = next.queryParams;\n for (let key in nextQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n for (let key in prevQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n return false;\n}\n","import { Next, ViewPortComponent, ViewPortPlan, ViewPortInstruction, LifecycleArguments } from './interfaces';\nimport { isNavigationCommand } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy } from './navigation-plan';\nimport { Router } from './router';\n\n/**\n * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route\n */\nexport class CanDeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'canDeactivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route\n */\nexport class CanActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'canActivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route\n */\nexport class DeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'deactivate', next, true);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `activate` on a view model of a route\n */\nexport class ActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'activate', next, true);\n }\n}\n\n/**\n * Recursively find list of deactivate-able view models\n * and invoke the either 'canDeactivate' or 'deactivate' on each\n */\nconst processDeactivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canDeactivate' | 'deactivate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let plan: Record = navigationInstruction.plan;\n let infos = findDeactivatable(plan, callbackName);\n let i = infos.length; // query from inside out\n\n function inspect(val: any): Promise {\n if (ignoreResult || shouldContinue(val)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n if (i--) {\n try {\n let viewModel = infos[i];\n let result = viewModel[callbackName](navigationInstruction);\n return processPotential(result, inspect, next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n navigationInstruction.router.couldDeactivate = true;\n\n return next();\n }\n\n return iterate();\n};\n\n/**\n * Recursively find and returns a list of deactivate-able view models\n */\nconst findDeactivatable = (\n plan: Record,\n callbackName: string,\n list: IActivatableInfo[] = []\n): any[] => {\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let prevComponent = viewPortPlan.prevComponent;\n\n if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace)\n && prevComponent\n ) {\n let viewModel = prevComponent.viewModel;\n\n if (callbackName in viewModel) {\n list.push(viewModel);\n }\n }\n\n if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) {\n addPreviousDeactivatable(prevComponent, callbackName, list);\n } else if (viewPortPlan.childNavigationInstruction) {\n findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list);\n }\n }\n\n return list;\n};\n\nconst addPreviousDeactivatable = (\n component: ViewPortComponent,\n callbackName: string,\n list: IActivatableInfo[]\n): void => {\n let childRouter = component.childRouter;\n\n if (childRouter && childRouter.currentInstruction) {\n let viewPortInstructions = childRouter.currentInstruction.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let prevComponent = viewPortInstruction.component;\n let prevViewModel = prevComponent.viewModel;\n\n if (callbackName in prevViewModel) {\n list.push(prevViewModel);\n }\n\n addPreviousDeactivatable(prevComponent, callbackName, list);\n }\n }\n};\n\nconst processActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let infos = findActivatable(navigationInstruction, callbackName);\n let length = infos.length;\n let i = -1; // query from top down\n\n function inspect(val: any, router: Router): Promise {\n if (ignoreResult || shouldContinue(val, router)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n i++;\n\n if (i < length) {\n try {\n let current = infos[i];\n let result = current.viewModel[callbackName](...current.lifecycleArgs);\n return processPotential(result, (val: any) => inspect(val, current.router), next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n return next();\n }\n\n return iterate();\n};\n\ninterface IActivatableInfo {\n viewModel: any;\n lifecycleArgs: LifecycleArguments;\n router: Router;\n}\n\n/**\n * Find list of activatable view model and add to list (3rd parameter)\n */\nconst findActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n list: IActivatableInfo[] = [],\n router?: Router\n): IActivatableInfo[] => {\n let plan: Record = navigationInstruction.plan;\n\n Object\n .keys(plan)\n .forEach((viewPortName) => {\n let viewPortPlan = plan[viewPortName];\n let viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName] as ViewPortInstruction;\n let viewPortComponent = viewPortInstruction.component;\n let viewModel = viewPortComponent.viewModel;\n\n if (\n (viewPortPlan.strategy === activationStrategy.invokeLifecycle\n || viewPortPlan.strategy === activationStrategy.replace\n )\n && callbackName in viewModel\n ) {\n list.push({\n viewModel,\n lifecycleArgs: viewPortInstruction.lifecycleArgs,\n router\n });\n }\n\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (childNavInstruction) {\n findActivatable(\n childNavInstruction,\n callbackName,\n list,\n viewPortComponent.childRouter || router\n );\n }\n });\n\n return list;\n};\n\nconst shouldContinue = (output: T, router?: Router): boolean | T => {\n if (output instanceof Error) {\n return false;\n }\n\n if (isNavigationCommand(output)) {\n if (typeof output.setRouter === 'function') {\n output.setRouter(router);\n }\n\n return !!output.shouldContinueProcessing;\n }\n\n if (output === undefined) {\n return true;\n }\n\n return output;\n};\n\n/**\n * A basic interface for an Observable type\n */\nexport interface IObservable {\n subscribe(sub?: IObservableConfig): ISubscription;\n}\n\nexport interface IObservableConfig {\n next(): void;\n error(err?: any): void;\n complete(): void;\n}\n\n/**\n * A basic interface for a Subscription to an Observable\n */\ninterface ISubscription {\n unsubscribe(): void;\n}\n\ntype SafeSubscriptionFunc = (sub: SafeSubscription) => ISubscription;\n\n/**\n * wraps a subscription, allowing unsubscribe calls even if\n * the first value comes synchronously\n */\nclass SafeSubscription {\n\n private _subscribed: boolean;\n private _subscription: ISubscription;\n\n constructor(subscriptionFunc: SafeSubscriptionFunc) {\n this._subscribed = true;\n this._subscription = subscriptionFunc(this);\n\n if (!this._subscribed) {\n this.unsubscribe();\n }\n }\n\n get subscribed(): boolean {\n return this._subscribed;\n }\n\n unsubscribe(): void {\n if (this._subscribed && this._subscription) {\n this._subscription.unsubscribe();\n }\n\n this._subscribed = false;\n }\n}\n\n/**\n * A function to process return value from `activate`/`canActivate` steps\n * Supports observable/promise\n *\n * For observable, resolve at first next() or on complete()\n */\nconst processPotential = (obj: any, resolve: (val?: any) => any, reject: (err?: any) => any): any => {\n // if promise like\n if (obj && typeof obj.then === 'function') {\n return Promise.resolve(obj).then(resolve).catch(reject);\n }\n\n // if observable\n if (obj && typeof obj.subscribe === 'function') {\n let obs: IObservable = obj;\n return new SafeSubscription(sub => obs.subscribe({\n next() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n },\n error(error) {\n if (sub.subscribed) {\n sub.unsubscribe();\n reject(error);\n }\n },\n complete() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n }\n }));\n }\n\n // else just resolve\n try {\n return resolve(obj);\n } catch (error) {\n return reject(error);\n }\n};\n","import { ViewPortInstruction, RouteConfig, ViewPort, LifecycleArguments, ActivationStrategyType } from './interfaces';\nimport { Router } from './router';\nimport { activationStrategy } from './navigation-plan';\n\n/**\n * Initialization options for a navigation instruction\n */\nexport interface NavigationInstructionInit {\n fragment: string;\n queryString?: string;\n params?: Record;\n queryParams?: Record;\n config: RouteConfig;\n parentInstruction?: NavigationInstruction;\n previousInstruction?: NavigationInstruction;\n router: Router;\n options?: Object;\n plan?: Record;\n}\n\n/**\n * A pipeline step for instructing a piepline to commit changes on a navigation instruction\n */\nexport class CommitChangesStep {\n run(navigationInstruction: NavigationInstruction, next: Function): Promise {\n return navigationInstruction\n ._commitChanges(/*wait to swap?*/true)\n .then(() => {\n navigationInstruction._updateTitle();\n return next();\n });\n }\n}\n\n/**\n* Class used to represent an instruction during a navigation.\n*/\nexport class NavigationInstruction {\n /**\n * The URL fragment.\n */\n fragment: string;\n\n /**\n * The query string.\n */\n queryString: string;\n\n /**\n * Parameters extracted from the route pattern.\n */\n params: any;\n\n /**\n * Parameters extracted from the query string.\n */\n queryParams: any;\n\n /**\n * The route config for the route matching this instruction.\n */\n config: RouteConfig;\n\n /**\n * The parent instruction, if this instruction was created by a child router.\n */\n parentInstruction: NavigationInstruction;\n\n parentCatchHandler: any;\n\n /**\n * The instruction being replaced by this instruction in the current router.\n */\n previousInstruction: NavigationInstruction;\n\n /**\n * viewPort instructions to used activation.\n */\n viewPortInstructions: Record;\n\n /**\n * The router instance.\n */\n router: Router;\n\n /**\n * Current built viewport plan of this nav instruction\n */\n plan: Record = null;\n\n options: Record = {};\n\n /**@internal */\n lifecycleArgs: LifecycleArguments;\n /**@internal */\n resolve?: (val?: any) => void;\n\n constructor(init: NavigationInstructionInit) {\n Object.assign(this, init);\n\n this.params = this.params || {};\n this.viewPortInstructions = {};\n\n let ancestorParams = [];\n let current: NavigationInstruction = this;\n do {\n let currentParams = Object.assign({}, current.params);\n if (current.config && current.config.hasChildRouter) {\n // remove the param for the injected child route segment\n delete currentParams[current.getWildCardName()];\n }\n\n ancestorParams.unshift(currentParams);\n current = current.parentInstruction;\n } while (current);\n\n let allParams = Object.assign({}, this.queryParams, ...ancestorParams);\n this.lifecycleArgs = [allParams, this.config, this];\n }\n\n /**\n * Gets an array containing this instruction and all child instructions for the current navigation.\n */\n getAllInstructions(): Array {\n let instructions: NavigationInstruction[] = [this];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let key in viewPortInstructions) {\n let childInstruction = viewPortInstructions[key].childNavigationInstruction;\n if (childInstruction) {\n instructions.push(...childInstruction.getAllInstructions());\n }\n }\n\n return instructions;\n }\n\n /**\n * Gets an array containing the instruction and all child instructions for the previous navigation.\n * Previous instructions are no longer available after navigation completes.\n */\n getAllPreviousInstructions(): Array {\n return this.getAllInstructions().map(c => c.previousInstruction).filter(c => c);\n }\n\n /**\n * Adds a viewPort instruction. Returns the newly created instruction based on parameters\n */\n addViewPortInstruction(name: string, strategy: ActivationStrategyType, moduleId: string, component: any): /*ViewPortInstruction*/ any {\n const lifecycleArgs = this.lifecycleArgs;\n const config: RouteConfig = Object.assign({}, lifecycleArgs[1], { currentViewPort: name });\n const viewportInstruction = this.viewPortInstructions[name] = {\n name: name,\n strategy: strategy,\n moduleId: moduleId,\n component: component,\n childRouter: component.childRouter,\n lifecycleArgs: [].concat(lifecycleArgs[0], config, lifecycleArgs[2]) as LifecycleArguments\n };\n\n return viewportInstruction;\n }\n\n /**\n * Gets the name of the route pattern's wildcard parameter, if applicable.\n */\n getWildCardName(): string {\n // todo: potential issue, or at least unsafe typings\n let configRoute = this.config.route as string;\n let wildcardIndex = configRoute.lastIndexOf('*');\n return configRoute.substr(wildcardIndex + 1);\n }\n\n /**\n * Gets the path and query string created by filling the route\n * pattern's wildcard parameter with the matching param.\n */\n getWildcardPath(): string {\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n let queryString = this.queryString;\n\n if (queryString) {\n path += '?' + queryString;\n }\n\n return path;\n }\n\n /**\n * Gets the instruction's base URL, accounting for wildcard route parameters.\n */\n getBaseUrl(): string {\n let $encodeURI = encodeURI;\n let fragment = decodeURI(this.fragment);\n\n if (fragment === '') {\n let nonEmptyRoute = this.router.routes.find(route => {\n return route.name === this.config.name &&\n route.route !== '';\n });\n if (nonEmptyRoute) {\n fragment = nonEmptyRoute.route as any;\n }\n }\n\n if (!this.params) {\n return $encodeURI(fragment);\n }\n\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n\n if (!path) {\n return $encodeURI(fragment);\n }\n\n return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path)));\n }\n\n /**@internal */\n _commitChanges(waitToSwap: boolean): Promise {\n let router = this.router;\n router.currentInstruction = this;\n\n const previousInstruction = this.previousInstruction;\n if (previousInstruction) {\n previousInstruction.config.navModel.isActive = false;\n }\n\n this.config.navModel.isActive = true;\n\n router.refreshNavigation();\n\n let loads: Promise[] = [];\n let delaySwaps: ISwapPlan[] = [];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let viewPort = router.viewPorts[viewPortName];\n\n if (!viewPort) {\n throw new Error(`There was no router-view found in the view for ${viewPortInstruction.moduleId}.`);\n }\n\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n if (viewPortInstruction.strategy === activationStrategy.replace) {\n if (child_nav_instruction && child_nav_instruction.parentCatchHandler) {\n loads.push(child_nav_instruction._commitChanges(waitToSwap));\n } else {\n if (waitToSwap) {\n delaySwaps.push({ viewPort, viewPortInstruction });\n }\n loads.push(\n viewPort\n .process(viewPortInstruction, waitToSwap)\n .then(() => child_nav_instruction\n ? child_nav_instruction._commitChanges(waitToSwap)\n : Promise.resolve()\n )\n );\n }\n } else {\n if (child_nav_instruction) {\n loads.push(child_nav_instruction._commitChanges(waitToSwap));\n }\n }\n }\n\n return Promise\n .all(loads)\n .then(() => {\n delaySwaps.forEach(x => x.viewPort.swap(x.viewPortInstruction));\n return null;\n })\n .then(() => prune(this));\n }\n\n /**@internal */\n _updateTitle(): void {\n let router = this.router;\n let title = this._buildTitle(router.titleSeparator);\n if (title) {\n router.history.setTitle(title);\n }\n }\n\n /**@internal */\n _buildTitle(separator: string = ' | '): string {\n let title = '';\n let childTitles = [];\n let navModelTitle = this.config.navModel.title;\n let instructionRouter = this.router;\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n if (navModelTitle) {\n title = instructionRouter.transformTitle(navModelTitle);\n }\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n\n if (child_nav_instruction) {\n let childTitle = child_nav_instruction._buildTitle(separator);\n if (childTitle) {\n childTitles.push(childTitle);\n }\n }\n }\n\n if (childTitles.length) {\n title = childTitles.join(separator) + (title ? separator : '') + title;\n }\n\n if (instructionRouter.title) {\n title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title);\n }\n\n return title;\n }\n}\n\nconst prune = (instruction: NavigationInstruction): void => {\n instruction.previousInstruction = null;\n instruction.plan = null;\n};\n\ninterface ISwapPlan {\n viewPort: ViewPort;\n viewPortInstruction: ViewPortInstruction;\n}\n","import { Router } from './router';\nimport { RouteConfig } from './interfaces';\n\n/**\n* Class for storing and interacting with a route's navigation settings.\n*/\nexport class NavModel {\n\n /**\n * True if this nav item is currently active.\n */\n isActive: boolean = false;\n\n /**\n * The title.\n */\n title: string = null;\n\n /**\n * This nav item's absolute href.\n */\n href: string = null;\n\n /**\n * This nav item's relative href.\n */\n relativeHref: string = null;\n\n /**\n * Data attached to the route at configuration time.\n */\n settings: any = {};\n\n /**\n * The route config.\n */\n config: RouteConfig = null;\n\n /**\n * The router associated with this navigation model.\n */\n router: Router;\n\n order: number | boolean;\n\n constructor(router: Router, relativeHref: string) {\n this.router = router;\n this.relativeHref = relativeHref;\n }\n\n /**\n * Sets the route's title and updates document.title.\n * If the a navigation is in progress, the change will be applied\n * to document.title when the navigation completes.\n *\n * @param title The new title.\n */\n setTitle(title: string): void {\n this.title = title;\n\n if (this.isActive) {\n this.router.updateTitle();\n }\n }\n}\n","import { RouteConfig } from './interfaces';\n\nexport function _normalizeAbsolutePath(path: string, hasPushState: boolean, absolute: boolean = false) {\n if (!hasPushState && path[0] !== '#') {\n path = '#' + path;\n }\n\n if (hasPushState && absolute) {\n path = path.substring(1, path.length);\n }\n\n return path;\n}\n\nexport function _createRootedPath(fragment: string, baseUrl: string, hasPushState: boolean, absolute?: boolean) {\n if (isAbsoluteUrl.test(fragment)) {\n return fragment;\n }\n\n let path = '';\n\n if (baseUrl.length && baseUrl[0] !== '/') {\n path += '/';\n }\n\n path += baseUrl;\n\n if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') {\n path += '/';\n }\n\n if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') {\n path = path.substring(0, path.length - 1);\n }\n\n return _normalizeAbsolutePath(path + fragment, hasPushState, absolute);\n}\n\nexport function _resolveUrl(fragment: string, baseUrl: string, hasPushState?: boolean) {\n if (isRootedPath.test(fragment)) {\n return _normalizeAbsolutePath(fragment, hasPushState);\n }\n\n return _createRootedPath(fragment, baseUrl, hasPushState);\n}\n\nexport function _ensureArrayWithSingleRoutePerConfig(config: RouteConfig) {\n let routeConfigs = [];\n\n if (Array.isArray(config.route)) {\n for (let i = 0, ii = config.route.length; i < ii; ++i) {\n let current = Object.assign({}, config);\n current.route = config.route[i];\n routeConfigs.push(current);\n }\n } else {\n routeConfigs.push(Object.assign({}, config));\n }\n\n return routeConfigs;\n}\n\nconst isRootedPath = /^#?\\//;\nconst isAbsoluteUrl = /^([a-z][a-z0-9+\\-.]*:)?\\/\\//i;\n","import { RouteConfig, PipelineStep, RouteConfigSpecifier } from './interfaces';\nimport { _ensureArrayWithSingleRoutePerConfig } from './util';\nimport { Router } from './router';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * Class used to configure a [[Router]] instance.\n *\n * @constructor\n */\nexport class RouterConfiguration {\n instructions: Array<(router: Router) => void> = [];\n options: {\n [key: string]: any;\n compareQueryParams?: boolean;\n root?: string;\n pushState?: boolean;\n hashChange?: boolean;\n silent?: boolean;\n } = {};\n pipelineSteps: Array<{ name: string, step: Function | PipelineStep }> = [];\n title: string;\n titleSeparator: string;\n unknownRouteConfig: RouteConfigSpecifier;\n viewPortDefaults: Record;\n\n /**@internal */\n _fallbackRoute: string;\n\n /**\n * Adds a step to be run during the [[Router]]'s navigation pipeline.\n *\n * @param name The name of the pipeline slot to insert the step into.\n * @param step The pipeline step.\n * @chainable\n */\n addPipelineStep(name: string, step: Function | PipelineStep): RouterConfiguration {\n if (step === null || step === undefined) {\n throw new Error('Pipeline step cannot be null or undefined.');\n }\n this.pipelineSteps.push({ name, step });\n return this;\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s authorize pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addAuthorizeStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.Authorize, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preActivate pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreActivateStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreActivate, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreRender, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s postRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPostRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PostRender, step);\n }\n\n /**\n * Configures a route that will be used if there is no previous location available on navigation cancellation.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @chainable\n */\n fallbackRoute(fragment: string): RouterConfiguration {\n this._fallbackRoute = fragment;\n return this;\n }\n\n /**\n * Maps one or more routes to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map.\n * @chainable\n */\n map(route: RouteConfig | RouteConfig[]): RouterConfiguration {\n if (Array.isArray(route)) {\n route.forEach(this.map.bind(this));\n return this;\n }\n\n return this.mapRoute(route);\n }\n\n /**\n * Configures defaults to use for any view ports.\n *\n * @param viewPortConfig a view port configuration object to use as a\n * default, of the form { viewPortName: { moduleId } }.\n * @chainable\n */\n useViewPortDefaults(viewPortConfig: Record): RouterConfiguration {\n this.viewPortDefaults = viewPortConfig;\n return this;\n }\n\n /**\n * Maps a single route to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map.\n * @chainable\n */\n mapRoute(config: RouteConfig): RouterConfiguration {\n this.instructions.push(router => {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n\n let navModel;\n for (let i = 0, ii = routeConfigs.length; i < ii; ++i) {\n let routeConfig = routeConfigs[i];\n routeConfig.settings = routeConfig.settings || {};\n if (!navModel) {\n navModel = router.createNavModel(routeConfig);\n }\n\n router.addRoute(routeConfig, navModel);\n }\n });\n\n return this;\n }\n\n /**\n * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes.\n *\n * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the\n * [[NavigationInstruction]] and selects a moduleId to load.\n * @chainable\n */\n mapUnknownRoutes(config: RouteConfigSpecifier): RouterConfiguration {\n this.unknownRouteConfig = config;\n return this;\n }\n\n /**\n * Applies the current configuration to the specified [[Router]].\n *\n * @param router The [[Router]] to apply the configuration to.\n */\n exportToRouter(router: Router): void {\n let instructions = this.instructions;\n for (let i = 0, ii = instructions.length; i < ii; ++i) {\n instructions[i](router);\n }\n\n if (this.title) {\n router.title = this.title;\n }\n\n if (this.titleSeparator) {\n router.titleSeparator = this.titleSeparator;\n }\n\n if (this.unknownRouteConfig) {\n router.handleUnknownRoutes(this.unknownRouteConfig);\n }\n\n if (this._fallbackRoute) {\n router.fallbackRoute = this._fallbackRoute;\n }\n\n if (this.viewPortDefaults) {\n router.useViewPortDefaults(this.viewPortDefaults);\n }\n\n Object.assign(router.options, this.options);\n\n let pipelineSteps = this.pipelineSteps;\n if (pipelineSteps.length) {\n if (!router.isRoot) {\n throw new Error('Pipeline steps can only be added to the root router');\n }\n\n let pipelineProvider = router.pipelineProvider;\n for (let i = 0, ii = pipelineSteps.length; i < ii; ++i) {\n let { name, step } = pipelineSteps[i];\n pipelineProvider.addStep(name, step);\n }\n }\n }\n}\n","import { RouteRecognizer, RouteHandler, ConfigurableRoute, State, RecognizedRoute } from 'aurelia-route-recognizer';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { NavigationInstruction, NavigationInstructionInit } from './navigation-instruction';\nimport { NavModel } from './nav-model';\nimport { RouterConfiguration } from './router-configuration';\nimport {\n _ensureArrayWithSingleRoutePerConfig,\n _normalizeAbsolutePath,\n _createRootedPath,\n _resolveUrl\n} from './util';\nimport { RouteConfig, NavigationResult, RouteConfigSpecifier, ViewPort, ViewPortInstruction } from './interfaces';\nimport { PipelineProvider } from './pipeline-provider';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface History {\n // This is wrong, as it's an implementation detail from aurelia-history-browser\n // but we are poking it in here so probably will need to make it official in `aurelia-history`\n /**\n * A private flag of Aurelia History implementation to indicate if push state should be used\n */\n _hasPushState: boolean;\n\n previousLocation: string;\n }\n}\n\n/**@internal */\ndeclare module 'aurelia-route-recognizer' {\n interface State {\n types: {\n dynamics: DynamicSegment;\n stars: StarSegment;\n };\n }\n\n interface RouteHandler {\n navigationStrategy?: (instruction: NavigationInstruction) => any;\n }\n\n interface RecognizedRoute {\n config?: RouteConfig;\n queryParams?: Record;\n }\n}\n\ntype RouterConfigurationResolution = RouterConfiguration | ((cfg: RouterConfiguration) => void | RouterConfiguration | Promise);\n\n/**\n * The primary class responsible for handling routing and navigation.\n */\nexport class Router {\n\n /**\n * Container associated with this router. Also used to create child container for creating child router.\n */\n container: Container;\n\n /**\n * History instance of Aurelia abstract class for wrapping platform history global object\n */\n history: History;\n\n /**\n * A registry of registered viewport. Will be used to handle process navigation instruction route loading\n * and dom swapping\n */\n viewPorts: Record;\n\n /**\n * List of route configs registered with this router\n */\n routes: RouteConfig[];\n\n /**\n * The [[Router]]'s current base URL, typically based on the [[Router.currentInstruction]].\n */\n baseUrl: string;\n\n /**\n * If defined, used in generation of document title for [[Router]]'s routes.\n */\n title: string | undefined;\n\n /**\n * The separator used in the document title between [[Router]]'s routes.\n */\n titleSeparator: string | undefined;\n\n /**\n * True if the [[Router]] has been configured.\n */\n isConfigured: boolean;\n\n /**\n * True if the [[Router]] is currently processing a navigation.\n */\n isNavigating: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigate function(s).\n */\n isExplicitNavigation: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigateBack function.\n */\n isExplicitNavigationBack: boolean;\n\n /**\n * True if the [[Router]] is navigating into the app for the first time in the browser session.\n */\n isNavigatingFirst: boolean;\n\n /**\n * True if the [[Router]] is navigating to a page instance not in the browser session history.\n */\n isNavigatingNew: boolean;\n\n /**\n * True if the [[Router]] is navigating forward in the browser session history.\n */\n isNavigatingForward: boolean;\n\n /**\n * True if the [[Router]] is navigating back in the browser session history.\n */\n isNavigatingBack: boolean;\n\n /**\n * True if the [[Router]] is navigating due to a browser refresh.\n */\n isNavigatingRefresh: boolean;\n\n /**\n * True if the previous instruction successfully completed the CanDeactivatePreviousStep in the current navigation.\n */\n couldDeactivate: boolean;\n\n /**\n * The currently active navigation tracker.\n */\n currentNavigationTracker: number;\n\n /**\n * The navigation models for routes that specified [[RouteConfig.nav]].\n */\n navigation: NavModel[];\n\n /**\n * The currently active navigation instruction.\n */\n currentInstruction: NavigationInstruction;\n\n /**\n * The parent router, or null if this instance is not a child router.\n */\n parent: Router = null;\n\n options: any = {};\n\n /**\n * The defaults used when a viewport lacks specified content\n */\n viewPortDefaults: Record = {};\n\n /**@internal */\n catchAllHandler: (instruction: NavigationInstruction) => NavigationInstruction | Promise;\n /**@internal */\n fallbackRoute: string;\n /**@internal */\n pipelineProvider: PipelineProvider;\n /**@internal */\n _fallbackOrder: number;\n /**@internal */\n _recognizer: RouteRecognizer;\n /**@internal */\n _childRecognizer: RouteRecognizer;\n /**@internal */\n _configuredPromise: Promise;\n /**@internal */\n _resolveConfiguredPromise: (value?: any) => void;\n\n /**\n * Extension point to transform the document title before it is built and displayed.\n * By default, child routers delegate to the parent router, and the app router\n * returns the title unchanged.\n */\n transformTitle: (title: string) => string = (title: string) => {\n if (this.parent) {\n return this.parent.transformTitle(title);\n }\n return title;\n }\n\n /**\n * @param container The [[Container]] to use when child routers.\n * @param history The [[History]] implementation to delegate navigation requests to.\n */\n constructor(container: Container, history: History) {\n this.container = container;\n this.history = history;\n this.reset();\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset() {\n this.viewPorts = {};\n this.routes = [];\n this.baseUrl = '';\n this.isConfigured = false;\n this.isNavigating = false;\n this.isExplicitNavigation = false;\n this.isExplicitNavigationBack = false;\n this.isNavigatingFirst = false;\n this.isNavigatingNew = false;\n this.isNavigatingRefresh = false;\n this.isNavigatingForward = false;\n this.isNavigatingBack = false;\n this.couldDeactivate = false;\n this.navigation = [];\n this.currentInstruction = null;\n this.viewPortDefaults = {};\n this._fallbackOrder = 100;\n this._recognizer = new RouteRecognizer();\n this._childRecognizer = new RouteRecognizer();\n this._configuredPromise = new Promise(resolve => {\n this._resolveConfiguredPromise = resolve;\n });\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent.\n */\n get isRoot(): boolean {\n return !this.parent;\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort.\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/any, name?: string): void {\n name = name || 'default';\n this.viewPorts[name] = viewPort;\n }\n\n /**\n * Returns a Promise that resolves when the router is configured.\n */\n ensureConfigured(): Promise {\n return this._configuredPromise;\n }\n\n /**\n * Configures the router.\n *\n * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]].\n */\n configure(callbackOrConfig: RouterConfiguration | ((config: RouterConfiguration) => RouterConfiguration)): Promise {\n this.isConfigured = true;\n\n let result: RouterConfigurationResolution = callbackOrConfig as RouterConfiguration;\n let config: RouterConfiguration;\n if (typeof callbackOrConfig === 'function') {\n config = new RouterConfiguration();\n result = callbackOrConfig(config);\n }\n\n return Promise\n .resolve(result)\n .then((c) => {\n if (c && (c as RouterConfiguration).exportToRouter) {\n config = c;\n }\n\n config.exportToRouter(this);\n this.isConfigured = true;\n this._resolveConfiguredPromise();\n });\n }\n\n /**\n * Navigates to a new location.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n navigate(fragment: string, options?: NavigationOptions): boolean {\n if (!this.isConfigured && this.parent) {\n return this.parent.navigate(fragment, options);\n }\n\n this.isExplicitNavigation = true;\n return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options);\n }\n\n /**\n * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed\n * by [[Router.navigate]].\n *\n * @param route The name of the route to use when generating the navigation location.\n * @param params The route parameters to be used when populating the route pattern.\n * @param options The navigation options.\n */\n navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean {\n let path = this.generate(route, params);\n return this.navigate(path, options);\n }\n\n /**\n * Navigates back to the most recent location in history.\n */\n navigateBack(): void {\n this.isExplicitNavigationBack = true;\n this.history.navigateBack();\n }\n\n /**\n * Creates a child router of the current router.\n *\n * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified.\n * @returns {Router} The new child Router.\n */\n createChild(container?: Container): Router {\n let childRouter = new Router(container || this.container.createChild(), this.history);\n childRouter.parent = this;\n return childRouter;\n }\n\n /**\n * Generates a URL fragment matching the specified route pattern.\n *\n * @param name The name of the route whose pattern should be used to generate the fragment.\n * @param params The route params to be used to populate the route pattern.\n * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url.\n * @returns {string} A string containing the generated URL fragment.\n */\n generate(nameOrRoute: string | RouteConfig, params: any = {}, options: any = {}): string {\n // A child recognizer generates routes for potential child routes. Any potential child route is added\n // to the childRoute property of params for the childRouter to recognize. When generating routes, we\n // use the childRecognizer when childRoute params are available to generate a child router enabled route.\n let recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer;\n let hasRoute = recognizer.hasRoute(nameOrRoute as string | RouteHandler);\n if (!hasRoute) {\n if (this.parent) {\n return this.parent.generate(nameOrRoute, params, options);\n }\n throw new Error(`A route with name '${nameOrRoute}' could not be found. Check that \\`name: '${nameOrRoute}'\\` was specified in the route's config.`);\n }\n let path = recognizer.generate(nameOrRoute as string | RouteHandler, params);\n let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute);\n return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath;\n }\n\n /**\n * Creates a [[NavModel]] for the specified route config.\n *\n * @param config The route config.\n */\n createNavModel(config: RouteConfig): NavModel {\n let navModel = new NavModel(\n this,\n 'href' in config\n ? config.href\n // potential error when config.route is a string[] ?\n : config.route as string);\n navModel.title = config.title;\n navModel.order = config.nav;\n navModel.href = config.href;\n navModel.settings = config.settings;\n navModel.config = config;\n\n return navModel;\n }\n\n /**\n * Registers a new route with the router.\n *\n * @param config The [[RouteConfig]].\n * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes.\n */\n addRoute(config: RouteConfig, navModel?: NavModel): void {\n if (Array.isArray(config.route)) {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n // the following is wrong. todo: fix this after TS refactoring release\n routeConfigs.forEach(this.addRoute.bind(this));\n return;\n }\n\n validateRouteConfig(config);\n\n if (!('viewPorts' in config) && !config.navigationStrategy) {\n config.viewPorts = {\n 'default': {\n moduleId: config.moduleId,\n view: config.view\n }\n };\n }\n\n if (!navModel) {\n navModel = this.createNavModel(config);\n }\n\n this.routes.push(config);\n\n let path = config.route;\n if (path.charAt(0) === '/') {\n path = path.substr(1);\n }\n let caseSensitive = config.caseSensitive === true;\n let state: State = this._recognizer.add({\n path: path,\n handler: config as RouteHandler,\n caseSensitive: caseSensitive\n } as ConfigurableRoute);\n\n if (path) {\n let settings = config.settings;\n delete config.settings;\n let withChild = JSON.parse(JSON.stringify(config));\n config.settings = settings;\n withChild.route = `${path}/*childRoute`;\n withChild.hasChildRouter = true;\n this._childRecognizer.add({\n path: withChild.route,\n handler: withChild,\n caseSensitive: caseSensitive\n });\n\n withChild.navModel = navModel;\n withChild.settings = config.settings;\n withChild.navigationStrategy = config.navigationStrategy;\n }\n\n config.navModel = navModel;\n\n let navigation = this.navigation;\n\n if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) {\n if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) {\n throw new Error('Invalid route config for \"' + config.route + '\" : dynamic routes must specify an \"href:\" to be included in the navigation model.');\n }\n\n if (typeof navModel.order !== 'number') {\n navModel.order = ++this._fallbackOrder;\n }\n\n navigation.push(navModel);\n // this is a potential error / inconsistency between browsers\n //\n // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\n // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other,\n // but sorted with respect to all different elements.\n // Note: the ECMAscript standard does not guarantee this behaviour,\n // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.\n navigation.sort((a, b) => a.order - b.order);\n }\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasRoute(name: string): boolean {\n return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name));\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasOwnRoute(name: string): boolean {\n return this._recognizer.hasRoute(name);\n }\n\n /**\n * Register a handler to use when the incoming URL fragment doesn't match any registered routes.\n *\n * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]].\n */\n handleUnknownRoutes(config?: RouteConfigSpecifier): void {\n if (!config) {\n throw new Error('Invalid unknown route handler');\n }\n\n this.catchAllHandler = instruction => {\n return this\n ._createRouteConfig(config, instruction)\n .then(c => {\n instruction.config = c;\n return instruction;\n });\n };\n }\n\n /**\n * Updates the document title using the current navigation instruction.\n */\n updateTitle(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n return parentRouter.updateTitle();\n }\n\n let currentInstruction = this.currentInstruction;\n if (currentInstruction) {\n currentInstruction._updateTitle();\n }\n return undefined;\n }\n\n /**\n * Updates the navigation routes with hrefs relative to the current location.\n * Note: This method will likely move to a plugin in a future release.\n */\n refreshNavigation(): void {\n let nav = this.navigation;\n\n for (let i = 0, length = nav.length; i < length; i++) {\n let current = nav[i];\n if (!current.config.href) {\n current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState);\n } else {\n current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState);\n }\n }\n }\n\n /**\n * Sets the default configuration for the view ports. This specifies how to\n * populate a view port for which no module is specified. The default is\n * an empty view/view-model pair.\n */\n useViewPortDefaults($viewPortDefaults: Record): void {\n // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction\n let viewPortDefaults: Record = $viewPortDefaults;\n for (let viewPortName in viewPortDefaults) {\n let viewPortConfig = viewPortDefaults[viewPortName];\n this.viewPortDefaults[viewPortName] = {\n moduleId: viewPortConfig.moduleId\n };\n }\n }\n\n /**@internal */\n _refreshBaseUrl(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction);\n }\n }\n\n /**@internal */\n _createNavigationInstruction(url: string = '', parentInstruction: NavigationInstruction = null): Promise {\n let fragment = url;\n let queryString = '';\n\n let queryIndex = url.indexOf('?');\n if (queryIndex !== -1) {\n fragment = url.substr(0, queryIndex);\n queryString = url.substr(queryIndex + 1);\n }\n\n let urlRecognizationResults = this._recognizer.recognize(url) as IRouteRecognizationResults;\n if (!urlRecognizationResults || !urlRecognizationResults.length) {\n urlRecognizationResults = this._childRecognizer.recognize(url) as IRouteRecognizationResults;\n }\n\n let instructionInit: NavigationInstructionInit = {\n fragment,\n queryString,\n config: null,\n parentInstruction,\n previousInstruction: this.currentInstruction,\n router: this,\n options: {\n compareQueryParams: this.options.compareQueryParams\n }\n };\n\n let result: Promise;\n\n if (urlRecognizationResults && urlRecognizationResults.length) {\n let first = urlRecognizationResults[0];\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: first.params,\n queryParams: first.queryParams || urlRecognizationResults.queryParams,\n config: first.config || first.handler\n }));\n\n if (typeof first.handler === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler, first);\n } else if (first.handler && typeof first.handler.navigationStrategy === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler);\n } else {\n result = Promise.resolve(instruction);\n }\n } else if (this.catchAllHandler) {\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n config: null // config will be created by the catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, this.catchAllHandler);\n } else if (this.parent) {\n let router = this._parentCatchAllHandler(this.parent);\n\n if (router) {\n let newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction);\n\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n router: router,\n parentInstruction: newParentInstruction,\n parentCatchHandler: true,\n config: null // config will be created by the chained parent catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, router.catchAllHandler);\n }\n }\n\n if (result && parentInstruction) {\n this.baseUrl = generateBaseUrl(this.parent, parentInstruction);\n }\n\n return result || Promise.reject(new Error(`Route not found: ${url}`));\n }\n\n /**@internal */\n _findParentInstructionFromRouter(router: Router, instruction: NavigationInstruction): NavigationInstruction {\n if (instruction.router === router) {\n instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId\n return instruction;\n } else if (instruction.parentInstruction) {\n return this._findParentInstructionFromRouter(router, instruction.parentInstruction);\n }\n return undefined;\n }\n\n /**@internal */\n _parentCatchAllHandler(router: Router): Router | false {\n if (router.catchAllHandler) {\n return router;\n } else if (router.parent) {\n return this._parentCatchAllHandler(router.parent);\n }\n return false;\n }\n\n /**\n * @internal\n */\n _createRouteConfig(config: RouteConfigSpecifier, instruction: NavigationInstruction): Promise {\n return Promise\n .resolve(config)\n .then((c: any) => {\n if (typeof c === 'string') {\n return { moduleId: c } as RouteConfig;\n } else if (typeof c === 'function') {\n return c(instruction);\n }\n\n return c;\n })\n // typing here could be either RouteConfig or RedirectConfig\n // but temporarily treat both as RouteConfig\n // todo: improve typings precision\n .then((c: string | RouteConfig) => typeof c === 'string' ? { moduleId: c } as RouteConfig : c)\n .then((c: RouteConfig) => {\n c.route = instruction.params.path;\n validateRouteConfig(c);\n\n if (!c.navModel) {\n c.navModel = this.createNavModel(c);\n }\n\n return c;\n });\n }\n}\n\n/* @internal exported for unit testing */\nexport const generateBaseUrl = (router: Router, instruction: NavigationInstruction): string => {\n return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`;\n};\n\n/* @internal exported for unit testing */\nexport const validateRouteConfig = (config: RouteConfig): void => {\n if (typeof config !== 'object') {\n throw new Error('Invalid Route Config');\n }\n\n if (typeof config.route !== 'string') {\n let name = config.name || '(no name)';\n throw new Error('Invalid Route Config for \"' + name + '\": You must specify a \"route:\" pattern.');\n }\n\n if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) {\n throw new Error('Invalid Route Config for \"' + config.route + '\": You must specify a \"moduleId:\", \"redirect:\", \"navigationStrategy:\", or \"viewPorts:\".');\n }\n};\n\n/* @internal exported for unit testing */\nexport const evaluateNavigationStrategy = (\n instruction: NavigationInstruction,\n evaluator: Function,\n context?: any\n): Promise => {\n return Promise.resolve(evaluator.call(context, instruction)).then(() => {\n if (!('viewPorts' in instruction.config)) {\n instruction.config.viewPorts = {\n 'default': {\n moduleId: instruction.config.moduleId\n }\n };\n }\n\n return instruction;\n });\n};\n\ninterface IRouteRecognizationResults extends Array {\n queryParams: Record;\n}\n","import { PipelineStatus } from './pipeline-status';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Next, StepRunnerFunction, NextCompletionHandler } from './interfaces';\n\n/**@internal exported for unit testing */\nexport const createNextFn = (instruction: NavigationInstruction, steps: StepRunnerFunction[]): Next => {\n let index = -1;\n const next: Next = function() {\n index++;\n\n if (index < steps.length) {\n let currentStep = steps[index];\n\n try {\n return currentStep(instruction, next);\n } catch (e) {\n return next.reject(e);\n }\n } else {\n return next.complete();\n }\n } as Next;\n\n next.complete = createCompletionHandler(next, PipelineStatus.Completed);\n next.cancel = createCompletionHandler(next, PipelineStatus.Canceled);\n next.reject = createCompletionHandler(next, PipelineStatus.Rejected);\n\n return next;\n};\n\n/**@internal exported for unit testing */\nexport const createCompletionHandler = (next: Next, status: PipelineStatus): NextCompletionHandler => {\n return (output: any) => Promise\n .resolve({\n status,\n output,\n completed: status === PipelineStatus.Completed\n });\n};\n","import { PipelineStep, PipelineResult, Next, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { createNextFn } from './next';\n\n/**\n* The class responsible for managing and processing the navigation pipeline.\n*/\nexport class Pipeline {\n /**\n * The pipeline steps. And steps added via addStep will be converted to a function\n * The actualy running functions with correct step contexts of this pipeline\n */\n steps: StepRunnerFunction[] = [];\n\n /**\n * Adds a step to the pipeline.\n *\n * @param step The pipeline step.\n */\n addStep(step: StepRunnerFunction | PipelineStep | IPipelineSlot): Pipeline {\n let run;\n\n if (typeof step === 'function') {\n run = step;\n } else if (typeof step.getSteps === 'function') {\n // getSteps is to enable support open slots\n // where devs can add multiple steps into the same slot name\n let steps = step.getSteps();\n for (let i = 0, l = steps.length; i < l; i++) {\n this.addStep(steps[i]);\n }\n\n return this;\n } else {\n run = (step as PipelineStep).run.bind(step);\n }\n\n this.steps.push(run);\n\n return this;\n }\n\n /**\n * Runs the pipeline.\n *\n * @param instruction The navigation instruction to process.\n */\n run(instruction: NavigationInstruction): Promise {\n const nextFn = createNextFn(instruction, this.steps);\n return nextFn();\n }\n}\n","import { Next, RouteConfig, ViewPortComponent, ViewPortPlan, ViewPortInstruction } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy, _buildNavigationPlan } from './navigation-plan';\nimport { Router } from './router';\n\n/**\n * Loading plan calculated based on a navigration-instruction and a viewport plan\n */\ninterface ILoadingPlan {\n viewPortPlan: ViewPortPlan;\n navigationInstruction: NavigationInstruction;\n}\n\n/**\n * Abstract class that is responsible for loading view / view model from a route config\n * The default implementation can be found in `aurelia-templating-router`\n */\nexport class RouteLoader {\n /**\n * Load a route config based on its viewmodel / view configuration\n */\n // return typing: return typings used to be never\n // as it was a throw. Changing it to Promise should not cause any issues\n loadRoute(router: Router, config: RouteConfig, navigationInstruction: NavigationInstruction): Promise {\n throw new Error('Route loaders must implement \"loadRoute(router, config, navigationInstruction)\".');\n }\n}\n\n/**\n * A pipeline step responsible for loading a route config of a navigation instruction\n */\nexport class LoadRouteStep {\n /**@internal */\n static inject() { return [RouteLoader]; }\n /**\n * Route loader isntance that will handle loading route config\n * @internal\n */\n routeLoader: RouteLoader;\n\n constructor(routeLoader: RouteLoader) {\n this.routeLoader = routeLoader;\n }\n\n /**\n * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline\n */\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return loadNewRoute(this.routeLoader, navigationInstruction)\n .then(next, next.cancel);\n }\n}\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadNewRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction\n): Promise => {\n let toLoad = determineWhatToLoad(navigationInstruction);\n let loadPromises = toLoad.map((loadingPlan: ILoadingPlan) => loadRoute(\n routeLoader,\n loadingPlan.navigationInstruction,\n loadingPlan.viewPortPlan\n ));\n\n return Promise.all(loadPromises);\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const determineWhatToLoad = (\n navigationInstruction: NavigationInstruction,\n toLoad: ILoadingPlan[] = []\n): ILoadingPlan[] => {\n let plan: Record = navigationInstruction.plan;\n\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let child_nav_instruction = viewPortPlan.childNavigationInstruction;\n\n if (viewPortPlan.strategy === activationStrategy.replace) {\n toLoad.push({ viewPortPlan, navigationInstruction } as ILoadingPlan);\n\n if (child_nav_instruction) {\n determineWhatToLoad(child_nav_instruction, toLoad);\n }\n } else {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction(\n viewPortName,\n viewPortPlan.strategy,\n viewPortPlan.prevModuleId,\n viewPortPlan.prevComponent\n ) as ViewPortInstruction;\n\n if (child_nav_instruction) {\n viewPortInstruction.childNavigationInstruction = child_nav_instruction;\n determineWhatToLoad(child_nav_instruction, toLoad);\n }\n }\n }\n\n return toLoad;\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n viewPortPlan: ViewPortPlan\n): Promise => {\n let moduleId = viewPortPlan.config ? viewPortPlan.config.moduleId : null;\n\n return loadComponent(routeLoader, navigationInstruction, viewPortPlan.config)\n .then((component) => {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction(\n viewPortPlan.name,\n viewPortPlan.strategy,\n moduleId,\n component\n ) as ViewPortInstruction;\n\n let childRouter = component.childRouter;\n if (childRouter) {\n let path = navigationInstruction.getWildcardPath();\n\n return childRouter\n ._createNavigationInstruction(path, navigationInstruction)\n .then((childInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(childInstruction)\n .then((childPlan) => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n viewPortInstruction.childNavigationInstruction = childInstruction;\n\n return loadNewRoute(routeLoader, childInstruction);\n });\n });\n }\n // ts complains without this, though they are same\n return void 0;\n });\n};\n\n/**\n * Load a routed-component based on navigation instruction and route config\n * @internal exported for unit testing only\n */\nexport const loadComponent = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n config: RouteConfig\n): Promise => {\n let router = navigationInstruction.router;\n let lifecycleArgs = navigationInstruction.lifecycleArgs;\n\n return Promise.resolve()\n .then(() => routeLoader.loadRoute(router, config, navigationInstruction))\n .then(\n /**\n * @param component an object carrying information about loaded route\n * typically contains information about view model, childContainer, view and router\n */\n (component: ViewPortComponent) => {\n let { viewModel, childContainer } = component;\n component.router = router;\n component.config = config;\n\n if ('configureRouter' in viewModel) {\n let childRouter = childContainer.getChildRouter();\n component.childRouter = childRouter;\n\n return childRouter\n .configure(c => viewModel.configureRouter(c, childRouter, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]))\n .then(() => component);\n }\n\n return component;\n });\n};\n","import { Container } from 'aurelia-dependency-injection';\nimport { Pipeline } from './pipeline';\nimport { BuildNavigationPlanStep } from './navigation-plan';\nimport { LoadRouteStep } from './route-loading';\nimport { CommitChangesStep } from './navigation-instruction';\nimport {\n CanDeactivatePreviousStep,\n CanActivateNextStep,\n DeactivatePreviousStep,\n ActivateNextStep\n} from './activation';\nimport { PipelineStep, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution\n */\nclass PipelineSlot implements IPipelineSlot {\n\n /**@internal */\n container: Container;\n /**@internal */\n slotName: string;\n /**@internal */\n slotAlias?: string;\n\n steps: (Function | PipelineStep)[] = [];\n\n constructor(container: Container, name: string, alias?: string) {\n this.container = container;\n this.slotName = name;\n this.slotAlias = alias;\n }\n\n getSteps(): (StepRunnerFunction | IPipelineSlot | PipelineStep)[] {\n return this.steps.map(x => this.container.get(x));\n }\n}\n\n/**\n* Class responsible for creating the navigation pipeline.\n*/\nexport class PipelineProvider {\n\n /**@internal */\n static inject() { return [Container]; }\n /**@internal */\n container: Container;\n /**@internal */\n steps: (Function | PipelineSlot)[];\n\n constructor(container: Container) {\n this.container = container;\n this.steps = [\n BuildNavigationPlanStep,\n CanDeactivatePreviousStep, // optional\n LoadRouteStep,\n this._createPipelineSlot(PipelineSlotName.Authorize),\n CanActivateNextStep, // optional\n this._createPipelineSlot(PipelineSlotName.PreActivate, 'modelbind'),\n // NOTE: app state changes start below - point of no return\n DeactivatePreviousStep, // optional\n ActivateNextStep, // optional\n this._createPipelineSlot(PipelineSlotName.PreRender, 'precommit'),\n CommitChangesStep,\n this._createPipelineSlot(PipelineSlotName.PostRender, 'postcomplete')\n ];\n }\n\n /**\n * Create the navigation pipeline.\n */\n createPipeline(useCanDeactivateStep: boolean = true): Pipeline {\n let pipeline = new Pipeline();\n this.steps.forEach(step => {\n if (useCanDeactivateStep || step !== CanDeactivatePreviousStep) {\n pipeline.addStep(this.container.get(step));\n }\n });\n return pipeline;\n }\n\n /**@internal */\n _findStep(name: string): PipelineSlot {\n // Steps that are not PipelineSlots are constructor functions, and they will automatically fail. Probably.\n return this.steps.find(x => (x as PipelineSlot).slotName === name || (x as PipelineSlot).slotAlias === name) as PipelineSlot;\n }\n\n /**\n * Adds a step into the pipeline at a known slot location.\n */\n addStep(name: string, step: PipelineStep | Function): void {\n let found = this._findStep(name);\n if (found) {\n // prevent duplicates\n if (!found.steps.includes(step)) {\n found.steps.push(step);\n }\n } else {\n throw new Error(`Invalid pipeline slot name: ${name}.`);\n }\n }\n\n /**\n * Removes a step from a slot in the pipeline\n */\n removeStep(name: string, step: PipelineStep): void {\n let slot = this._findStep(name);\n if (slot) {\n let steps = slot.steps;\n steps.splice(steps.indexOf(step), 1);\n }\n }\n\n /**\n * @internal\n * Clears all steps from a slot in the pipeline\n */\n _clearSteps(name: string = ''): void {\n let slot = this._findStep(name);\n if (slot) {\n slot.steps = [];\n }\n }\n\n /**\n * Resets all pipeline slots\n */\n reset(): void {\n this._clearSteps('authorize');\n this._clearSteps('preActivate');\n this._clearSteps('preRender');\n this._clearSteps('postRender');\n }\n\n /**@internal */\n _createPipelineSlot(name: string, alias?: string): PipelineSlot {\n return new PipelineSlot(this.container, name, alias);\n }\n}\n","import * as LogManager from 'aurelia-logging';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\nimport { PipelineProvider } from './pipeline-provider';\nimport { isNavigationCommand } from './navigation-commands';\nimport { EventAggregator } from 'aurelia-event-aggregator';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { ViewPort, ConfiguresRouter, PipelineResult } from './interfaces';\nimport { RouterEvent } from './router-event';\n\n/**@internal */\ndeclare module 'aurelia-dependency-injection' {\n interface Container {\n viewModel?: any;\n }\n}\n\nconst logger = LogManager.getLogger('app-router');\n\n/**\n* The main application router.\n*/\nexport class AppRouter extends Router {\n\n /**@internal */\n static inject() { return [Container, History, PipelineProvider, EventAggregator]; }\n\n events: EventAggregator;\n /**@internal */\n maxInstructionCount: number;\n /**@internal */\n _queue: NavigationInstruction[];\n /**@internal */\n isActive: boolean;\n\n constructor(container: Container, history: History, pipelineProvider: PipelineProvider, events: EventAggregator) {\n super(container, history); // Note the super will call reset internally.\n this.pipelineProvider = pipelineProvider;\n this.events = events;\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset(): void {\n super.reset();\n this.maxInstructionCount = 10;\n if (!this._queue) {\n this._queue = [];\n } else {\n this._queue.length = 0;\n }\n }\n\n /**\n * Loads the specified URL.\n *\n * @param url The URL fragment to load.\n */\n loadUrl(url: string): Promise {\n return this\n ._createNavigationInstruction(url)\n .then(instruction => this._queueInstruction(instruction))\n .catch(error => {\n logger.error(error);\n restorePreviousLocation(this);\n });\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort. This is typically a element in Aurelia default impl\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/ any, name?: string): Promise {\n // having strong typing without changing public API\n const $viewPort: ViewPort = viewPort;\n super.registerViewPort($viewPort, name);\n\n // beside adding viewport to the registry of this instance\n // AppRouter also configure routing/history to start routing functionality\n // There are situation where there are more than 1 element at root view\n // in that case, still only activate once via the following guard\n if (!this.isActive) {\n const viewModel = this._findViewModel($viewPort);\n if ('configureRouter' in viewModel) {\n // If there are more than one element at root view\n // use this flag to guard against configure method being invoked multiple times\n // this flag is set inside method configure\n if (!this.isConfigured) {\n // replace the real resolve with a noop to guarantee that any action in base class Router\n // won't resolve the configurePromise prematurely\n const resolveConfiguredPromise = this._resolveConfiguredPromise;\n this._resolveConfiguredPromise = () => {/**/};\n return this\n .configure(config => {\n viewModel.configureRouter(config, this);\n return config;\n })\n .then(() => {\n this.activate();\n resolveConfiguredPromise();\n });\n }\n } else {\n this.activate();\n }\n }\n // when a viewport is added dynamically to a root view that is already activated\n // just process the navigation instruction\n else {\n this._dequeueInstruction();\n }\n\n return Promise.resolve();\n }\n\n /**\n * Activates the router. This instructs the router to begin listening for history changes and processing instructions.\n *\n * @params options The set of options to activate the router with.\n */\n activate(options?: NavigationOptions): void {\n if (this.isActive) {\n return;\n }\n\n this.isActive = true;\n // route handler property is responsible for handling url change\n // the interface of aurelia-history isn't clear on this perspective\n this.options = Object.assign({ routeHandler: this.loadUrl.bind(this) }, this.options, options);\n this.history.activate(this.options);\n this._dequeueInstruction();\n }\n\n /**\n * Deactivates the router.\n */\n deactivate(): void {\n this.isActive = false;\n this.history.deactivate();\n }\n\n /**@internal */\n _queueInstruction(instruction: NavigationInstruction): Promise {\n return new Promise((resolve) => {\n instruction.resolve = resolve;\n this._queue.unshift(instruction);\n this._dequeueInstruction();\n });\n }\n\n /**@internal */\n _dequeueInstruction(instructionCount: number = 0): Promise {\n return Promise.resolve().then(() => {\n if (this.isNavigating && !instructionCount) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n let instruction = this._queue.shift();\n this._queue.length = 0;\n\n if (!instruction) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n this.isNavigating = true;\n\n let navtracker: number = this.history.getState('NavigationTracker');\n if (!navtracker && !this.currentNavigationTracker) {\n this.isNavigatingFirst = true;\n this.isNavigatingNew = true;\n } else if (!navtracker) {\n this.isNavigatingNew = true;\n } else if (!this.currentNavigationTracker) {\n this.isNavigatingRefresh = true;\n } else if (this.currentNavigationTracker < navtracker) {\n this.isNavigatingForward = true;\n } else if (this.currentNavigationTracker > navtracker) {\n this.isNavigatingBack = true;\n } if (!navtracker) {\n navtracker = Date.now();\n this.history.setState('NavigationTracker', navtracker);\n }\n this.currentNavigationTracker = navtracker;\n\n instruction.previousInstruction = this.currentInstruction;\n\n if (!instructionCount) {\n this.events.publish(RouterEvent.Processing, { instruction });\n } else if (instructionCount === this.maxInstructionCount - 1) {\n logger.error(`${instructionCount + 1} navigation instructions have been attempted without success. Restoring last known good location.`);\n restorePreviousLocation(this);\n return this._dequeueInstruction(instructionCount + 1);\n } else if (instructionCount > this.maxInstructionCount) {\n throw new Error('Maximum navigation attempts exceeded. Giving up.');\n }\n\n let pipeline = this.pipelineProvider.createPipeline(!this.couldDeactivate);\n\n return pipeline\n .run(instruction)\n .then(result => processResult(instruction, result, instructionCount, this))\n .catch(error => {\n return { output: error instanceof Error ? error : new Error(error) } as PipelineResult;\n })\n .then(result => resolveInstruction(instruction, result, !!instructionCount, this));\n });\n }\n\n /**@internal */\n _findViewModel(viewPort: ViewPort): ConfiguresRouter | undefined {\n if (this.container.viewModel) {\n return this.container.viewModel;\n }\n\n if (viewPort.container) {\n let container = viewPort.container;\n\n while (container) {\n if (container.viewModel) {\n this.container.viewModel = container.viewModel;\n return container.viewModel;\n }\n\n container = container.parent;\n }\n }\n\n return undefined;\n }\n}\n\nconst processResult = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n instructionCount: number,\n router: AppRouter\n): Promise => {\n if (!(result && 'completed' in result && 'output' in result)) {\n result = result || {} as PipelineResult;\n result.output = new Error(`Expected router pipeline to return a navigation result, but got [${JSON.stringify(result)}] instead.`);\n }\n\n let finalResult: PipelineResult = null;\n let navigationCommandResult = null;\n if (isNavigationCommand(result.output)) {\n navigationCommandResult = result.output.navigate(router);\n } else {\n finalResult = result;\n\n if (!result.completed) {\n if (result.output instanceof Error) {\n logger.error(result.output.toString());\n }\n\n restorePreviousLocation(router);\n }\n }\n\n return Promise.resolve(navigationCommandResult)\n .then(_ => router._dequeueInstruction(instructionCount + 1))\n .then(innerResult => finalResult || innerResult || result);\n};\n\nconst resolveInstruction = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n isInnerInstruction: boolean,\n router: AppRouter\n): PipelineResult => {\n instruction.resolve(result);\n\n let eventArgs = { instruction, result };\n if (!isInnerInstruction) {\n router.isNavigating = false;\n router.isExplicitNavigation = false;\n router.isExplicitNavigationBack = false;\n router.isNavigatingFirst = false;\n router.isNavigatingNew = false;\n router.isNavigatingRefresh = false;\n router.isNavigatingForward = false;\n router.isNavigatingBack = false;\n router.couldDeactivate = false;\n\n let eventName: string;\n\n if (result.output instanceof Error) {\n eventName = RouterEvent.Error;\n } else if (!result.completed) {\n eventName = RouterEvent.Canceled;\n } else {\n let queryString = instruction.queryString ? ('?' + instruction.queryString) : '';\n router.history.previousLocation = instruction.fragment + queryString;\n eventName = RouterEvent.Success;\n }\n\n router.events.publish(eventName, eventArgs);\n router.events.publish(RouterEvent.Complete, eventArgs);\n } else {\n router.events.publish(RouterEvent.ChildComplete, eventArgs);\n }\n\n return result;\n};\n\nconst restorePreviousLocation = (router: AppRouter): void => {\n let previousLocation = router.history.previousLocation;\n if (previousLocation) {\n router.navigate(router.history.previousLocation, { trigger: false, replace: true });\n } else if (router.fallbackRoute) {\n router.navigate(router.fallbackRoute, { trigger: true, replace: true });\n } else {\n logger.error('Router navigation failed, and no previous location or fallbackRoute could be restored.');\n }\n};\n","/**\n* The status of a Pipeline.\n*/\nexport const enum PipelineStatus {\n Completed = 'completed',\n Canceled = 'canceled',\n Rejected = 'rejected',\n Running = 'running'\n}\n","/**\n * A list of known router events used by the Aurelia router\n * to signal the pipeline has come to a certain state\n */\n// const enum is preserved in tsconfig\nexport const enum RouterEvent {\n Processing = 'router:navigation:processing',\n Error = 'router:navigation:error',\n Canceled = 'router:navigation:canceled',\n Complete = 'router:navigation:complete',\n Success = 'router:navigation:success',\n ChildComplete = 'router:navigation:child:complete'\n}\n","/**\n * Available pipeline slot names to insert interceptor into router pipeline\n */\n// const enum is preserved in tsconfig\nexport const enum PipelineSlotName {\n /**\n * Authorization slot. Invoked early in the pipeline,\n * before `canActivate` hook of incoming route\n */\n Authorize = 'authorize',\n /**\n * Pre-activation slot. Invoked early in the pipeline,\n * Invoked timing:\n * - after Authorization slot\n * - after canActivate hook on new view model\n * - before deactivate hook on old view model\n * - before activate hook on new view model\n */\n PreActivate = 'preActivate',\n /**\n * Pre-render slot. Invoked later in the pipeline\n * Invokcation timing:\n * - after activate hook on new view model\n * - before commit step on new navigation instruction\n */\n PreRender = 'preRender',\n /**\n * Post-render slot. Invoked last in the pipeline\n */\n PostRender = 'postRender'\n}\n"],"names":["LogManager.getLogger"],"mappings":";;;;;;AAuBA;;;;;;AAMA,SAAgB,mBAAmB,CAAC,GAAQ;IAC1C,OAAO,GAAG,IAAI,OAAO,GAA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CAAC,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;KACzE;SAAM;QACL,MAAM,CAAC,KAAK,CAAC,wFAAwF,CAAC,CAAC;KACxG;CACF,CAAC;;AChUF;;;AAGA,IAAkB,cAKjB;AALD,WAAkB,cAAc;IAC9B,yCAAuB,CAAA;IACvB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,qCAAmB,CAAA;CACpB,EALiB,cAAc,KAAd,cAAc,QAK/B;;ACRD;;;;;AAKA,IAAkB,WAOjB;AAPD,WAAkB,WAAW;IAC3B,0DAA2C,CAAA;IAC3C,gDAAiC,CAAA;IACjC,sDAAuC,CAAA;IACvC,sDAAuC,CAAA;IACvC,oDAAqC,CAAA;IACrC,iEAAkD,CAAA;CACnD,EAPiB,WAAW,KAAX,WAAW,QAO5B;;ACZD;;;;AAIA,IAAkB,gBA0BjB;AA1BD,WAAkB,gBAAgB;;;;;IAKhC,2CAAuB,CAAA;;;;;;;;;IASvB,+CAA2B,CAAA;;;;;;;IAO3B,2CAAuB,CAAA;;;;IAIvB,6CAAyB,CAAA;CAC1B,EA1BiB,gBAAgB,KAAhB,gBAAgB,QA0BjC;;;;"} \ No newline at end of file +{"version":3,"file":"aurelia-router.js","sources":["../../src/navigation-instruction.ts","../../src/nav-model.ts","../../src/util.ts","../../src/router-configuration.ts","../../src/router.ts","../../src/next.ts","../../src/pipeline.ts","../../src/navigation-commands.ts","../../src/navigation-plan.ts","../../src/step-build-navigation-plan.ts","../../src/utilities-route-loading.ts","../../src/route-loader.ts","../../src/step-load-route.ts","../../src/step-commit-changes.ts","../../src/activation-strategy.ts","../../src/utilities-activation.ts","../../src/step-activation.ts","../../src/pipeline-provider.ts","../../src/app-router.ts","../../src/pipeline-status.ts","../../src/router-event.ts","../../src/pipeline-slot-name.ts"],"sourcesContent":["import { ViewPortInstruction, RouteConfig, ViewPort, LifecycleArguments, ViewPortComponent } from './interfaces';\nimport { Router } from './router';\nimport { ActivationStrategyType, InternalActivationStrategy } from './activation-strategy';\n\n/**\n * Initialization options for a navigation instruction\n */\nexport interface NavigationInstructionInit {\n fragment: string;\n queryString?: string;\n params?: Record;\n queryParams?: Record;\n config: RouteConfig;\n parentInstruction?: NavigationInstruction;\n previousInstruction?: NavigationInstruction;\n router: Router;\n options?: Object;\n plan?: Record;\n}\n\nexport interface ViewPortInstructionInit {\n name: string;\n strategy: ActivationStrategyType;\n moduleId: string;\n component: ViewPortComponent;\n}\n\n/**\n * Class used to represent an instruction during a navigation.\n */\nexport class NavigationInstruction {\n /**\n * The URL fragment.\n */\n fragment: string;\n\n /**\n * The query string.\n */\n queryString: string;\n\n /**\n * Parameters extracted from the route pattern.\n */\n params: any;\n\n /**\n * Parameters extracted from the query string.\n */\n queryParams: any;\n\n /**\n * The route config for the route matching this instruction.\n */\n config: RouteConfig;\n\n /**\n * The parent instruction, if this instruction was created by a child router.\n */\n parentInstruction: NavigationInstruction;\n\n parentCatchHandler: any;\n\n /**\n * The instruction being replaced by this instruction in the current router.\n */\n previousInstruction: NavigationInstruction;\n\n /**\n * viewPort instructions to used activation.\n */\n viewPortInstructions: Record;\n\n /**\n * The router instance.\n */\n router: Router;\n\n /**\n * Current built viewport plan of this nav instruction\n */\n plan: Record = null;\n\n options: Record = {};\n\n /**@internal */\n lifecycleArgs: LifecycleArguments;\n /**@internal */\n resolve?: (val?: any) => void;\n\n constructor(init: NavigationInstructionInit) {\n Object.assign(this, init);\n\n this.params = this.params || {};\n this.viewPortInstructions = {};\n\n let ancestorParams = [];\n let current: NavigationInstruction = this;\n do {\n let currentParams = Object.assign({}, current.params);\n if (current.config && current.config.hasChildRouter) {\n // remove the param for the injected child route segment\n delete currentParams[current.getWildCardName()];\n }\n\n ancestorParams.unshift(currentParams);\n current = current.parentInstruction;\n } while (current);\n\n let allParams = Object.assign({}, this.queryParams, ...ancestorParams);\n this.lifecycleArgs = [allParams, this.config, this];\n }\n\n /**\n * Gets an array containing this instruction and all child instructions for the current navigation.\n */\n getAllInstructions(): Array {\n let instructions: NavigationInstruction[] = [this];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let key in viewPortInstructions) {\n let childInstruction = viewPortInstructions[key].childNavigationInstruction;\n if (childInstruction) {\n instructions.push(...childInstruction.getAllInstructions());\n }\n }\n\n return instructions;\n }\n\n /**\n * Gets an array containing the instruction and all child instructions for the previous navigation.\n * Previous instructions are no longer available after navigation completes.\n */\n getAllPreviousInstructions(): Array {\n return this.getAllInstructions().map(c => c.previousInstruction).filter(c => c);\n }\n\n /**\n * Adds a viewPort instruction. Returns the newly created instruction based on parameters\n */\n addViewPortInstruction(initOptions: ViewPortInstructionInit): /*ViewPortInstruction*/ any;\n addViewPortInstruction(viewPortName: string, strategy: ActivationStrategyType, moduleId: string, component: any): /*ViewPortInstruction*/ any;\n addViewPortInstruction(\n nameOrInitOptions: string | ViewPortInstructionInit,\n strategy?: ActivationStrategyType,\n moduleId?: string,\n component?: any\n ): /*ViewPortInstruction*/ any {\n\n let viewPortInstruction: ViewPortInstruction;\n let viewPortName = typeof nameOrInitOptions === 'string' ? nameOrInitOptions : nameOrInitOptions.name;\n const lifecycleArgs = this.lifecycleArgs;\n const config: RouteConfig = Object.assign({}, lifecycleArgs[1], { currentViewPort: viewPortName });\n\n if (typeof nameOrInitOptions === 'string') {\n viewPortInstruction = {\n name: nameOrInitOptions,\n strategy: strategy,\n moduleId: moduleId,\n component: component,\n childRouter: component.childRouter,\n lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] as LifecycleArguments\n };\n } else {\n viewPortInstruction = {\n name: viewPortName,\n strategy: nameOrInitOptions.strategy,\n component: nameOrInitOptions.component,\n moduleId: nameOrInitOptions.moduleId,\n childRouter: nameOrInitOptions.component.childRouter,\n lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] as LifecycleArguments\n };\n }\n\n return this.viewPortInstructions[viewPortName] = viewPortInstruction;\n }\n\n /**\n * Gets the name of the route pattern's wildcard parameter, if applicable.\n */\n getWildCardName(): string {\n // todo: potential issue, or at least unsafe typings\n let configRoute = this.config.route as string;\n let wildcardIndex = configRoute.lastIndexOf('*');\n return configRoute.substr(wildcardIndex + 1);\n }\n\n /**\n * Gets the path and query string created by filling the route\n * pattern's wildcard parameter with the matching param.\n */\n getWildcardPath(): string {\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n let queryString = this.queryString;\n\n if (queryString) {\n path += '?' + queryString;\n }\n\n return path;\n }\n\n /**\n * Gets the instruction's base URL, accounting for wildcard route parameters.\n */\n getBaseUrl(): string {\n let $encodeURI = encodeURI;\n let fragment = decodeURI(this.fragment);\n\n if (fragment === '') {\n let nonEmptyRoute = this.router.routes.find(route => {\n return route.name === this.config.name &&\n route.route !== '';\n });\n if (nonEmptyRoute) {\n fragment = nonEmptyRoute.route as any;\n }\n }\n\n if (!this.params) {\n return $encodeURI(fragment);\n }\n\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n\n if (!path) {\n return $encodeURI(fragment);\n }\n\n return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path)));\n }\n\n /**\n * Finalize a viewport instruction\n * @internal\n */\n _commitChanges(waitToSwap: boolean): Promise {\n let router = this.router;\n router.currentInstruction = this;\n\n const previousInstruction = this.previousInstruction;\n if (previousInstruction) {\n previousInstruction.config.navModel.isActive = false;\n }\n\n this.config.navModel.isActive = true;\n\n router.refreshNavigation();\n\n let loads: Promise[] = [];\n let delaySwaps: ISwapPlan[] = [];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let viewPort = router.viewPorts[viewPortName];\n\n if (!viewPort) {\n throw new Error(`There was no router-view found in the view for ${viewPortInstruction.moduleId}.`);\n }\n\n let childNavInstruction = viewPortInstruction.childNavigationInstruction;\n if (viewPortInstruction.strategy === InternalActivationStrategy.Replace) {\n if (childNavInstruction && childNavInstruction.parentCatchHandler) {\n loads.push(childNavInstruction._commitChanges(waitToSwap));\n } else {\n if (waitToSwap) {\n delaySwaps.push({ viewPort, viewPortInstruction });\n }\n loads.push(\n viewPort\n .process(viewPortInstruction, waitToSwap)\n .then(() => childNavInstruction\n ? childNavInstruction._commitChanges(waitToSwap)\n : Promise.resolve()\n )\n );\n }\n } else {\n if (childNavInstruction) {\n loads.push(childNavInstruction._commitChanges(waitToSwap));\n }\n }\n }\n\n return Promise\n .all(loads)\n .then(() => {\n delaySwaps.forEach(x => x.viewPort.swap(x.viewPortInstruction));\n return null;\n })\n .then(() => prune(this));\n }\n\n /**@internal */\n _updateTitle(): void {\n let router = this.router;\n let title = this._buildTitle(router.titleSeparator);\n if (title) {\n router.history.setTitle(title);\n }\n }\n\n /**@internal */\n _buildTitle(separator: string = ' | '): string {\n let title = '';\n let childTitles = [];\n let navModelTitle = this.config.navModel.title;\n let instructionRouter = this.router;\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n if (navModelTitle) {\n title = instructionRouter.transformTitle(navModelTitle);\n }\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n\n if (child_nav_instruction) {\n let childTitle = child_nav_instruction._buildTitle(separator);\n if (childTitle) {\n childTitles.push(childTitle);\n }\n }\n }\n\n if (childTitles.length) {\n title = childTitles.join(separator) + (title ? separator : '') + title;\n }\n\n if (instructionRouter.title) {\n title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title);\n }\n\n return title;\n }\n}\n\nconst prune = (instruction: NavigationInstruction): void => {\n instruction.previousInstruction = null;\n instruction.plan = null;\n};\n\ninterface ISwapPlan {\n viewPort: ViewPort;\n viewPortInstruction: ViewPortInstruction;\n}\n","import { Router } from './router';\nimport { RouteConfig } from './interfaces';\n\n/**\n* Class for storing and interacting with a route's navigation settings.\n*/\nexport class NavModel {\n\n /**\n * True if this nav item is currently active.\n */\n isActive: boolean = false;\n\n /**\n * The title.\n */\n title: string = null;\n\n /**\n * This nav item's absolute href.\n */\n href: string = null;\n\n /**\n * This nav item's relative href.\n */\n relativeHref: string = null;\n\n /**\n * Data attached to the route at configuration time.\n */\n settings: any = {};\n\n /**\n * The route config.\n */\n config: RouteConfig = null;\n\n /**\n * The router associated with this navigation model.\n */\n router: Router;\n\n order: number | boolean;\n\n constructor(router: Router, relativeHref: string) {\n this.router = router;\n this.relativeHref = relativeHref;\n }\n\n /**\n * Sets the route's title and updates document.title.\n * If the a navigation is in progress, the change will be applied\n * to document.title when the navigation completes.\n *\n * @param title The new title.\n */\n setTitle(title: string): void {\n this.title = title;\n\n if (this.isActive) {\n this.router.updateTitle();\n }\n }\n}\n","import { RouteConfig } from './interfaces';\n\nexport function _normalizeAbsolutePath(path: string, hasPushState: boolean, absolute: boolean = false) {\n if (!hasPushState && path[0] !== '#') {\n path = '#' + path;\n }\n\n if (hasPushState && absolute) {\n path = path.substring(1, path.length);\n }\n\n return path;\n}\n\nexport function _createRootedPath(fragment: string, baseUrl: string, hasPushState: boolean, absolute?: boolean) {\n if (isAbsoluteUrl.test(fragment)) {\n return fragment;\n }\n\n let path = '';\n\n if (baseUrl.length && baseUrl[0] !== '/') {\n path += '/';\n }\n\n path += baseUrl;\n\n if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') {\n path += '/';\n }\n\n if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') {\n path = path.substring(0, path.length - 1);\n }\n\n return _normalizeAbsolutePath(path + fragment, hasPushState, absolute);\n}\n\nexport function _resolveUrl(fragment: string, baseUrl: string, hasPushState?: boolean) {\n if (isRootedPath.test(fragment)) {\n return _normalizeAbsolutePath(fragment, hasPushState);\n }\n\n return _createRootedPath(fragment, baseUrl, hasPushState);\n}\n\nexport function _ensureArrayWithSingleRoutePerConfig(config: RouteConfig) {\n let routeConfigs = [];\n\n if (Array.isArray(config.route)) {\n for (let i = 0, ii = config.route.length; i < ii; ++i) {\n let current = Object.assign({}, config);\n current.route = config.route[i];\n routeConfigs.push(current);\n }\n } else {\n routeConfigs.push(Object.assign({}, config));\n }\n\n return routeConfigs;\n}\n\nconst isRootedPath = /^#?\\//;\nconst isAbsoluteUrl = /^([a-z][a-z0-9+\\-.]*:)?\\/\\//i;\n","import { RouteConfig, PipelineStep, RouteConfigSpecifier } from './interfaces';\nimport { _ensureArrayWithSingleRoutePerConfig } from './util';\nimport { Router } from './router';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * Class used to configure a [[Router]] instance.\n *\n * @constructor\n */\nexport class RouterConfiguration {\n instructions: Array<(router: Router) => void> = [];\n options: {\n [key: string]: any;\n compareQueryParams?: boolean;\n root?: string;\n pushState?: boolean;\n hashChange?: boolean;\n silent?: boolean;\n } = {};\n pipelineSteps: Array<{ name: string, step: Function | PipelineStep }> = [];\n title: string;\n titleSeparator: string;\n unknownRouteConfig: RouteConfigSpecifier;\n viewPortDefaults: Record;\n\n /**@internal */\n _fallbackRoute: string;\n\n /**\n * Adds a step to be run during the [[Router]]'s navigation pipeline.\n *\n * @param name The name of the pipeline slot to insert the step into.\n * @param step The pipeline step.\n * @chainable\n */\n addPipelineStep(name: string, step: Function | PipelineStep): RouterConfiguration {\n if (step === null || step === undefined) {\n throw new Error('Pipeline step cannot be null or undefined.');\n }\n this.pipelineSteps.push({ name, step });\n return this;\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s authorize pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addAuthorizeStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.Authorize, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preActivate pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreActivateStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreActivate, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreRender, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s postRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPostRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PostRender, step);\n }\n\n /**\n * Configures a route that will be used if there is no previous location available on navigation cancellation.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @chainable\n */\n fallbackRoute(fragment: string): RouterConfiguration {\n this._fallbackRoute = fragment;\n return this;\n }\n\n /**\n * Maps one or more routes to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map.\n * @chainable\n */\n map(route: RouteConfig | RouteConfig[]): RouterConfiguration {\n if (Array.isArray(route)) {\n route.forEach(r => this.map(r));\n return this;\n }\n\n return this.mapRoute(route);\n }\n\n /**\n * Configures defaults to use for any view ports.\n *\n * @param viewPortConfig a view port configuration object to use as a\n * default, of the form { viewPortName: { moduleId } }.\n * @chainable\n */\n useViewPortDefaults(viewPortConfig: Record): RouterConfiguration {\n this.viewPortDefaults = viewPortConfig;\n return this;\n }\n\n /**\n * Maps a single route to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map.\n * @chainable\n */\n mapRoute(config: RouteConfig): RouterConfiguration {\n this.instructions.push(router => {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n\n let navModel;\n for (let i = 0, ii = routeConfigs.length; i < ii; ++i) {\n let routeConfig = routeConfigs[i];\n routeConfig.settings = routeConfig.settings || {};\n if (!navModel) {\n navModel = router.createNavModel(routeConfig);\n }\n\n router.addRoute(routeConfig, navModel);\n }\n });\n\n return this;\n }\n\n /**\n * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes.\n *\n * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the\n * [[NavigationInstruction]] and selects a moduleId to load.\n * @chainable\n */\n mapUnknownRoutes(config: RouteConfigSpecifier): RouterConfiguration {\n this.unknownRouteConfig = config;\n return this;\n }\n\n /**\n * Applies the current configuration to the specified [[Router]].\n *\n * @param router The [[Router]] to apply the configuration to.\n */\n exportToRouter(router: Router): void {\n let instructions = this.instructions;\n for (let i = 0, ii = instructions.length; i < ii; ++i) {\n instructions[i](router);\n }\n\n let { title, titleSeparator, unknownRouteConfig, _fallbackRoute, viewPortDefaults } = this;\n\n if (title) {\n router.title = title;\n }\n\n if (titleSeparator) {\n router.titleSeparator = titleSeparator;\n }\n\n if (unknownRouteConfig) {\n router.handleUnknownRoutes(unknownRouteConfig);\n }\n\n if (_fallbackRoute) {\n router.fallbackRoute = _fallbackRoute;\n }\n\n if (viewPortDefaults) {\n router.useViewPortDefaults(viewPortDefaults);\n }\n\n Object.assign(router.options, this.options);\n\n let pipelineSteps = this.pipelineSteps;\n let pipelineStepCount = pipelineSteps.length;\n if (pipelineStepCount) {\n if (!router.isRoot) {\n throw new Error('Pipeline steps can only be added to the root router');\n }\n\n let pipelineProvider = router.pipelineProvider;\n for (let i = 0, ii = pipelineStepCount; i < ii; ++i) {\n let { name, step } = pipelineSteps[i];\n pipelineProvider.addStep(name, step);\n }\n }\n }\n}\n","import { RouteRecognizer, RouteHandler, ConfigurableRoute, State, RecognizedRoute } from 'aurelia-route-recognizer';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { NavigationInstruction, NavigationInstructionInit } from './navigation-instruction';\nimport { NavModel } from './nav-model';\nimport { RouterConfiguration } from './router-configuration';\nimport {\n _ensureArrayWithSingleRoutePerConfig,\n _normalizeAbsolutePath,\n _createRootedPath,\n _resolveUrl\n} from './util';\nimport { RouteConfig, RouteConfigSpecifier, ViewPortInstruction } from './interfaces';\nimport { PipelineProvider } from './pipeline-provider';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface History {\n // This is wrong, as it's an implementation detail from aurelia-history-browser\n // but we are poking it in here so probably will need to make it official in `aurelia-history`\n /**\n * A private flag of Aurelia History implementation to indicate if push state should be used\n */\n _hasPushState: boolean;\n\n previousLocation: string;\n }\n}\n\n/**@internal */\ndeclare module 'aurelia-route-recognizer' {\n interface State {\n types: {\n dynamics: DynamicSegment;\n stars: StarSegment;\n };\n }\n\n interface RouteHandler {\n navigationStrategy?: (instruction: NavigationInstruction) => any;\n }\n\n interface RecognizedRoute {\n config?: RouteConfig;\n queryParams?: Record;\n }\n}\n\ntype RouterConfigurationResolution = RouterConfiguration | ((cfg: RouterConfiguration) => void | RouterConfiguration | Promise);\n\n/**\n * The primary class responsible for handling routing and navigation.\n */\nexport class Router {\n\n /**\n * Container associated with this router. Also used to create child container for creating child router.\n */\n container: Container;\n\n /**\n * History instance of Aurelia abstract class for wrapping platform history global object\n */\n history: History;\n\n /**\n * A registry of registered viewport. Will be used to handle process navigation instruction route loading\n * and dom swapping\n */\n viewPorts: Record;\n\n /**\n * List of route configs registered with this router\n */\n routes: RouteConfig[];\n\n /**\n * The [[Router]]'s current base URL, typically based on the [[Router.currentInstruction]].\n */\n baseUrl: string;\n\n /**\n * If defined, used in generation of document title for [[Router]]'s routes.\n */\n title: string | undefined;\n\n /**\n * The separator used in the document title between [[Router]]'s routes.\n */\n titleSeparator: string | undefined;\n\n /**\n * True if the [[Router]] has been configured.\n */\n isConfigured: boolean;\n\n /**\n * True if the [[Router]] is currently processing a navigation.\n */\n isNavigating: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigate function(s).\n */\n isExplicitNavigation: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigateBack function.\n */\n isExplicitNavigationBack: boolean;\n\n /**\n * True if the [[Router]] is navigating into the app for the first time in the browser session.\n */\n isNavigatingFirst: boolean;\n\n /**\n * True if the [[Router]] is navigating to a page instance not in the browser session history.\n */\n isNavigatingNew: boolean;\n\n /**\n * True if the [[Router]] is navigating forward in the browser session history.\n */\n isNavigatingForward: boolean;\n\n /**\n * True if the [[Router]] is navigating back in the browser session history.\n */\n isNavigatingBack: boolean;\n\n /**\n * True if the [[Router]] is navigating due to a browser refresh.\n */\n isNavigatingRefresh: boolean;\n\n /**\n * True if the previous instruction successfully completed the CanDeactivatePreviousStep in the current navigation.\n */\n couldDeactivate: boolean;\n\n /**\n * The currently active navigation tracker.\n */\n currentNavigationTracker: number;\n\n /**\n * The navigation models for routes that specified [[RouteConfig.nav]].\n */\n navigation: NavModel[];\n\n /**\n * The currently active navigation instruction.\n */\n currentInstruction: NavigationInstruction;\n\n /**\n * The parent router, or null if this instance is not a child router.\n */\n parent: Router = null;\n\n options: any = {};\n\n /**\n * The defaults used when a viewport lacks specified content\n */\n viewPortDefaults: Record = {};\n\n /**@internal */\n catchAllHandler: (instruction: NavigationInstruction) => NavigationInstruction | Promise;\n /**@internal */\n fallbackRoute: string;\n /**@internal */\n pipelineProvider: PipelineProvider;\n /**@internal */\n _fallbackOrder: number;\n /**@internal */\n _recognizer: RouteRecognizer;\n /**@internal */\n _childRecognizer: RouteRecognizer;\n /**@internal */\n _configuredPromise: Promise;\n /**@internal */\n _resolveConfiguredPromise: (value?: any) => void;\n\n /**\n * Extension point to transform the document title before it is built and displayed.\n * By default, child routers delegate to the parent router, and the app router\n * returns the title unchanged.\n */\n transformTitle: (title: string) => string = (title: string) => {\n if (this.parent) {\n return this.parent.transformTitle(title);\n }\n return title;\n }\n\n /**\n * @param container The [[Container]] to use when child routers.\n * @param history The [[History]] implementation to delegate navigation requests to.\n */\n constructor(container: Container, history: History) {\n this.container = container;\n this.history = history;\n this.reset();\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset() {\n this.viewPorts = {};\n this.routes = [];\n this.baseUrl = '';\n this.isConfigured = false;\n this.isNavigating = false;\n this.isExplicitNavigation = false;\n this.isExplicitNavigationBack = false;\n this.isNavigatingFirst = false;\n this.isNavigatingNew = false;\n this.isNavigatingRefresh = false;\n this.isNavigatingForward = false;\n this.isNavigatingBack = false;\n this.couldDeactivate = false;\n this.navigation = [];\n this.currentInstruction = null;\n this.viewPortDefaults = {};\n this._fallbackOrder = 100;\n this._recognizer = new RouteRecognizer();\n this._childRecognizer = new RouteRecognizer();\n this._configuredPromise = new Promise(resolve => {\n this._resolveConfiguredPromise = resolve;\n });\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent.\n */\n get isRoot(): boolean {\n return !this.parent;\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort.\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/any, name?: string): void {\n name = name || 'default';\n this.viewPorts[name] = viewPort;\n }\n\n /**\n * Returns a Promise that resolves when the router is configured.\n */\n ensureConfigured(): Promise {\n return this._configuredPromise;\n }\n\n /**\n * Configures the router.\n *\n * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]].\n */\n configure(callbackOrConfig: RouterConfiguration | ((config: RouterConfiguration) => RouterConfiguration)): Promise {\n this.isConfigured = true;\n\n let result: RouterConfigurationResolution = callbackOrConfig as RouterConfiguration;\n let config: RouterConfiguration;\n if (typeof callbackOrConfig === 'function') {\n config = new RouterConfiguration();\n result = callbackOrConfig(config);\n }\n\n return Promise\n .resolve(result)\n .then((c) => {\n if (c && (c as RouterConfiguration).exportToRouter) {\n config = c;\n }\n\n config.exportToRouter(this);\n this.isConfigured = true;\n this._resolveConfiguredPromise();\n });\n }\n\n /**\n * Navigates to a new location.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n navigate(fragment: string, options?: NavigationOptions): boolean {\n if (!this.isConfigured && this.parent) {\n return this.parent.navigate(fragment, options);\n }\n\n this.isExplicitNavigation = true;\n return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options);\n }\n\n /**\n * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed\n * by [[Router.navigate]].\n *\n * @param route The name of the route to use when generating the navigation location.\n * @param params The route parameters to be used when populating the route pattern.\n * @param options The navigation options.\n */\n navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean {\n let path = this.generate(route, params);\n return this.navigate(path, options);\n }\n\n /**\n * Navigates back to the most recent location in history.\n */\n navigateBack(): void {\n this.isExplicitNavigationBack = true;\n this.history.navigateBack();\n }\n\n /**\n * Creates a child router of the current router.\n *\n * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified.\n * @returns {Router} The new child Router.\n */\n createChild(container?: Container): Router {\n let childRouter = new Router(container || this.container.createChild(), this.history);\n childRouter.parent = this;\n return childRouter;\n }\n\n /**\n * Generates a URL fragment matching the specified route pattern.\n *\n * @param name The name of the route whose pattern should be used to generate the fragment.\n * @param params The route params to be used to populate the route pattern.\n * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url.\n * @returns {string} A string containing the generated URL fragment.\n */\n generate(nameOrRoute: string | RouteConfig, params: any = {}, options: any = {}): string {\n // A child recognizer generates routes for potential child routes. Any potential child route is added\n // to the childRoute property of params for the childRouter to recognize. When generating routes, we\n // use the childRecognizer when childRoute params are available to generate a child router enabled route.\n let recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer;\n let hasRoute = recognizer.hasRoute(nameOrRoute as string | RouteHandler);\n if (!hasRoute) {\n if (this.parent) {\n return this.parent.generate(nameOrRoute, params, options);\n }\n throw new Error(`A route with name '${nameOrRoute}' could not be found. Check that \\`name: '${nameOrRoute}'\\` was specified in the route's config.`);\n }\n let path = recognizer.generate(nameOrRoute as string | RouteHandler, params);\n let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute);\n return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath;\n }\n\n /**\n * Creates a [[NavModel]] for the specified route config.\n *\n * @param config The route config.\n */\n createNavModel(config: RouteConfig): NavModel {\n let navModel = new NavModel(\n this,\n 'href' in config\n ? config.href\n // potential error when config.route is a string[] ?\n : config.route as string);\n navModel.title = config.title;\n navModel.order = config.nav;\n navModel.href = config.href;\n navModel.settings = config.settings;\n navModel.config = config;\n\n return navModel;\n }\n\n /**\n * Registers a new route with the router.\n *\n * @param config The [[RouteConfig]].\n * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes.\n */\n addRoute(config: RouteConfig, navModel?: NavModel): void {\n if (Array.isArray(config.route)) {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n // the following is wrong. todo: fix this after TS refactoring release\n routeConfigs.forEach(this.addRoute.bind(this));\n return;\n }\n\n validateRouteConfig(config);\n\n if (!('viewPorts' in config) && !config.navigationStrategy) {\n config.viewPorts = {\n 'default': {\n moduleId: config.moduleId,\n view: config.view\n }\n };\n }\n\n if (!navModel) {\n navModel = this.createNavModel(config);\n }\n\n this.routes.push(config);\n\n let path = config.route;\n if (path.charAt(0) === '/') {\n path = path.substr(1);\n }\n let caseSensitive = config.caseSensitive === true;\n let state: State = this._recognizer.add({\n path: path,\n handler: config as RouteHandler,\n caseSensitive: caseSensitive\n } as ConfigurableRoute);\n\n if (path) {\n let settings = config.settings;\n delete config.settings;\n let withChild = JSON.parse(JSON.stringify(config));\n config.settings = settings;\n withChild.route = `${path}/*childRoute`;\n withChild.hasChildRouter = true;\n this._childRecognizer.add({\n path: withChild.route,\n handler: withChild,\n caseSensitive: caseSensitive\n });\n\n withChild.navModel = navModel;\n withChild.settings = config.settings;\n withChild.navigationStrategy = config.navigationStrategy;\n }\n\n config.navModel = navModel;\n\n let navigation = this.navigation;\n\n if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) {\n if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) {\n throw new Error('Invalid route config for \"' + config.route + '\" : dynamic routes must specify an \"href:\" to be included in the navigation model.');\n }\n\n if (typeof navModel.order !== 'number') {\n navModel.order = ++this._fallbackOrder;\n }\n\n navigation.push(navModel);\n // this is a potential error / inconsistency between browsers\n //\n // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\n // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other,\n // but sorted with respect to all different elements.\n // Note: the ECMAscript standard does not guarantee this behaviour,\n // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.\n navigation.sort((a, b) => a.order - b.order);\n }\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasRoute(name: string): boolean {\n return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name));\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasOwnRoute(name: string): boolean {\n return this._recognizer.hasRoute(name);\n }\n\n /**\n * Register a handler to use when the incoming URL fragment doesn't match any registered routes.\n *\n * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]].\n */\n handleUnknownRoutes(config?: RouteConfigSpecifier): void {\n if (!config) {\n throw new Error('Invalid unknown route handler');\n }\n\n this.catchAllHandler = instruction => {\n return this\n ._createRouteConfig(config, instruction)\n .then(c => {\n instruction.config = c;\n return instruction;\n });\n };\n }\n\n /**\n * Updates the document title using the current navigation instruction.\n */\n updateTitle(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n return parentRouter.updateTitle();\n }\n\n let currentInstruction = this.currentInstruction;\n if (currentInstruction) {\n currentInstruction._updateTitle();\n }\n return undefined;\n }\n\n /**\n * Updates the navigation routes with hrefs relative to the current location.\n * Note: This method will likely move to a plugin in a future release.\n */\n refreshNavigation(): void {\n let nav = this.navigation;\n\n for (let i = 0, length = nav.length; i < length; i++) {\n let current = nav[i];\n if (!current.config.href) {\n current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState);\n } else {\n current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState);\n }\n }\n }\n\n /**\n * Sets the default configuration for the view ports. This specifies how to\n * populate a view port for which no module is specified. The default is\n * an empty view/view-model pair.\n */\n useViewPortDefaults($viewPortDefaults: Record): void {\n // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction\n let viewPortDefaults: Record = $viewPortDefaults;\n for (let viewPortName in viewPortDefaults) {\n let viewPortConfig = viewPortDefaults[viewPortName];\n this.viewPortDefaults[viewPortName] = {\n moduleId: viewPortConfig.moduleId\n };\n }\n }\n\n /**@internal */\n _refreshBaseUrl(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction);\n }\n }\n\n /**@internal */\n _createNavigationInstruction(url: string = '', parentInstruction: NavigationInstruction = null): Promise {\n let fragment = url;\n let queryString = '';\n\n let queryIndex = url.indexOf('?');\n if (queryIndex !== -1) {\n fragment = url.substr(0, queryIndex);\n queryString = url.substr(queryIndex + 1);\n }\n\n let urlRecognizationResults = this._recognizer.recognize(url) as IRouteRecognizationResults;\n if (!urlRecognizationResults || !urlRecognizationResults.length) {\n urlRecognizationResults = this._childRecognizer.recognize(url) as IRouteRecognizationResults;\n }\n\n let instructionInit: NavigationInstructionInit = {\n fragment,\n queryString,\n config: null,\n parentInstruction,\n previousInstruction: this.currentInstruction,\n router: this,\n options: {\n compareQueryParams: this.options.compareQueryParams\n }\n };\n\n let result: Promise;\n\n if (urlRecognizationResults && urlRecognizationResults.length) {\n let first = urlRecognizationResults[0];\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: first.params,\n queryParams: first.queryParams || urlRecognizationResults.queryParams,\n config: first.config || first.handler\n }));\n\n if (typeof first.handler === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler, first);\n } else if (first.handler && typeof first.handler.navigationStrategy === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler);\n } else {\n result = Promise.resolve(instruction);\n }\n } else if (this.catchAllHandler) {\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n config: null // config will be created by the catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, this.catchAllHandler);\n } else if (this.parent) {\n let router = this._parentCatchAllHandler(this.parent);\n\n if (router) {\n let newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction);\n\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n router: router,\n parentInstruction: newParentInstruction,\n parentCatchHandler: true,\n config: null // config will be created by the chained parent catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, router.catchAllHandler);\n }\n }\n\n if (result && parentInstruction) {\n this.baseUrl = generateBaseUrl(this.parent, parentInstruction);\n }\n\n return result || Promise.reject(new Error(`Route not found: ${url}`));\n }\n\n /**@internal */\n _findParentInstructionFromRouter(router: Router, instruction: NavigationInstruction): NavigationInstruction {\n if (instruction.router === router) {\n instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId\n return instruction;\n } else if (instruction.parentInstruction) {\n return this._findParentInstructionFromRouter(router, instruction.parentInstruction);\n }\n return undefined;\n }\n\n /**@internal */\n _parentCatchAllHandler(router: Router): Router | false {\n if (router.catchAllHandler) {\n return router;\n } else if (router.parent) {\n return this._parentCatchAllHandler(router.parent);\n }\n return false;\n }\n\n /**\n * @internal\n */\n _createRouteConfig(config: RouteConfigSpecifier, instruction: NavigationInstruction): Promise {\n return Promise\n .resolve(config)\n .then((c: any) => {\n if (typeof c === 'string') {\n return { moduleId: c } as RouteConfig;\n } else if (typeof c === 'function') {\n return c(instruction);\n }\n\n return c;\n })\n // typing here could be either RouteConfig or RedirectConfig\n // but temporarily treat both as RouteConfig\n // todo: improve typings precision\n .then((c: string | RouteConfig) => typeof c === 'string' ? { moduleId: c } as RouteConfig : c)\n .then((c: RouteConfig) => {\n c.route = instruction.params.path;\n validateRouteConfig(c);\n\n if (!c.navModel) {\n c.navModel = this.createNavModel(c);\n }\n\n return c;\n });\n }\n}\n\n/* @internal exported for unit testing */\nexport const generateBaseUrl = (router: Router, instruction: NavigationInstruction): string => {\n return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`;\n};\n\n/* @internal exported for unit testing */\nexport const validateRouteConfig = (config: RouteConfig): void => {\n if (typeof config !== 'object') {\n throw new Error('Invalid Route Config');\n }\n\n if (typeof config.route !== 'string') {\n let name = config.name || '(no name)';\n throw new Error('Invalid Route Config for \"' + name + '\": You must specify a \"route:\" pattern.');\n }\n\n if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) {\n throw new Error('Invalid Route Config for \"' + config.route + '\": You must specify a \"moduleId:\", \"redirect:\", \"navigationStrategy:\", or \"viewPorts:\".');\n }\n};\n\n/* @internal exported for unit testing */\nexport const evaluateNavigationStrategy = (\n instruction: NavigationInstruction,\n evaluator: Function,\n context?: any\n): Promise => {\n return Promise\n .resolve(evaluator.call(context, instruction))\n .then(() => {\n if (!('viewPorts' in instruction.config)) {\n instruction.config.viewPorts = {\n 'default': {\n moduleId: instruction.config.moduleId\n }\n };\n }\n\n return instruction;\n });\n};\n\ninterface IRouteRecognizationResults extends Array {\n queryParams: Record;\n}\n","import { PipelineStatus } from './pipeline-status';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Next, StepRunnerFunction, NextCompletionHandler } from './interfaces';\n\n/**@internal exported for unit testing */\nexport const createNextFn = (instruction: NavigationInstruction, steps: StepRunnerFunction[]): Next => {\n let index = -1;\n const next: Next = function() {\n index++;\n\n if (index < steps.length) {\n let currentStep = steps[index];\n\n try {\n return currentStep(instruction, next);\n } catch (e) {\n return next.reject(e);\n }\n } else {\n return next.complete();\n }\n } as Next;\n\n next.complete = createCompletionHandler(next, PipelineStatus.Completed);\n next.cancel = createCompletionHandler(next, PipelineStatus.Canceled);\n next.reject = createCompletionHandler(next, PipelineStatus.Rejected);\n\n return next;\n};\n\n/**@internal exported for unit testing */\nexport const createCompletionHandler = (next: Next, status: PipelineStatus): NextCompletionHandler => {\n return (output: any) => Promise\n .resolve({\n status,\n output,\n completed: status === PipelineStatus.Completed\n });\n};\n","import { PipelineStep, PipelineResult, Next, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { createNextFn } from './next';\n\n/**\n * The class responsible for managing and processing the navigation pipeline.\n */\nexport class Pipeline {\n /**\n * The pipeline steps. And steps added via addStep will be converted to a function\n * The actualy running functions with correct step contexts of this pipeline\n */\n steps: StepRunnerFunction[] = [];\n\n /**\n * Adds a step to the pipeline.\n *\n * @param step The pipeline step.\n */\n addStep(step: StepRunnerFunction | PipelineStep | IPipelineSlot): Pipeline {\n let run;\n\n if (typeof step === 'function') {\n run = step;\n } else if (typeof step.getSteps === 'function') {\n // getSteps is to enable support open slots\n // where devs can add multiple steps into the same slot name\n let steps = step.getSteps();\n for (let i = 0, l = steps.length; i < l; i++) {\n this.addStep(steps[i]);\n }\n\n return this;\n } else {\n run = (step as PipelineStep).run.bind(step);\n }\n\n this.steps.push(run);\n\n return this;\n }\n\n /**\n * Runs the pipeline.\n *\n * @param instruction The navigation instruction to process.\n */\n run(instruction: NavigationInstruction): Promise {\n const nextFn = createNextFn(instruction, this.steps);\n return nextFn();\n }\n}\n","import { NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface NavigationOptions {\n useAppRouter?: boolean;\n }\n}\n\n/**\n* When a navigation command is encountered, the current navigation\n* will be cancelled and control will be passed to the navigation\n* command so it can determine the correct action.\n*/\nexport interface NavigationCommand {\n navigate: (router: Router) => void;\n /**@internal */\n shouldContinueProcessing?: boolean;\n /**@internal */\n setRouter?: (router: Router) => void;\n}\n\n/**\n* Determines if the provided object is a navigation command.\n* A navigation command is anything with a navigate method.\n*\n* @param obj The object to check.\n*/\nexport function isNavigationCommand(obj: any): obj is NavigationCommand {\n return obj && typeof obj.navigate === 'function';\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect.\n*/\nexport class Redirect implements NavigationCommand {\n\n url: string;\n /**@internal */\n options: NavigationOptions;\n /**@internal */\n shouldContinueProcessing: boolean;\n\n private router: Router;\n\n /**\n * @param url The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n constructor(url: string, options: NavigationOptions = {}) {\n this.url = url;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigate(this.url, this.options);\n }\n}\n\n/**\n * Used during the activation lifecycle to cause a redirect to a named route.\n */\nexport class RedirectToRoute implements NavigationCommand {\n\n route: string;\n params: any;\n /**@internal */\n options: NavigationOptions;\n\n /**@internal */\n shouldContinueProcessing: boolean;\n\n /**@internal */\n router: Router;\n\n /**\n * @param route The name of the route.\n * @param params The parameters to be sent to the activation method.\n * @param options The options to use for navigation.\n */\n constructor(route: string, params: any = {}, options: NavigationOptions = {}) {\n this.route = route;\n this.params = params;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigateToRoute(this.route, this.params, this.options);\n }\n}\n","import { ViewPortPlan, ViewPortInstruction, RouteConfig, ViewPort } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { InternalActivationStrategy, ActivationStrategyType } from './activation-strategy';\n\ntype ViewPortPlansRecord = Record;\n\n/**\n * @internal exported for unit testing\n */\nexport function _buildNavigationPlan(\n instruction: NavigationInstruction,\n forceLifecycleMinimum?: boolean\n): Promise {\n let config = instruction.config;\n\n if ('redirect' in config) {\n return buildRedirectPlan(instruction);\n }\n\n const prevInstruction = instruction.previousInstruction;\n const defaultViewPortConfigs = instruction.router.viewPortDefaults;\n\n if (prevInstruction) {\n return buildTransitionPlans(instruction, prevInstruction, defaultViewPortConfigs, forceLifecycleMinimum);\n }\n\n // first navigation, only need to prepare a few information for each viewport plan\n const viewPortPlans: ViewPortPlansRecord = {};\n let viewPortConfigs = config.viewPorts;\n for (let viewPortName in viewPortConfigs) {\n let viewPortConfig = viewPortConfigs[viewPortName];\n if (viewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) {\n viewPortConfig = defaultViewPortConfigs[viewPortName];\n }\n viewPortPlans[viewPortName] = {\n name: viewPortName,\n strategy: InternalActivationStrategy.Replace,\n config: viewPortConfig\n };\n }\n\n return Promise.resolve(viewPortPlans);\n}\n\n/**\n * Build redirect plan based on config of a navigation instruction\n * @internal exported for unit testing\n */\nexport const buildRedirectPlan = (instruction: NavigationInstruction) => {\n const config = instruction.config;\n const router = instruction.router;\n return router\n ._createNavigationInstruction(config.redirect)\n .then(redirectInstruction => {\n\n const params: Record = {};\n const originalInstructionParams = instruction.params;\n const redirectInstructionParams = redirectInstruction.params;\n\n for (let key in redirectInstructionParams) {\n // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this }\n let val = redirectInstructionParams[key];\n if (typeof val === 'string' && val[0] === ':') {\n val = val.slice(1);\n // And if that param is found on the original instruction then use it\n if (val in originalInstructionParams) {\n params[key] = originalInstructionParams[val];\n }\n } else {\n params[key] = redirectInstructionParams[key];\n }\n }\n let redirectLocation = router.generate(redirectInstruction.config, params, instruction.options);\n\n // Special handling for child routes\n for (let key in originalInstructionParams) {\n redirectLocation = redirectLocation.replace(`:${key}`, originalInstructionParams[key]);\n }\n\n let queryString = instruction.queryString;\n if (queryString) {\n redirectLocation += '?' + queryString;\n }\n\n return Promise.resolve(new Redirect(redirectLocation));\n });\n};\n\n/**\n * @param viewPortPlans the Plan record that holds information about built plans\n * @internal exported for unit testing\n */\nexport const buildTransitionPlans = (\n currentInstruction: NavigationInstruction,\n previousInstruction: NavigationInstruction,\n defaultViewPortConfigs: Record,\n forceLifecycleMinimum?: boolean\n): Promise => {\n\n let viewPortPlans: ViewPortPlansRecord = {};\n let newInstructionConfig = currentInstruction.config;\n let hasNewParams = hasDifferentParameterValues(previousInstruction, currentInstruction);\n let pending: Promise[] = [];\n let previousViewPortInstructions = previousInstruction.viewPortInstructions as Record;\n\n for (let viewPortName in previousViewPortInstructions) {\n\n const prevViewPortInstruction = previousViewPortInstructions[viewPortName];\n const prevViewPortComponent = prevViewPortInstruction.component;\n const newInstructionViewPortConfigs = newInstructionConfig.viewPorts as Record;\n\n // if this is invoked on a viewport without any changes, based on new url,\n // newViewPortConfig will be the existing viewport instruction\n let nextViewPortConfig = viewPortName in newInstructionViewPortConfigs\n ? newInstructionViewPortConfigs[viewPortName]\n : prevViewPortInstruction;\n\n if (nextViewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) {\n nextViewPortConfig = defaultViewPortConfigs[viewPortName];\n }\n\n const viewPortActivationStrategy = determineActivationStrategy(\n currentInstruction,\n prevViewPortInstruction,\n nextViewPortConfig,\n hasNewParams,\n forceLifecycleMinimum\n );\n const viewPortPlan = viewPortPlans[viewPortName] = {\n name: viewPortName,\n // ViewPortInstruction can quack like a RouteConfig\n config: nextViewPortConfig as RouteConfig,\n prevComponent: prevViewPortComponent,\n prevModuleId: prevViewPortInstruction.moduleId,\n strategy: viewPortActivationStrategy\n } as ViewPortPlan;\n\n // recursively build nav plans for all existing child routers/viewports of this viewport\n // this is possible because existing child viewports and routers already have necessary information\n // to process the wildcard path from parent instruction\n if (viewPortActivationStrategy !== InternalActivationStrategy.Replace && prevViewPortInstruction.childRouter) {\n const path = currentInstruction.getWildcardPath();\n const task: Promise = prevViewPortInstruction\n .childRouter\n ._createNavigationInstruction(path, currentInstruction)\n .then((childInstruction: NavigationInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(\n childInstruction,\n // is it safe to assume viewPortPlan has not been changed from previous assignment?\n // if so, can just use local variable viewPortPlanStrategy\n // there could be user code modifying viewport plan during _createNavigationInstruction?\n viewPortPlan.strategy === InternalActivationStrategy.InvokeLifecycle\n )\n .then(childPlan => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n // for bluebird ?\n return null;\n });\n });\n\n pending.push(task);\n }\n }\n\n return Promise.all(pending).then(() => viewPortPlans);\n};\n\n/**\n * @param newViewPortConfig if this is invoked on a viewport without any changes, based on new url, newViewPortConfig will be the existing viewport instruction\n * @internal exported for unit testing\n */\nexport const determineActivationStrategy = (\n currentNavInstruction: NavigationInstruction,\n prevViewPortInstruction: ViewPortInstruction,\n newViewPortConfig: RouteConfig | ViewPortInstruction,\n // indicates whether there is difference between old and new url params\n hasNewParams: boolean,\n forceLifecycleMinimum?: boolean\n): ActivationStrategyType => {\n\n let newInstructionConfig = currentNavInstruction.config;\n let prevViewPortViewModel = prevViewPortInstruction.component.viewModel;\n let viewPortPlanStrategy: ActivationStrategyType;\n\n if (prevViewPortInstruction.moduleId !== newViewPortConfig.moduleId) {\n viewPortPlanStrategy = InternalActivationStrategy.Replace;\n } else if ('determineActivationStrategy' in prevViewPortViewModel) {\n viewPortPlanStrategy = prevViewPortViewModel.determineActivationStrategy(...currentNavInstruction.lifecycleArgs);\n } else if (newInstructionConfig.activationStrategy) {\n viewPortPlanStrategy = newInstructionConfig.activationStrategy;\n } else if (hasNewParams || forceLifecycleMinimum) {\n viewPortPlanStrategy = InternalActivationStrategy.InvokeLifecycle;\n } else {\n viewPortPlanStrategy = InternalActivationStrategy.NoChange;\n }\n return viewPortPlanStrategy;\n};\n\n/**@internal exported for unit testing */\nexport const hasDifferentParameterValues = (prev: NavigationInstruction, next: NavigationInstruction): boolean => {\n let prevParams = prev.params;\n let nextParams = next.params;\n let nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null;\n\n for (let key in nextParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n for (let key in prevParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n if (!next.options.compareQueryParams) {\n return false;\n }\n\n let prevQueryParams = prev.queryParams;\n let nextQueryParams = next.queryParams;\n for (let key in nextQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n for (let key in prevQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n return false;\n};\n","import { Next } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { _buildNavigationPlan } from './navigation-plan';\n\n/**\n * Transform a navigation instruction into viewport plan record object,\n * or a redirect request if user viewmodel demands\n */\nexport class BuildNavigationPlanStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return _buildNavigationPlan(navigationInstruction)\n .then(plan => {\n if (plan instanceof Redirect) {\n return next.cancel(plan);\n }\n navigationInstruction.plan = plan;\n return next();\n })\n .catch(next.cancel);\n }\n}\n","import { RouteConfig, ViewPortComponent, ViewPortPlan, ViewPortInstruction } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { _buildNavigationPlan } from './navigation-plan';\nimport { InternalActivationStrategy } from './activation-strategy';\nimport { RouteLoader } from './route-loader';\n\n/**\n * Loading plan calculated based on a navigration-instruction and a viewport plan\n */\ninterface ILoadingPlan {\n viewPortPlan: ViewPortPlan;\n navigationInstruction: NavigationInstruction;\n}\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadNewRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction\n): Promise => {\n let loadingPlans = determineLoadingPlans(navigationInstruction);\n let loadPromises = loadingPlans.map((loadingPlan: ILoadingPlan) => loadRoute(\n routeLoader,\n loadingPlan.navigationInstruction,\n loadingPlan.viewPortPlan\n ));\n\n return Promise.all(loadPromises);\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const determineLoadingPlans = (\n navigationInstruction: NavigationInstruction,\n loadingPlans: ILoadingPlan[] = []\n): ILoadingPlan[] => {\n let viewPortPlans: Record = navigationInstruction.plan;\n\n for (let viewPortName in viewPortPlans) {\n let viewPortPlan = viewPortPlans[viewPortName];\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (viewPortPlan.strategy === InternalActivationStrategy.Replace) {\n loadingPlans.push({ viewPortPlan, navigationInstruction } as ILoadingPlan);\n\n if (childNavInstruction) {\n determineLoadingPlans(childNavInstruction, loadingPlans);\n }\n } else {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction({\n name: viewPortName,\n strategy: viewPortPlan.strategy,\n moduleId: viewPortPlan.prevModuleId,\n component: viewPortPlan.prevComponent\n }) as ViewPortInstruction;\n\n if (childNavInstruction) {\n viewPortInstruction.childNavigationInstruction = childNavInstruction;\n determineLoadingPlans(childNavInstruction, loadingPlans);\n }\n }\n }\n\n return loadingPlans;\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n viewPortPlan: ViewPortPlan\n): Promise => {\n let planConfig = viewPortPlan.config;\n let moduleId = planConfig ? planConfig.moduleId : null;\n\n return loadComponent(routeLoader, navigationInstruction, planConfig)\n .then((component) => {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction({\n name: viewPortPlan.name,\n strategy: viewPortPlan.strategy,\n moduleId: moduleId,\n component: component\n }) as ViewPortInstruction;\n\n let childRouter = component.childRouter;\n if (childRouter) {\n let path = navigationInstruction.getWildcardPath();\n\n return childRouter\n ._createNavigationInstruction(path, navigationInstruction)\n .then((childInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(childInstruction)\n .then((childPlan) => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n viewPortInstruction.childNavigationInstruction = childInstruction;\n\n return loadNewRoute(routeLoader, childInstruction);\n });\n });\n }\n // ts complains without this, though they are same\n return void 0;\n });\n};\n\n/**\n * Load a routed-component based on navigation instruction and route config\n * @internal exported for unit testing only\n */\nexport const loadComponent = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n config: RouteConfig\n): Promise => {\n let router = navigationInstruction.router;\n let lifecycleArgs = navigationInstruction.lifecycleArgs;\n\n return Promise.resolve()\n .then(() => routeLoader.loadRoute(router, config, navigationInstruction))\n .then(\n /**\n * @param component an object carrying information about loaded route\n * typically contains information about view model, childContainer, view and router\n */\n (component: ViewPortComponent) => {\n let { viewModel, childContainer } = component;\n component.router = router;\n component.config = config;\n\n if ('configureRouter' in viewModel) {\n let childRouter = childContainer.getChildRouter();\n component.childRouter = childRouter;\n\n return childRouter\n .configure(c => viewModel.configureRouter(c, childRouter, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]))\n .then(() => component);\n }\n\n return component;\n }\n );\n};\n","import { RouteConfig } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Router } from './router';\n\n/**\n * Abstract class that is responsible for loading view / view model from a route config\n * The default implementation can be found in `aurelia-templating-router`\n */\nexport class RouteLoader {\n /**\n * Load a route config based on its viewmodel / view configuration\n */\n // return typing: return typings used to be never\n // as it was a throw. Changing it to Promise should not cause any issues\n loadRoute(router: Router, config: RouteConfig, navigationInstruction: NavigationInstruction): Promise {\n throw new Error('Route loaders must implement \"loadRoute(router, config, navigationInstruction)\".');\n }\n}\n","import { Next } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { loadNewRoute } from './utilities-route-loading';\nimport { RouteLoader } from './route-loader';\n/**\n * A pipeline step responsible for loading a route config of a navigation instruction\n */\nexport class LoadRouteStep {\n /**@internal */\n static inject() { return [RouteLoader]; }\n /**\n * Route loader isntance that will handle loading route config\n * @internal\n */\n routeLoader: RouteLoader;\n constructor(routeLoader: RouteLoader) {\n this.routeLoader = routeLoader;\n }\n /**\n * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline\n */\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return loadNewRoute(this.routeLoader, navigationInstruction)\n .then(next, next.cancel);\n }\n}\n","import { NavigationInstruction } from './navigation-instruction';\n\n/**\n * A pipeline step for instructing a piepline to commit changes on a navigation instruction\n */\nexport class CommitChangesStep {\n run(navigationInstruction: NavigationInstruction, next: Function): Promise {\n return navigationInstruction\n ._commitChanges(/*wait to swap?*/ true)\n .then(() => {\n navigationInstruction._updateTitle();\n return next();\n });\n }\n}\n","/**\n * An optional interface describing the available activation strategies.\n * @internal Used internally.\n */\nexport const enum InternalActivationStrategy {\n /**\n * Reuse the existing view model, without invoking Router lifecycle hooks.\n */\n NoChange = 'no-change',\n /**\n * Reuse the existing view model, invoking Router lifecycle hooks.\n */\n InvokeLifecycle = 'invoke-lifecycle',\n /**\n * Replace the existing view model, invoking Router lifecycle hooks.\n */\n Replace = 'replace'\n}\n\n/**\n * The strategy to use when activating modules during navigation.\n */\n// kept for compat reason\nexport const activationStrategy: ActivationStrategy = {\n noChange: InternalActivationStrategy.NoChange,\n invokeLifecycle: InternalActivationStrategy.InvokeLifecycle,\n replace: InternalActivationStrategy.Replace\n};\n\n/**\n * An optional interface describing the available activation strategies.\n */\nexport interface ActivationStrategy {\n /**\n * Reuse the existing view model, without invoking Router lifecycle hooks.\n */\n noChange: 'no-change';\n /**\n * Reuse the existing view model, invoking Router lifecycle hooks.\n */\n invokeLifecycle: 'invoke-lifecycle';\n /**\n * Replace the existing view model, invoking Router lifecycle hooks.\n */\n replace: 'replace';\n}\n\n/**\n * Enum like type for activation strategy built-in values\n */\nexport type ActivationStrategyType = ActivationStrategy[keyof ActivationStrategy];\n","import { Next, ViewPortComponent, ViewPortPlan, ViewPortInstruction, LifecycleArguments } from './interfaces';\nimport { isNavigationCommand } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy } from './activation-strategy';\nimport { Router } from './router';\n\n/**\n * Recursively find list of deactivate-able view models\n * and invoke the either 'canDeactivate' or 'deactivate' on each\n * @internal exported for unit testing\n */\nexport const processDeactivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canDeactivate' | 'deactivate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let plan: Record = navigationInstruction.plan;\n let infos = findDeactivatable(plan, callbackName);\n let i = infos.length; // query from inside out\n\n function inspect(val: any): Promise {\n if (ignoreResult || shouldContinue(val)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n if (i--) {\n try {\n let viewModel = infos[i];\n let result = viewModel[callbackName](navigationInstruction);\n return processPotential(result, inspect, next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n navigationInstruction.router.couldDeactivate = true;\n\n return next();\n }\n\n return iterate();\n};\n\n/**\n * Recursively find and returns a list of deactivate-able view models\n * @internal exported for unit testing\n */\nexport const findDeactivatable = (\n plan: Record,\n callbackName: string,\n list: IActivatableInfo[] = []\n): any[] => {\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let prevComponent = viewPortPlan.prevComponent;\n\n if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace)\n && prevComponent\n ) {\n let viewModel = prevComponent.viewModel;\n\n if (callbackName in viewModel) {\n list.push(viewModel);\n }\n }\n\n if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) {\n addPreviousDeactivatable(prevComponent, callbackName, list);\n } else if (viewPortPlan.childNavigationInstruction) {\n findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list);\n }\n }\n\n return list;\n};\n\n/**\n * @internal exported for unit testing\n */\nexport const addPreviousDeactivatable = (\n component: ViewPortComponent,\n callbackName: string,\n list: IActivatableInfo[]\n): void => {\n let childRouter = component.childRouter;\n\n if (childRouter && childRouter.currentInstruction) {\n let viewPortInstructions = childRouter.currentInstruction.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let prevComponent = viewPortInstruction.component;\n let prevViewModel = prevComponent.viewModel;\n\n if (callbackName in prevViewModel) {\n list.push(prevViewModel);\n }\n\n addPreviousDeactivatable(prevComponent, callbackName, list);\n }\n }\n};\n\n/**\n * @internal exported for unit testing\n */\nexport const processActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let infos = findActivatable(navigationInstruction, callbackName);\n let length = infos.length;\n let i = -1; // query from top down\n\n function inspect(val: any, router: Router): Promise {\n if (ignoreResult || shouldContinue(val, router)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n i++;\n\n if (i < length) {\n try {\n let current = infos[i];\n let result = current.viewModel[callbackName](...current.lifecycleArgs);\n return processPotential(result, (val: any) => inspect(val, current.router), next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n return next();\n }\n\n return iterate();\n};\n\ninterface IActivatableInfo {\n viewModel: any;\n lifecycleArgs: LifecycleArguments;\n router: Router;\n}\n\n/**\n * Find list of activatable view model and add to list (3rd parameter)\n * @internal exported for unit testing\n */\nexport const findActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n list: IActivatableInfo[] = [],\n router?: Router\n): IActivatableInfo[] => {\n let plan: Record = navigationInstruction.plan;\n\n Object\n .keys(plan)\n .forEach((viewPortName) => {\n let viewPortPlan = plan[viewPortName];\n let viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName] as ViewPortInstruction;\n let viewPortComponent = viewPortInstruction.component;\n let viewModel = viewPortComponent.viewModel;\n\n if (\n (viewPortPlan.strategy === activationStrategy.invokeLifecycle\n || viewPortPlan.strategy === activationStrategy.replace\n )\n && callbackName in viewModel\n ) {\n list.push({\n viewModel,\n lifecycleArgs: viewPortInstruction.lifecycleArgs,\n router\n });\n }\n\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (childNavInstruction) {\n findActivatable(\n childNavInstruction,\n callbackName,\n list,\n viewPortComponent.childRouter || router\n );\n }\n });\n\n return list;\n};\n\nconst shouldContinue = (output: T, router?: Router): boolean | T => {\n if (output instanceof Error) {\n return false;\n }\n\n if (isNavigationCommand(output)) {\n if (typeof output.setRouter === 'function') {\n output.setRouter(router);\n }\n\n return !!output.shouldContinueProcessing;\n }\n\n if (output === undefined) {\n return true;\n }\n\n return output;\n};\n\n/**\n * A basic interface for an Observable type\n */\nexport interface IObservable {\n subscribe(sub?: IObservableConfig): ISubscription;\n}\n\nexport interface IObservableConfig {\n next(): void;\n error(err?: any): void;\n complete(): void;\n}\n\n/**\n * A basic interface for a Subscription to an Observable\n */\ninterface ISubscription {\n unsubscribe(): void;\n}\n\ntype SafeSubscriptionFunc = (sub: SafeSubscription) => ISubscription;\n\n/**\n * wraps a subscription, allowing unsubscribe calls even if\n * the first value comes synchronously\n */\nclass SafeSubscription {\n\n private _subscribed: boolean;\n private _subscription: ISubscription;\n\n constructor(subscriptionFunc: SafeSubscriptionFunc) {\n this._subscribed = true;\n this._subscription = subscriptionFunc(this);\n\n if (!this._subscribed) {\n this.unsubscribe();\n }\n }\n\n get subscribed(): boolean {\n return this._subscribed;\n }\n\n unsubscribe(): void {\n if (this._subscribed && this._subscription) {\n this._subscription.unsubscribe();\n }\n\n this._subscribed = false;\n }\n}\n\n/**\n * A function to process return value from `activate`/`canActivate` steps\n * Supports observable/promise\n *\n * For observable, resolve at first next() or on complete()\n */\nconst processPotential = (obj: any, resolve: (val?: any) => any, reject: (err?: any) => any): any => {\n // if promise like\n if (obj && typeof obj.then === 'function') {\n return Promise.resolve(obj).then(resolve).catch(reject);\n }\n\n // if observable\n if (obj && typeof obj.subscribe === 'function') {\n let obs: IObservable = obj;\n return new SafeSubscription(sub => obs.subscribe({\n next() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n },\n error(error) {\n if (sub.subscribed) {\n sub.unsubscribe();\n reject(error);\n }\n },\n complete() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n }\n }));\n }\n\n // else just resolve\n try {\n return resolve(obj);\n } catch (error) {\n return reject(error);\n }\n};\n","import { Next } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { processDeactivatable, processActivatable } from './utilities-activation';\n\n/**\n * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route\n */\nexport class CanDeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'canDeactivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route\n */\nexport class CanActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'canActivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route\n */\nexport class DeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'deactivate', next, true);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `activate` on a view model of a route\n */\nexport class ActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'activate', next, true);\n }\n}\n","import { Container } from 'aurelia-dependency-injection';\nimport { Pipeline } from './pipeline';\nimport { BuildNavigationPlanStep } from './step-build-navigation-plan';\nimport { LoadRouteStep } from './step-load-route';\nimport { CommitChangesStep } from './step-commit-changes';\nimport { CanDeactivatePreviousStep, CanActivateNextStep, DeactivatePreviousStep, ActivateNextStep } from './step-activation';\nimport { PipelineStep, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution\n */\nclass PipelineSlot implements IPipelineSlot {\n\n /**@internal */\n container: Container;\n /**@internal */\n slotName: string;\n /**@internal */\n slotAlias?: string;\n\n steps: (Function | PipelineStep)[] = [];\n\n constructor(container: Container, name: string, alias?: string) {\n this.container = container;\n this.slotName = name;\n this.slotAlias = alias;\n }\n\n getSteps(): (StepRunnerFunction | IPipelineSlot | PipelineStep)[] {\n return this.steps.map(x => this.container.get(x));\n }\n}\n\n/**\n * Class responsible for creating the navigation pipeline.\n */\nexport class PipelineProvider {\n\n /**@internal */\n static inject() { return [Container]; }\n /**@internal */\n container: Container;\n /**@internal */\n steps: (Function | PipelineSlot)[];\n\n constructor(container: Container) {\n this.container = container;\n this.steps = [\n BuildNavigationPlanStep,\n CanDeactivatePreviousStep, // optional\n LoadRouteStep,\n createPipelineSlot(container, PipelineSlotName.Authorize),\n CanActivateNextStep, // optional\n createPipelineSlot(container, PipelineSlotName.PreActivate, 'modelbind'),\n // NOTE: app state changes start below - point of no return\n DeactivatePreviousStep, // optional\n ActivateNextStep, // optional\n createPipelineSlot(container, PipelineSlotName.PreRender, 'precommit'),\n CommitChangesStep,\n createPipelineSlot(container, PipelineSlotName.PostRender, 'postcomplete')\n ];\n }\n\n /**\n * Create the navigation pipeline.\n */\n createPipeline(useCanDeactivateStep: boolean = true): Pipeline {\n let pipeline = new Pipeline();\n this.steps.forEach(step => {\n if (useCanDeactivateStep || step !== CanDeactivatePreviousStep) {\n pipeline.addStep(this.container.get(step));\n }\n });\n return pipeline;\n }\n\n /**@internal */\n _findStep(name: string): PipelineSlot {\n // Steps that are not PipelineSlots are constructor functions, and they will automatically fail. Probably.\n return this.steps.find(x => (x as PipelineSlot).slotName === name || (x as PipelineSlot).slotAlias === name) as PipelineSlot;\n }\n\n /**\n * Adds a step into the pipeline at a known slot location.\n */\n addStep(name: string, step: PipelineStep | Function): void {\n let found = this._findStep(name);\n if (found) {\n let slotSteps = found.steps;\n // prevent duplicates\n if (!slotSteps.includes(step)) {\n slotSteps.push(step);\n }\n } else {\n throw new Error(`Invalid pipeline slot name: ${name}.`);\n }\n }\n\n /**\n * Removes a step from a slot in the pipeline\n */\n removeStep(name: string, step: PipelineStep): void {\n let slot = this._findStep(name);\n if (slot) {\n let slotSteps = slot.steps;\n slotSteps.splice(slotSteps.indexOf(step), 1);\n }\n }\n\n /**\n * Clears all steps from a slot in the pipeline\n * @internal\n */\n _clearSteps(name: string = ''): void {\n let slot = this._findStep(name);\n if (slot) {\n slot.steps = [];\n }\n }\n\n /**\n * Resets all pipeline slots\n */\n reset(): void {\n this._clearSteps(PipelineSlotName.Authorize);\n this._clearSteps(PipelineSlotName.PreActivate);\n this._clearSteps(PipelineSlotName.PreRender);\n this._clearSteps(PipelineSlotName.PostRender);\n }\n}\n\n/**@internal */\nconst createPipelineSlot = (container: Container, name: PipelineSlotName, alias?: string): PipelineSlot => {\n return new PipelineSlot(container, name, alias);\n};\n","import * as LogManager from 'aurelia-logging';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\nimport { PipelineProvider } from './pipeline-provider';\nimport { isNavigationCommand } from './navigation-commands';\nimport { EventAggregator } from 'aurelia-event-aggregator';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { ViewPort, ConfiguresRouter, PipelineResult } from './interfaces';\nimport { RouterEvent } from './router-event';\n\n/**@internal */\ndeclare module 'aurelia-dependency-injection' {\n interface Container {\n viewModel?: any;\n }\n}\n\nconst logger = LogManager.getLogger('app-router');\n\n/**\n * The main application router.\n */\nexport class AppRouter extends Router {\n\n /**@internal */\n static inject() { return [Container, History, PipelineProvider, EventAggregator]; }\n\n events: EventAggregator;\n /**@internal */\n maxInstructionCount: number;\n /**@internal */\n _queue: NavigationInstruction[];\n /**@internal */\n isActive: boolean;\n\n constructor(container: Container, history: History, pipelineProvider: PipelineProvider, events: EventAggregator) {\n super(container, history); // Note the super will call reset internally.\n this.pipelineProvider = pipelineProvider;\n this.events = events;\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset(): void {\n super.reset();\n this.maxInstructionCount = 10;\n if (!this._queue) {\n this._queue = [];\n } else {\n this._queue.length = 0;\n }\n }\n\n /**\n * Loads the specified URL.\n *\n * @param url The URL fragment to load.\n */\n loadUrl(url: string): Promise {\n return this\n ._createNavigationInstruction(url)\n .then(instruction => this._queueInstruction(instruction))\n .catch(error => {\n logger.error(error);\n restorePreviousLocation(this);\n });\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort. This is typically a element in Aurelia default impl\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/ any, name?: string): Promise {\n // having strong typing without changing public API\n const $viewPort: ViewPort = viewPort;\n super.registerViewPort($viewPort, name);\n\n // beside adding viewport to the registry of this instance\n // AppRouter also configure routing/history to start routing functionality\n // There are situation where there are more than 1 element at root view\n // in that case, still only activate once via the following guard\n if (!this.isActive) {\n const viewModel = this._findViewModel($viewPort);\n if ('configureRouter' in viewModel) {\n // If there are more than one element at root view\n // use this flag to guard against configure method being invoked multiple times\n // this flag is set inside method configure\n if (!this.isConfigured) {\n // replace the real resolve with a noop to guarantee that any action in base class Router\n // won't resolve the configurePromise prematurely\n const resolveConfiguredPromise = this._resolveConfiguredPromise;\n this._resolveConfiguredPromise = () => {/**/};\n return this\n .configure(config => {\n viewModel.configureRouter(config, this);\n return config;\n })\n .then(() => {\n this.activate();\n resolveConfiguredPromise();\n });\n }\n } else {\n this.activate();\n }\n }\n // when a viewport is added dynamically to a root view that is already activated\n // just process the navigation instruction\n else {\n this._dequeueInstruction();\n }\n\n return Promise.resolve();\n }\n\n /**\n * Activates the router. This instructs the router to begin listening for history changes and processing instructions.\n *\n * @params options The set of options to activate the router with.\n */\n activate(options?: NavigationOptions): void {\n if (this.isActive) {\n return;\n }\n\n this.isActive = true;\n // route handler property is responsible for handling url change\n // the interface of aurelia-history isn't clear on this perspective\n this.options = Object.assign({ routeHandler: this.loadUrl.bind(this) }, this.options, options);\n this.history.activate(this.options);\n this._dequeueInstruction();\n }\n\n /**\n * Deactivates the router.\n */\n deactivate(): void {\n this.isActive = false;\n this.history.deactivate();\n }\n\n /**@internal */\n _queueInstruction(instruction: NavigationInstruction): Promise {\n return new Promise((resolve) => {\n instruction.resolve = resolve;\n this._queue.unshift(instruction);\n this._dequeueInstruction();\n });\n }\n\n /**@internal */\n _dequeueInstruction(instructionCount: number = 0): Promise {\n return Promise.resolve().then(() => {\n if (this.isNavigating && !instructionCount) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n let instruction = this._queue.shift();\n this._queue.length = 0;\n\n if (!instruction) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n this.isNavigating = true;\n\n let navtracker: number = this.history.getState('NavigationTracker');\n let currentNavTracker = this.currentNavigationTracker;\n\n if (!navtracker && !currentNavTracker) {\n this.isNavigatingFirst = true;\n this.isNavigatingNew = true;\n } else if (!navtracker) {\n this.isNavigatingNew = true;\n } else if (!currentNavTracker) {\n this.isNavigatingRefresh = true;\n } else if (currentNavTracker < navtracker) {\n this.isNavigatingForward = true;\n } else if (currentNavTracker > navtracker) {\n this.isNavigatingBack = true;\n } if (!navtracker) {\n navtracker = Date.now();\n this.history.setState('NavigationTracker', navtracker);\n }\n this.currentNavigationTracker = navtracker;\n\n instruction.previousInstruction = this.currentInstruction;\n\n let maxInstructionCount = this.maxInstructionCount;\n\n if (!instructionCount) {\n this.events.publish(RouterEvent.Processing, { instruction });\n } else if (instructionCount === maxInstructionCount - 1) {\n logger.error(`${instructionCount + 1} navigation instructions have been attempted without success. Restoring last known good location.`);\n restorePreviousLocation(this);\n return this._dequeueInstruction(instructionCount + 1);\n } else if (instructionCount > maxInstructionCount) {\n throw new Error('Maximum navigation attempts exceeded. Giving up.');\n }\n\n let pipeline = this.pipelineProvider.createPipeline(!this.couldDeactivate);\n\n return pipeline\n .run(instruction)\n .then(result => processResult(instruction, result, instructionCount, this))\n .catch(error => {\n return { output: error instanceof Error ? error : new Error(error) } as PipelineResult;\n })\n .then(result => resolveInstruction(instruction, result, !!instructionCount, this));\n });\n }\n\n /**@internal */\n _findViewModel(viewPort: ViewPort): ConfiguresRouter | undefined {\n if (this.container.viewModel) {\n return this.container.viewModel;\n }\n\n if (viewPort.container) {\n let container = viewPort.container;\n\n while (container) {\n if (container.viewModel) {\n this.container.viewModel = container.viewModel;\n return container.viewModel;\n }\n\n container = container.parent;\n }\n }\n\n return undefined;\n }\n}\n\nconst processResult = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n instructionCount: number,\n router: AppRouter\n): Promise => {\n if (!(result && 'completed' in result && 'output' in result)) {\n result = result || {} as PipelineResult;\n result.output = new Error(`Expected router pipeline to return a navigation result, but got [${JSON.stringify(result)}] instead.`);\n }\n\n let finalResult: PipelineResult = null;\n let navigationCommandResult = null;\n if (isNavigationCommand(result.output)) {\n navigationCommandResult = result.output.navigate(router);\n } else {\n finalResult = result;\n\n if (!result.completed) {\n if (result.output instanceof Error) {\n logger.error(result.output.toString());\n }\n\n restorePreviousLocation(router);\n }\n }\n\n return Promise.resolve(navigationCommandResult)\n .then(_ => router._dequeueInstruction(instructionCount + 1))\n .then(innerResult => finalResult || innerResult || result);\n};\n\nconst resolveInstruction = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n isInnerInstruction: boolean,\n router: AppRouter\n): PipelineResult => {\n instruction.resolve(result);\n\n let eventAggregator = router.events;\n let eventArgs = { instruction, result };\n if (!isInnerInstruction) {\n router.isNavigating = false;\n router.isExplicitNavigation = false;\n router.isExplicitNavigationBack = false;\n router.isNavigatingFirst = false;\n router.isNavigatingNew = false;\n router.isNavigatingRefresh = false;\n router.isNavigatingForward = false;\n router.isNavigatingBack = false;\n router.couldDeactivate = false;\n\n let eventName: string;\n\n if (result.output instanceof Error) {\n eventName = RouterEvent.Error;\n } else if (!result.completed) {\n eventName = RouterEvent.Canceled;\n } else {\n let queryString = instruction.queryString ? ('?' + instruction.queryString) : '';\n router.history.previousLocation = instruction.fragment + queryString;\n eventName = RouterEvent.Success;\n }\n\n eventAggregator.publish(eventName, eventArgs);\n eventAggregator.publish(RouterEvent.Complete, eventArgs);\n } else {\n eventAggregator.publish(RouterEvent.ChildComplete, eventArgs);\n }\n\n return result;\n};\n\nconst restorePreviousLocation = (router: AppRouter): void => {\n let previousLocation = router.history.previousLocation;\n if (previousLocation) {\n router.navigate(previousLocation, { trigger: false, replace: true });\n } else if (router.fallbackRoute) {\n router.navigate(router.fallbackRoute, { trigger: true, replace: true });\n } else {\n logger.error('Router navigation failed, and no previous location or fallbackRoute could be restored.');\n }\n};\n","/**\n* The status of a Pipeline.\n*/\nexport const enum PipelineStatus {\n Completed = 'completed',\n Canceled = 'canceled',\n Rejected = 'rejected',\n Running = 'running'\n}\n","/**\n * A list of known router events used by the Aurelia router\n * to signal the pipeline has come to a certain state\n */\n// const enum is preserved in tsconfig\nexport const enum RouterEvent {\n Processing = 'router:navigation:processing',\n Error = 'router:navigation:error',\n Canceled = 'router:navigation:canceled',\n Complete = 'router:navigation:complete',\n Success = 'router:navigation:success',\n ChildComplete = 'router:navigation:child:complete'\n}\n","/**\n * Available pipeline slot names to insert interceptor into router pipeline\n */\n// const enum is preserved in tsconfig\nexport const enum PipelineSlotName {\n /**\n * Authorization slot. Invoked early in the pipeline,\n * before `canActivate` hook of incoming route\n */\n Authorize = 'authorize',\n /**\n * Pre-activation slot. Invoked early in the pipeline,\n * Invoked timing:\n * - after Authorization slot\n * - after canActivate hook on new view model\n * - before deactivate hook on old view model\n * - before activate hook on new view model\n */\n PreActivate = 'preActivate',\n /**\n * Pre-render slot. Invoked later in the pipeline\n * Invokcation timing:\n * - after activate hook on new view model\n * - before commit step on new navigation instruction\n */\n PreRender = 'preRender',\n /**\n * Post-render slot. Invoked last in the pipeline\n */\n PostRender = 'postRender'\n}\n"],"names":["LogManager.getLogger"],"mappings":";;;;;;AA2BA;;;AAGA,MAAa,qBAAqB;IA4DhC,YAAY,IAA+B;;;;QAT3C,SAAI,GAAwC,IAAI,CAAC;QAEjD,YAAO,GAAwB,EAAE,CAAC;QAQhC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAE1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;QAChC,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;QAE/B,IAAI,cAAc,GAAG,EAAE,CAAC;QACxB,IAAI,OAAO,GAA0B,IAAI,CAAC;QAC1C,GAAG;YACD,IAAI,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YACtD,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE;;gBAEnD,OAAO,aAAa,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;aACjD;YAED,cAAc,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;YACtC,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC;SACrC,QAAQ,OAAO,EAAE;QAElB,IAAI,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,cAAc,CAAC,CAAC;QACvE,IAAI,CAAC,aAAa,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;KACrD;;;;IAKD,kBAAkB;QAChB,IAAI,YAAY,GAA4B,CAAC,IAAI,CAAC,CAAC;QACnD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C,oDAAqC,CAAA;IACrC,iEAAkD,CAAA;CACnD,EAPiB,WAAW,KAAX,WAAW,QAO5B;;ACZD;;;;AAIA,IAAkB,gBA0BjB;AA1BD,WAAkB,gBAAgB;;;;;IAKhC,2CAAuB,CAAA;;;;;;;;;IASvB,+CAA2B,CAAA;;;;;;;IAO3B,2CAAuB,CAAA;;;;IAIvB,6CAAyB,CAAA;CAC1B,EA1BiB,gBAAgB,KAAhB,gBAAgB,QA0BjC;;;;"} \ No newline at end of file diff --git a/dist/native-modules/aurelia-router.js b/dist/native-modules/aurelia-router.js index e7c8ee40..fe7ad092 100644 --- a/dist/native-modules/aurelia-router.js +++ b/dist/native-modules/aurelia-router.js @@ -4,1753 +4,1871 @@ import { History } from 'aurelia-history'; import { RouteRecognizer } from 'aurelia-route-recognizer'; import { EventAggregator } from 'aurelia-event-aggregator'; +/*! ***************************************************************************** +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 = function(d, b) { + 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]; }; + return extendStatics(d, b); +}; + +function __extends(d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +} + /** -* Determines if the provided object is a navigation command. -* A navigation command is anything with a navigate method. -* -* @param obj The object to check. -*/ -function isNavigationCommand(obj) { - return obj && typeof obj.navigate === 'function'; -} -/** -* Used during the activation lifecycle to cause a redirect. -*/ -var Redirect = /** @class */ (function () { - /** - * @param url The URL fragment to use as the navigation destination. - * @param options The navigation options. - */ - function Redirect(url, options) { - if (options === void 0) { options = {}; } - this.url = url; - this.options = Object.assign({ trigger: true, replace: true }, options); - this.shouldContinueProcessing = false; + * Class used to represent an instruction during a navigation. + */ +var NavigationInstruction = /** @class */ (function () { + function NavigationInstruction(init) { + /** + * Current built viewport plan of this nav instruction + */ + this.plan = null; + this.options = {}; + Object.assign(this, init); + this.params = this.params || {}; + this.viewPortInstructions = {}; + var ancestorParams = []; + var current = this; + do { + var currentParams = Object.assign({}, current.params); + if (current.config && current.config.hasChildRouter) { + // remove the param for the injected child route segment + delete currentParams[current.getWildCardName()]; + } + ancestorParams.unshift(currentParams); + current = current.parentInstruction; + } while (current); + var allParams = Object.assign.apply(Object, [{}, this.queryParams].concat(ancestorParams)); + this.lifecycleArgs = [allParams, this.config, this]; } /** - * Called by the activation system to set the child router. - * - * @param router The router. - */ - Redirect.prototype.setRouter = function (router) { - this.router = router; + * Gets an array containing this instruction and all child instructions for the current navigation. + */ + NavigationInstruction.prototype.getAllInstructions = function () { + var instructions = [this]; + var viewPortInstructions = this.viewPortInstructions; + for (var key in viewPortInstructions) { + var childInstruction = viewPortInstructions[key].childNavigationInstruction; + if (childInstruction) { + instructions.push.apply(instructions, childInstruction.getAllInstructions()); + } + } + return instructions; }; /** - * Called by the navigation pipeline to navigate. - * - * @param appRouter The router to be redirected. - */ - Redirect.prototype.navigate = function (appRouter) { - var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); - navigatingRouter.navigate(this.url, this.options); + * Gets an array containing the instruction and all child instructions for the previous navigation. + * Previous instructions are no longer available after navigation completes. + */ + NavigationInstruction.prototype.getAllPreviousInstructions = function () { + return this.getAllInstructions().map(function (c) { return c.previousInstruction; }).filter(function (c) { return c; }); + }; + NavigationInstruction.prototype.addViewPortInstruction = function (nameOrInitOptions, strategy, moduleId, component) { + var viewPortInstruction; + var viewPortName = typeof nameOrInitOptions === 'string' ? nameOrInitOptions : nameOrInitOptions.name; + var lifecycleArgs = this.lifecycleArgs; + var config = Object.assign({}, lifecycleArgs[1], { currentViewPort: viewPortName }); + if (typeof nameOrInitOptions === 'string') { + viewPortInstruction = { + name: nameOrInitOptions, + strategy: strategy, + moduleId: moduleId, + component: component, + childRouter: component.childRouter, + lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] + }; + } + else { + viewPortInstruction = { + name: viewPortName, + strategy: nameOrInitOptions.strategy, + component: nameOrInitOptions.component, + moduleId: nameOrInitOptions.moduleId, + childRouter: nameOrInitOptions.component.childRouter, + lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] + }; + } + return this.viewPortInstructions[viewPortName] = viewPortInstruction; }; - return Redirect; -}()); -/** -* Used during the activation lifecycle to cause a redirect to a named route. -*/ -var RedirectToRoute = /** @class */ (function () { /** - * @param route The name of the route. - * @param params The parameters to be sent to the activation method. - * @param options The options to use for navigation. + * Gets the name of the route pattern's wildcard parameter, if applicable. */ - function RedirectToRoute(route, params, options) { - if (params === void 0) { params = {}; } - if (options === void 0) { options = {}; } - this.route = route; - this.params = params; - this.options = Object.assign({ trigger: true, replace: true }, options); - this.shouldContinueProcessing = false; - } - /** - * Called by the activation system to set the child router. - * - * @param router The router. - */ - RedirectToRoute.prototype.setRouter = function (router) { - this.router = router; + NavigationInstruction.prototype.getWildCardName = function () { + // todo: potential issue, or at least unsafe typings + var configRoute = this.config.route; + var wildcardIndex = configRoute.lastIndexOf('*'); + return configRoute.substr(wildcardIndex + 1); }; /** - * Called by the navigation pipeline to navigate. - * - * @param appRouter The router to be redirected. - */ - RedirectToRoute.prototype.navigate = function (appRouter) { - var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); - navigatingRouter.navigateToRoute(this.route, this.params, this.options); + * Gets the path and query string created by filling the route + * pattern's wildcard parameter with the matching param. + */ + NavigationInstruction.prototype.getWildcardPath = function () { + var wildcardName = this.getWildCardName(); + var path = this.params[wildcardName] || ''; + var queryString = this.queryString; + if (queryString) { + path += '?' + queryString; + } + return path; }; - return RedirectToRoute; -}()); - -/** -* The strategy to use when activating modules during navigation. -*/ -var activationStrategy = { - noChange: 'no-change', - invokeLifecycle: 'invoke-lifecycle', - replace: 'replace' -}; -/** - * Transform a navigation instruction into viewport plan record object, - * or a redirect request if user viewmodel demands - */ -var BuildNavigationPlanStep = /** @class */ (function () { - function BuildNavigationPlanStep() { - } - BuildNavigationPlanStep.prototype.run = function (navigationInstruction, next) { - return _buildNavigationPlan(navigationInstruction) - .then(function (plan) { - if (plan instanceof Redirect) { - return next.cancel(plan); + /** + * Gets the instruction's base URL, accounting for wildcard route parameters. + */ + NavigationInstruction.prototype.getBaseUrl = function () { + var _this = this; + var $encodeURI = encodeURI; + var fragment = decodeURI(this.fragment); + if (fragment === '') { + var nonEmptyRoute = this.router.routes.find(function (route) { + return route.name === _this.config.name && + route.route !== ''; + }); + if (nonEmptyRoute) { + fragment = nonEmptyRoute.route; } - navigationInstruction.plan = plan; - return next(); - }) - .catch(next.cancel); + } + if (!this.params) { + return $encodeURI(fragment); + } + var wildcardName = this.getWildCardName(); + var path = this.params[wildcardName] || ''; + if (!path) { + return $encodeURI(fragment); + } + return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path))); }; - return BuildNavigationPlanStep; -}()); -function _buildNavigationPlan(instruction, forceLifecycleMinimum) { - var config = instruction.config; - // todo: separate and export for unit tests - if ('redirect' in config) { - var router_1 = instruction.router; - return router_1 - ._createNavigationInstruction(config.redirect) - .then(function (newInstruction) { - var params = {}; - for (var key in newInstruction.params) { - // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this } - var val = newInstruction.params[key]; - if (typeof val === 'string' && val[0] === ':') { - val = val.slice(1); - // And if that param is found on the original instruction then use it - if (val in instruction.params) { - params[key] = instruction.params[val]; - } + /** + * Finalize a viewport instruction + * @internal + */ + NavigationInstruction.prototype._commitChanges = function (waitToSwap) { + var _this = this; + var router = this.router; + router.currentInstruction = this; + var previousInstruction = this.previousInstruction; + if (previousInstruction) { + previousInstruction.config.navModel.isActive = false; + } + this.config.navModel.isActive = true; + router.refreshNavigation(); + var loads = []; + var delaySwaps = []; + var viewPortInstructions = this.viewPortInstructions; + var _loop_1 = function (viewPortName) { + var viewPortInstruction = viewPortInstructions[viewPortName]; + var viewPort = router.viewPorts[viewPortName]; + if (!viewPort) { + throw new Error("There was no router-view found in the view for " + viewPortInstruction.moduleId + "."); + } + var childNavInstruction = viewPortInstruction.childNavigationInstruction; + if (viewPortInstruction.strategy === "replace" /* Replace */) { + if (childNavInstruction && childNavInstruction.parentCatchHandler) { + loads.push(childNavInstruction._commitChanges(waitToSwap)); } else { - params[key] = newInstruction.params[key]; + if (waitToSwap) { + delaySwaps.push({ viewPort: viewPort, viewPortInstruction: viewPortInstruction }); + } + loads.push(viewPort + .process(viewPortInstruction, waitToSwap) + .then(function () { return childNavInstruction + ? childNavInstruction._commitChanges(waitToSwap) + : Promise.resolve(); })); } } - var redirectLocation = router_1.generate(newInstruction.config, params, instruction.options); - // Special handling for child routes - for (var key in instruction.params) { - redirectLocation = redirectLocation.replace(":" + key, instruction.params[key]); - } - if (instruction.queryString) { - redirectLocation += '?' + instruction.queryString; - } - return Promise.resolve(new Redirect(redirectLocation)); - }); - } - var prev = instruction.previousInstruction; - var plan = {}; - var defaults = instruction.router.viewPortDefaults; - if (prev) { - var newParams = hasDifferentParameterValues(prev, instruction); - var pending_1 = []; - var _loop_1 = function (viewPortName) { - var _a; - var prevViewPortInstruction = prev.viewPortInstructions[viewPortName]; - var nextViewPortConfig = viewPortName in config.viewPorts ? config.viewPorts[viewPortName] : prevViewPortInstruction; - if (nextViewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) { - nextViewPortConfig = defaults[viewPortName]; - } - var viewPortPlan = plan[viewPortName] = { - name: viewPortName, - config: nextViewPortConfig, - prevComponent: prevViewPortInstruction.component, - prevModuleId: prevViewPortInstruction.moduleId - }; - if (prevViewPortInstruction.moduleId !== nextViewPortConfig.moduleId) { - viewPortPlan.strategy = activationStrategy.replace; - } - else if ('determineActivationStrategy' in prevViewPortInstruction.component.viewModel) { - viewPortPlan.strategy = (_a = prevViewPortInstruction.component.viewModel).determineActivationStrategy.apply(_a, instruction.lifecycleArgs); - } - else if (config.activationStrategy) { - viewPortPlan.strategy = config.activationStrategy; - } - else if (newParams || forceLifecycleMinimum) { - viewPortPlan.strategy = activationStrategy.invokeLifecycle; - } else { - viewPortPlan.strategy = activationStrategy.noChange; - } - if (viewPortPlan.strategy !== activationStrategy.replace && prevViewPortInstruction.childRouter) { - var path = instruction.getWildcardPath(); - var task = prevViewPortInstruction - .childRouter - ._createNavigationInstruction(path, instruction) - .then(function (childInstruction) { - viewPortPlan.childNavigationInstruction = childInstruction; - return _buildNavigationPlan(childInstruction, viewPortPlan.strategy === activationStrategy.invokeLifecycle) - .then(function (childPlan) { - if (childPlan instanceof Redirect) { - return Promise.reject(childPlan); - } - childInstruction.plan = childPlan; - // for bluebird ? - return null; - }); - }); - pending_1.push(task); + if (childNavInstruction) { + loads.push(childNavInstruction._commitChanges(waitToSwap)); + } } }; - for (var viewPortName in prev.viewPortInstructions) { + for (var viewPortName in viewPortInstructions) { _loop_1(viewPortName); } - return Promise.all(pending_1).then(function () { return plan; }); - } - for (var viewPortName in config.viewPorts) { - var viewPortConfig = config.viewPorts[viewPortName]; - if (viewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) { - viewPortConfig = defaults[viewPortName]; - } - plan[viewPortName] = { - name: viewPortName, - strategy: activationStrategy.replace, - config: viewPortConfig - }; - } - return Promise.resolve(plan); -} -function hasDifferentParameterValues(prev, next) { - var prevParams = prev.params; - var nextParams = next.params; - var nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; - for (var key in nextParams) { - if (key === nextWildCardName) { - continue; - } - if (prevParams[key] !== nextParams[key]) { - return true; + return Promise + .all(loads) + .then(function () { + delaySwaps.forEach(function (x) { return x.viewPort.swap(x.viewPortInstruction); }); + return null; + }) + .then(function () { return prune(_this); }); + }; + /**@internal */ + NavigationInstruction.prototype._updateTitle = function () { + var router = this.router; + var title = this._buildTitle(router.titleSeparator); + if (title) { + router.history.setTitle(title); } - } - for (var key in prevParams) { - if (key === nextWildCardName) { - continue; + }; + /**@internal */ + NavigationInstruction.prototype._buildTitle = function (separator) { + if (separator === void 0) { separator = ' | '; } + var title = ''; + var childTitles = []; + var navModelTitle = this.config.navModel.title; + var instructionRouter = this.router; + var viewPortInstructions = this.viewPortInstructions; + if (navModelTitle) { + title = instructionRouter.transformTitle(navModelTitle); } - if (prevParams[key] !== nextParams[key]) { - return true; + for (var viewPortName in viewPortInstructions) { + var viewPortInstruction = viewPortInstructions[viewPortName]; + var child_nav_instruction = viewPortInstruction.childNavigationInstruction; + if (child_nav_instruction) { + var childTitle = child_nav_instruction._buildTitle(separator); + if (childTitle) { + childTitles.push(childTitle); + } + } } - } - if (!next.options.compareQueryParams) { - return false; - } - var prevQueryParams = prev.queryParams; - var nextQueryParams = next.queryParams; - for (var key in nextQueryParams) { - if (prevQueryParams[key] !== nextQueryParams[key]) { - return true; + if (childTitles.length) { + title = childTitles.join(separator) + (title ? separator : '') + title; } - } - for (var key in prevQueryParams) { - if (prevQueryParams[key] !== nextQueryParams[key]) { - return true; + if (instructionRouter.title) { + title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title); } - } - return false; -} - -/** - * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route - */ -var CanDeactivatePreviousStep = /** @class */ (function () { - function CanDeactivatePreviousStep() { - } - CanDeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { - return processDeactivatable(navigationInstruction, 'canDeactivate', next); + return title; }; - return CanDeactivatePreviousStep; + return NavigationInstruction; }()); +var prune = function (instruction) { + instruction.previousInstruction = null; + instruction.plan = null; +}; + /** - * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route - */ -var CanActivateNextStep = /** @class */ (function () { - function CanActivateNextStep() { +* Class for storing and interacting with a route's navigation settings. +*/ +var NavModel = /** @class */ (function () { + function NavModel(router, relativeHref) { + /** + * True if this nav item is currently active. + */ + this.isActive = false; + /** + * The title. + */ + this.title = null; + /** + * This nav item's absolute href. + */ + this.href = null; + /** + * This nav item's relative href. + */ + this.relativeHref = null; + /** + * Data attached to the route at configuration time. + */ + this.settings = {}; + /** + * The route config. + */ + this.config = null; + this.router = router; + this.relativeHref = relativeHref; } - CanActivateNextStep.prototype.run = function (navigationInstruction, next) { - return processActivatable(navigationInstruction, 'canActivate', next); + /** + * Sets the route's title and updates document.title. + * If the a navigation is in progress, the change will be applied + * to document.title when the navigation completes. + * + * @param title The new title. + */ + NavModel.prototype.setTitle = function (title) { + this.title = title; + if (this.isActive) { + this.router.updateTitle(); + } }; - return CanActivateNextStep; -}()); -/** - * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route - */ -var DeactivatePreviousStep = /** @class */ (function () { - function DeactivatePreviousStep() { + return NavModel; +}()); + +function _normalizeAbsolutePath(path, hasPushState, absolute) { + if (absolute === void 0) { absolute = false; } + if (!hasPushState && path[0] !== '#') { + path = '#' + path; } - DeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { - return processDeactivatable(navigationInstruction, 'deactivate', next, true); - }; - return DeactivatePreviousStep; -}()); -/** - * A pipeline step responsible for finding and activating method `activate` on a view model of a route - */ -var ActivateNextStep = /** @class */ (function () { - function ActivateNextStep() { + if (hasPushState && absolute) { + path = path.substring(1, path.length); } - ActivateNextStep.prototype.run = function (navigationInstruction, next) { - return processActivatable(navigationInstruction, 'activate', next, true); - }; - return ActivateNextStep; -}()); -/** - * Recursively find list of deactivate-able view models - * and invoke the either 'canDeactivate' or 'deactivate' on each - */ -var processDeactivatable = function (navigationInstruction, callbackName, next, ignoreResult) { - var plan = navigationInstruction.plan; - var infos = findDeactivatable(plan, callbackName); - var i = infos.length; // query from inside out - function inspect(val) { - if (ignoreResult || shouldContinue(val)) { - return iterate(); - } - return next.cancel(val); + return path; +} +function _createRootedPath(fragment, baseUrl, hasPushState, absolute) { + if (isAbsoluteUrl.test(fragment)) { + return fragment; } - function iterate() { - if (i--) { - try { - var viewModel = infos[i]; - var result = viewModel[callbackName](navigationInstruction); - return processPotential(result, inspect, next.cancel); - } - catch (error) { - return next.cancel(error); - } + var path = ''; + if (baseUrl.length && baseUrl[0] !== '/') { + path += '/'; + } + path += baseUrl; + if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') { + path += '/'; + } + if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') { + path = path.substring(0, path.length - 1); + } + return _normalizeAbsolutePath(path + fragment, hasPushState, absolute); +} +function _resolveUrl(fragment, baseUrl, hasPushState) { + if (isRootedPath.test(fragment)) { + return _normalizeAbsolutePath(fragment, hasPushState); + } + return _createRootedPath(fragment, baseUrl, hasPushState); +} +function _ensureArrayWithSingleRoutePerConfig(config) { + var routeConfigs = []; + if (Array.isArray(config.route)) { + for (var i = 0, ii = config.route.length; i < ii; ++i) { + var current = Object.assign({}, config); + current.route = config.route[i]; + routeConfigs.push(current); } - navigationInstruction.router.couldDeactivate = true; - return next(); } - return iterate(); -}; + else { + routeConfigs.push(Object.assign({}, config)); + } + return routeConfigs; +} +var isRootedPath = /^#?\//; +var isAbsoluteUrl = /^([a-z][a-z0-9+\-.]*:)?\/\//i; + /** - * Recursively find and returns a list of deactivate-able view models + * Class used to configure a [[Router]] instance. + * + * @constructor */ -var findDeactivatable = function (plan, callbackName, list) { - if (list === void 0) { list = []; } - for (var viewPortName in plan) { - var viewPortPlan = plan[viewPortName]; - var prevComponent = viewPortPlan.prevComponent; - if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace) - && prevComponent) { - var viewModel = prevComponent.viewModel; - if (callbackName in viewModel) { - list.push(viewModel); - } - } - if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) { - addPreviousDeactivatable(prevComponent, callbackName, list); - } - else if (viewPortPlan.childNavigationInstruction) { - findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list); - } - } - return list; -}; -var addPreviousDeactivatable = function (component, callbackName, list) { - var childRouter = component.childRouter; - if (childRouter && childRouter.currentInstruction) { - var viewPortInstructions = childRouter.currentInstruction.viewPortInstructions; - for (var viewPortName in viewPortInstructions) { - var viewPortInstruction = viewPortInstructions[viewPortName]; - var prevComponent = viewPortInstruction.component; - var prevViewModel = prevComponent.viewModel; - if (callbackName in prevViewModel) { - list.push(prevViewModel); - } - addPreviousDeactivatable(prevComponent, callbackName, list); - } - } -}; -var processActivatable = function (navigationInstruction, callbackName, next, ignoreResult) { - var infos = findActivatable(navigationInstruction, callbackName); - var length = infos.length; - var i = -1; // query from top down - function inspect(val, router) { - if (ignoreResult || shouldContinue(val, router)) { - return iterate(); - } - return next.cancel(val); - } - function iterate() { - var _a; - i++; - if (i < length) { - try { - var current_1 = infos[i]; - var result = (_a = current_1.viewModel)[callbackName].apply(_a, current_1.lifecycleArgs); - return processPotential(result, function (val) { return inspect(val, current_1.router); }, next.cancel); - } - catch (error) { - return next.cancel(error); - } - } - return next(); - } - return iterate(); -}; -/** - * Find list of activatable view model and add to list (3rd parameter) - */ -var findActivatable = function (navigationInstruction, callbackName, list, router) { - if (list === void 0) { list = []; } - var plan = navigationInstruction.plan; - Object - .keys(plan) - .forEach(function (viewPortName) { - var viewPortPlan = plan[viewPortName]; - var viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName]; - var viewPortComponent = viewPortInstruction.component; - var viewModel = viewPortComponent.viewModel; - if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle - || viewPortPlan.strategy === activationStrategy.replace) - && callbackName in viewModel) { - list.push({ - viewModel: viewModel, - lifecycleArgs: viewPortInstruction.lifecycleArgs, - router: router - }); - } - var childNavInstruction = viewPortPlan.childNavigationInstruction; - if (childNavInstruction) { - findActivatable(childNavInstruction, callbackName, list, viewPortComponent.childRouter || router); - } - }); - return list; -}; -var shouldContinue = function (output, router) { - if (output instanceof Error) { - return false; - } - if (isNavigationCommand(output)) { - if (typeof output.setRouter === 'function') { - output.setRouter(router); - } - return !!output.shouldContinueProcessing; - } - if (output === undefined) { - return true; - } - return output; -}; -/** - * wraps a subscription, allowing unsubscribe calls even if - * the first value comes synchronously - */ -var SafeSubscription = /** @class */ (function () { - function SafeSubscription(subscriptionFunc) { - this._subscribed = true; - this._subscription = subscriptionFunc(this); - if (!this._subscribed) { - this.unsubscribe(); - } - } - Object.defineProperty(SafeSubscription.prototype, "subscribed", { - get: function () { - return this._subscribed; - }, - enumerable: true, - configurable: true - }); - SafeSubscription.prototype.unsubscribe = function () { - if (this._subscribed && this._subscription) { - this._subscription.unsubscribe(); - } - this._subscribed = false; - }; - return SafeSubscription; -}()); -/** - * A function to process return value from `activate`/`canActivate` steps - * Supports observable/promise - * - * For observable, resolve at first next() or on complete() - */ -var processPotential = function (obj, resolve, reject) { - // if promise like - if (obj && typeof obj.then === 'function') { - return Promise.resolve(obj).then(resolve).catch(reject); - } - // if observable - if (obj && typeof obj.subscribe === 'function') { - var obs_1 = obj; - return new SafeSubscription(function (sub) { return obs_1.subscribe({ - next: function () { - if (sub.subscribed) { - sub.unsubscribe(); - resolve(obj); - } - }, - error: function (error) { - if (sub.subscribed) { - sub.unsubscribe(); - reject(error); - } - }, - complete: function () { - if (sub.subscribed) { - sub.unsubscribe(); - resolve(obj); - } - } - }); }); - } - // else just resolve - try { - return resolve(obj); - } - catch (error) { - return reject(error); - } -}; - -/*! ***************************************************************************** -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 = function(d, b) { - 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]; }; - return extendStatics(d, b); -}; - -function __extends(d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); -} - -/** - * A pipeline step for instructing a piepline to commit changes on a navigation instruction - */ -var CommitChangesStep = /** @class */ (function () { - function CommitChangesStep() { - } - CommitChangesStep.prototype.run = function (navigationInstruction, next) { - return navigationInstruction - ._commitChanges(/*wait to swap?*/ true) - .then(function () { - navigationInstruction._updateTitle(); - return next(); - }); - }; - return CommitChangesStep; -}()); -/** -* Class used to represent an instruction during a navigation. -*/ -var NavigationInstruction = /** @class */ (function () { - function NavigationInstruction(init) { - /** - * Current built viewport plan of this nav instruction - */ - this.plan = null; - this.options = {}; - Object.assign(this, init); - this.params = this.params || {}; - this.viewPortInstructions = {}; - var ancestorParams = []; - var current = this; - do { - var currentParams = Object.assign({}, current.params); - if (current.config && current.config.hasChildRouter) { - // remove the param for the injected child route segment - delete currentParams[current.getWildCardName()]; - } - ancestorParams.unshift(currentParams); - current = current.parentInstruction; - } while (current); - var allParams = Object.assign.apply(Object, [{}, this.queryParams].concat(ancestorParams)); - this.lifecycleArgs = [allParams, this.config, this]; +var RouterConfiguration = /** @class */ (function () { + function RouterConfiguration() { + this.instructions = []; + this.options = {}; + this.pipelineSteps = []; } /** - * Gets an array containing this instruction and all child instructions for the current navigation. - */ - NavigationInstruction.prototype.getAllInstructions = function () { - var instructions = [this]; - var viewPortInstructions = this.viewPortInstructions; - for (var key in viewPortInstructions) { - var childInstruction = viewPortInstructions[key].childNavigationInstruction; - if (childInstruction) { - instructions.push.apply(instructions, childInstruction.getAllInstructions()); - } + * Adds a step to be run during the [[Router]]'s navigation pipeline. + * + * @param name The name of the pipeline slot to insert the step into. + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPipelineStep = function (name, step) { + if (step === null || step === undefined) { + throw new Error('Pipeline step cannot be null or undefined.'); } - return instructions; + this.pipelineSteps.push({ name: name, step: step }); + return this; }; /** - * Gets an array containing the instruction and all child instructions for the previous navigation. - * Previous instructions are no longer available after navigation completes. - */ - NavigationInstruction.prototype.getAllPreviousInstructions = function () { - return this.getAllInstructions().map(function (c) { return c.previousInstruction; }).filter(function (c) { return c; }); + * Adds a step to be run during the [[Router]]'s authorize pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addAuthorizeStep = function (step) { + return this.addPipelineStep("authorize" /* Authorize */, step); }; /** - * Adds a viewPort instruction. Returns the newly created instruction based on parameters - */ - NavigationInstruction.prototype.addViewPortInstruction = function (name, strategy, moduleId, component) { - var lifecycleArgs = this.lifecycleArgs; - var config = Object.assign({}, lifecycleArgs[1], { currentViewPort: name }); - var viewportInstruction = this.viewPortInstructions[name] = { - name: name, - strategy: strategy, - moduleId: moduleId, - component: component, - childRouter: component.childRouter, - lifecycleArgs: [].concat(lifecycleArgs[0], config, lifecycleArgs[2]) - }; - return viewportInstruction; + * Adds a step to be run during the [[Router]]'s preActivate pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPreActivateStep = function (step) { + return this.addPipelineStep("preActivate" /* PreActivate */, step); }; /** - * Gets the name of the route pattern's wildcard parameter, if applicable. - */ - NavigationInstruction.prototype.getWildCardName = function () { - // todo: potential issue, or at least unsafe typings - var configRoute = this.config.route; - var wildcardIndex = configRoute.lastIndexOf('*'); - return configRoute.substr(wildcardIndex + 1); + * Adds a step to be run during the [[Router]]'s preRender pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPreRenderStep = function (step) { + return this.addPipelineStep("preRender" /* PreRender */, step); }; /** - * Gets the path and query string created by filling the route - * pattern's wildcard parameter with the matching param. - */ - NavigationInstruction.prototype.getWildcardPath = function () { - var wildcardName = this.getWildCardName(); - var path = this.params[wildcardName] || ''; - var queryString = this.queryString; - if (queryString) { - path += '?' + queryString; - } - return path; + * Adds a step to be run during the [[Router]]'s postRender pipeline slot. + * + * @param step The pipeline step. + * @chainable + */ + RouterConfiguration.prototype.addPostRenderStep = function (step) { + return this.addPipelineStep("postRender" /* PostRender */, step); }; /** - * Gets the instruction's base URL, accounting for wildcard route parameters. - */ - NavigationInstruction.prototype.getBaseUrl = function () { - var _this = this; - var $encodeURI = encodeURI; - var fragment = decodeURI(this.fragment); - if (fragment === '') { - var nonEmptyRoute = this.router.routes.find(function (route) { - return route.name === _this.config.name && - route.route !== ''; - }); - if (nonEmptyRoute) { - fragment = nonEmptyRoute.route; - } - } - if (!this.params) { - return $encodeURI(fragment); - } - var wildcardName = this.getWildCardName(); - var path = this.params[wildcardName] || ''; - if (!path) { - return $encodeURI(fragment); - } - return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path))); + * Configures a route that will be used if there is no previous location available on navigation cancellation. + * + * @param fragment The URL fragment to use as the navigation destination. + * @chainable + */ + RouterConfiguration.prototype.fallbackRoute = function (fragment) { + this._fallbackRoute = fragment; + return this; }; - /**@internal */ - NavigationInstruction.prototype._commitChanges = function (waitToSwap) { + /** + * Maps one or more routes to be registered with the router. + * + * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map. + * @chainable + */ + RouterConfiguration.prototype.map = function (route) { var _this = this; - var router = this.router; - router.currentInstruction = this; - var previousInstruction = this.previousInstruction; - if (previousInstruction) { - previousInstruction.config.navModel.isActive = false; - } - this.config.navModel.isActive = true; - router.refreshNavigation(); - var loads = []; - var delaySwaps = []; - var viewPortInstructions = this.viewPortInstructions; - var _loop_1 = function (viewPortName) { - var viewPortInstruction = viewPortInstructions[viewPortName]; - var viewPort = router.viewPorts[viewPortName]; - if (!viewPort) { - throw new Error("There was no router-view found in the view for " + viewPortInstruction.moduleId + "."); - } - var child_nav_instruction = viewPortInstruction.childNavigationInstruction; - if (viewPortInstruction.strategy === activationStrategy.replace) { - if (child_nav_instruction && child_nav_instruction.parentCatchHandler) { - loads.push(child_nav_instruction._commitChanges(waitToSwap)); - } - else { - if (waitToSwap) { - delaySwaps.push({ viewPort: viewPort, viewPortInstruction: viewPortInstruction }); - } - loads.push(viewPort - .process(viewPortInstruction, waitToSwap) - .then(function () { return child_nav_instruction - ? child_nav_instruction._commitChanges(waitToSwap) - : Promise.resolve(); })); - } - } - else { - if (child_nav_instruction) { - loads.push(child_nav_instruction._commitChanges(waitToSwap)); - } - } - }; - for (var viewPortName in viewPortInstructions) { - _loop_1(viewPortName); + if (Array.isArray(route)) { + route.forEach(function (r) { return _this.map(r); }); + return this; } - return Promise - .all(loads) - .then(function () { - delaySwaps.forEach(function (x) { return x.viewPort.swap(x.viewPortInstruction); }); - return null; - }) - .then(function () { return prune(_this); }); + return this.mapRoute(route); }; - /**@internal */ - NavigationInstruction.prototype._updateTitle = function () { - var router = this.router; - var title = this._buildTitle(router.titleSeparator); - if (title) { - router.history.setTitle(title); - } + /** + * Configures defaults to use for any view ports. + * + * @param viewPortConfig a view port configuration object to use as a + * default, of the form { viewPortName: { moduleId } }. + * @chainable + */ + RouterConfiguration.prototype.useViewPortDefaults = function (viewPortConfig) { + this.viewPortDefaults = viewPortConfig; + return this; }; - /**@internal */ - NavigationInstruction.prototype._buildTitle = function (separator) { - if (separator === void 0) { separator = ' | '; } - var title = ''; - var childTitles = []; - var navModelTitle = this.config.navModel.title; - var instructionRouter = this.router; - var viewPortInstructions = this.viewPortInstructions; - if (navModelTitle) { - title = instructionRouter.transformTitle(navModelTitle); - } - for (var viewPortName in viewPortInstructions) { - var viewPortInstruction = viewPortInstructions[viewPortName]; - var child_nav_instruction = viewPortInstruction.childNavigationInstruction; - if (child_nav_instruction) { - var childTitle = child_nav_instruction._buildTitle(separator); - if (childTitle) { - childTitles.push(childTitle); + /** + * Maps a single route to be registered with the router. + * + * @param route The [[RouteConfig]] to map. + * @chainable + */ + RouterConfiguration.prototype.mapRoute = function (config) { + this.instructions.push(function (router) { + var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); + var navModel; + for (var i = 0, ii = routeConfigs.length; i < ii; ++i) { + var routeConfig = routeConfigs[i]; + routeConfig.settings = routeConfig.settings || {}; + if (!navModel) { + navModel = router.createNavModel(routeConfig); } + router.addRoute(routeConfig, navModel); } - } - if (childTitles.length) { - title = childTitles.join(separator) + (title ? separator : '') + title; - } - if (instructionRouter.title) { - title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title); - } - return title; + }); + return this; + }; + /** + * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes. + * + * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the + * [[NavigationInstruction]] and selects a moduleId to load. + * @chainable + */ + RouterConfiguration.prototype.mapUnknownRoutes = function (config) { + this.unknownRouteConfig = config; + return this; }; - return NavigationInstruction; -}()); -var prune = function (instruction) { - instruction.previousInstruction = null; - instruction.plan = null; -}; - -/** -* Class for storing and interacting with a route's navigation settings. -*/ -var NavModel = /** @class */ (function () { - function NavModel(router, relativeHref) { - /** - * True if this nav item is currently active. - */ - this.isActive = false; - /** - * The title. - */ - this.title = null; - /** - * This nav item's absolute href. - */ - this.href = null; - /** - * This nav item's relative href. - */ - this.relativeHref = null; - /** - * Data attached to the route at configuration time. - */ - this.settings = {}; - /** - * The route config. - */ - this.config = null; - this.router = router; - this.relativeHref = relativeHref; - } /** - * Sets the route's title and updates document.title. - * If the a navigation is in progress, the change will be applied - * to document.title when the navigation completes. - * - * @param title The new title. - */ - NavModel.prototype.setTitle = function (title) { - this.title = title; - if (this.isActive) { - this.router.updateTitle(); + * Applies the current configuration to the specified [[Router]]. + * + * @param router The [[Router]] to apply the configuration to. + */ + RouterConfiguration.prototype.exportToRouter = function (router) { + var instructions = this.instructions; + for (var i = 0, ii = instructions.length; i < ii; ++i) { + instructions[i](router); + } + var _a = this, title = _a.title, titleSeparator = _a.titleSeparator, unknownRouteConfig = _a.unknownRouteConfig, _fallbackRoute = _a._fallbackRoute, viewPortDefaults = _a.viewPortDefaults; + if (title) { + router.title = title; + } + if (titleSeparator) { + router.titleSeparator = titleSeparator; + } + if (unknownRouteConfig) { + router.handleUnknownRoutes(unknownRouteConfig); + } + if (_fallbackRoute) { + router.fallbackRoute = _fallbackRoute; + } + if (viewPortDefaults) { + router.useViewPortDefaults(viewPortDefaults); + } + Object.assign(router.options, this.options); + var pipelineSteps = this.pipelineSteps; + var pipelineStepCount = pipelineSteps.length; + if (pipelineStepCount) { + if (!router.isRoot) { + throw new Error('Pipeline steps can only be added to the root router'); + } + var pipelineProvider = router.pipelineProvider; + for (var i = 0, ii = pipelineStepCount; i < ii; ++i) { + var _b = pipelineSteps[i], name_1 = _b.name, step = _b.step; + pipelineProvider.addStep(name_1, step); + } } }; - return NavModel; + return RouterConfiguration; }()); -function _normalizeAbsolutePath(path, hasPushState, absolute) { - if (absolute === void 0) { absolute = false; } - if (!hasPushState && path[0] !== '#') { - path = '#' + path; - } - if (hasPushState && absolute) { - path = path.substring(1, path.length); - } - return path; -} -function _createRootedPath(fragment, baseUrl, hasPushState, absolute) { - if (isAbsoluteUrl.test(fragment)) { - return fragment; - } - var path = ''; - if (baseUrl.length && baseUrl[0] !== '/') { - path += '/'; - } - path += baseUrl; - if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') { - path += '/'; - } - if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') { - path = path.substring(0, path.length - 1); - } - return _normalizeAbsolutePath(path + fragment, hasPushState, absolute); -} -function _resolveUrl(fragment, baseUrl, hasPushState) { - if (isRootedPath.test(fragment)) { - return _normalizeAbsolutePath(fragment, hasPushState); - } - return _createRootedPath(fragment, baseUrl, hasPushState); -} -function _ensureArrayWithSingleRoutePerConfig(config) { - var routeConfigs = []; - if (Array.isArray(config.route)) { - for (var i = 0, ii = config.route.length; i < ii; ++i) { - var current = Object.assign({}, config); - current.route = config.route[i]; - routeConfigs.push(current); - } - } - else { - routeConfigs.push(Object.assign({}, config)); - } - return routeConfigs; -} -var isRootedPath = /^#?\//; -var isAbsoluteUrl = /^([a-z][a-z0-9+\-.]*:)?\/\//i; - /** - * Class used to configure a [[Router]] instance. - * - * @constructor + * The primary class responsible for handling routing and navigation. */ -var RouterConfiguration = /** @class */ (function () { - function RouterConfiguration() { - this.instructions = []; +var Router = /** @class */ (function () { + /** + * @param container The [[Container]] to use when child routers. + * @param history The [[History]] implementation to delegate navigation requests to. + */ + function Router(container, history) { + var _this = this; + /** + * The parent router, or null if this instance is not a child router. + */ + this.parent = null; this.options = {}; - this.pipelineSteps = []; + /** + * The defaults used when a viewport lacks specified content + */ + this.viewPortDefaults = {}; + /** + * Extension point to transform the document title before it is built and displayed. + * By default, child routers delegate to the parent router, and the app router + * returns the title unchanged. + */ + this.transformTitle = function (title) { + if (_this.parent) { + return _this.parent.transformTitle(title); + } + return title; + }; + this.container = container; + this.history = history; + this.reset(); } /** - * Adds a step to be run during the [[Router]]'s navigation pipeline. - * - * @param name The name of the pipeline slot to insert the step into. - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPipelineStep = function (name, step) { - if (step === null || step === undefined) { - throw new Error('Pipeline step cannot be null or undefined.'); + * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. + * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. + */ + Router.prototype.reset = function () { + var _this = this; + this.viewPorts = {}; + this.routes = []; + this.baseUrl = ''; + this.isConfigured = false; + this.isNavigating = false; + this.isExplicitNavigation = false; + this.isExplicitNavigationBack = false; + this.isNavigatingFirst = false; + this.isNavigatingNew = false; + this.isNavigatingRefresh = false; + this.isNavigatingForward = false; + this.isNavigatingBack = false; + this.couldDeactivate = false; + this.navigation = []; + this.currentInstruction = null; + this.viewPortDefaults = {}; + this._fallbackOrder = 100; + this._recognizer = new RouteRecognizer(); + this._childRecognizer = new RouteRecognizer(); + this._configuredPromise = new Promise(function (resolve) { + _this._resolveConfiguredPromise = resolve; + }); + }; + Object.defineProperty(Router.prototype, "isRoot", { + /** + * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent. + */ + get: function () { + return !this.parent; + }, + enumerable: true, + configurable: true + }); + /** + * Registers a viewPort to be used as a rendering target for activated routes. + * + * @param viewPort The viewPort. + * @param name The name of the viewPort. 'default' if unspecified. + */ + Router.prototype.registerViewPort = function (viewPort, name) { + name = name || 'default'; + this.viewPorts[name] = viewPort; + }; + /** + * Returns a Promise that resolves when the router is configured. + */ + Router.prototype.ensureConfigured = function () { + return this._configuredPromise; + }; + /** + * Configures the router. + * + * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]]. + */ + Router.prototype.configure = function (callbackOrConfig) { + var _this = this; + this.isConfigured = true; + var result = callbackOrConfig; + var config; + if (typeof callbackOrConfig === 'function') { + config = new RouterConfiguration(); + result = callbackOrConfig(config); } - this.pipelineSteps.push({ name: name, step: step }); - return this; + return Promise + .resolve(result) + .then(function (c) { + if (c && c.exportToRouter) { + config = c; + } + config.exportToRouter(_this); + _this.isConfigured = true; + _this._resolveConfiguredPromise(); + }); }; /** - * Adds a step to be run during the [[Router]]'s authorize pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addAuthorizeStep = function (step) { - return this.addPipelineStep("authorize" /* Authorize */, step); + * Navigates to a new location. + * + * @param fragment The URL fragment to use as the navigation destination. + * @param options The navigation options. + */ + Router.prototype.navigate = function (fragment, options) { + if (!this.isConfigured && this.parent) { + return this.parent.navigate(fragment, options); + } + this.isExplicitNavigation = true; + return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options); }; /** - * Adds a step to be run during the [[Router]]'s preActivate pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPreActivateStep = function (step) { - return this.addPipelineStep("preActivate" /* PreActivate */, step); + * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed + * by [[Router.navigate]]. + * + * @param route The name of the route to use when generating the navigation location. + * @param params The route parameters to be used when populating the route pattern. + * @param options The navigation options. + */ + Router.prototype.navigateToRoute = function (route, params, options) { + var path = this.generate(route, params); + return this.navigate(path, options); + }; + /** + * Navigates back to the most recent location in history. + */ + Router.prototype.navigateBack = function () { + this.isExplicitNavigationBack = true; + this.history.navigateBack(); + }; + /** + * Creates a child router of the current router. + * + * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified. + * @returns {Router} The new child Router. + */ + Router.prototype.createChild = function (container) { + var childRouter = new Router(container || this.container.createChild(), this.history); + childRouter.parent = this; + return childRouter; + }; + /** + * Generates a URL fragment matching the specified route pattern. + * + * @param name The name of the route whose pattern should be used to generate the fragment. + * @param params The route params to be used to populate the route pattern. + * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url. + * @returns {string} A string containing the generated URL fragment. + */ + Router.prototype.generate = function (nameOrRoute, params, options) { + if (params === void 0) { params = {}; } + if (options === void 0) { options = {}; } + // A child recognizer generates routes for potential child routes. Any potential child route is added + // to the childRoute property of params for the childRouter to recognize. When generating routes, we + // use the childRecognizer when childRoute params are available to generate a child router enabled route. + var recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer; + var hasRoute = recognizer.hasRoute(nameOrRoute); + if (!hasRoute) { + if (this.parent) { + return this.parent.generate(nameOrRoute, params, options); + } + throw new Error("A route with name '" + nameOrRoute + "' could not be found. Check that `name: '" + nameOrRoute + "'` was specified in the route's config."); + } + var path = recognizer.generate(nameOrRoute, params); + var rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute); + return options.absolute ? "" + this.history.getAbsoluteRoot() + rootedPath : rootedPath; }; /** - * Adds a step to be run during the [[Router]]'s preRender pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPreRenderStep = function (step) { - return this.addPipelineStep("preRender" /* PreRender */, step); + * Creates a [[NavModel]] for the specified route config. + * + * @param config The route config. + */ + Router.prototype.createNavModel = function (config) { + var navModel = new NavModel(this, 'href' in config + ? config.href + // potential error when config.route is a string[] ? + : config.route); + navModel.title = config.title; + navModel.order = config.nav; + navModel.href = config.href; + navModel.settings = config.settings; + navModel.config = config; + return navModel; }; /** - * Adds a step to be run during the [[Router]]'s postRender pipeline slot. - * - * @param step The pipeline step. - * @chainable - */ - RouterConfiguration.prototype.addPostRenderStep = function (step) { - return this.addPipelineStep("postRender" /* PostRender */, step); + * Registers a new route with the router. + * + * @param config The [[RouteConfig]]. + * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes. + */ + Router.prototype.addRoute = function (config, navModel) { + if (Array.isArray(config.route)) { + var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); + // the following is wrong. todo: fix this after TS refactoring release + routeConfigs.forEach(this.addRoute.bind(this)); + return; + } + validateRouteConfig(config); + if (!('viewPorts' in config) && !config.navigationStrategy) { + config.viewPorts = { + 'default': { + moduleId: config.moduleId, + view: config.view + } + }; + } + if (!navModel) { + navModel = this.createNavModel(config); + } + this.routes.push(config); + var path = config.route; + if (path.charAt(0) === '/') { + path = path.substr(1); + } + var caseSensitive = config.caseSensitive === true; + var state = this._recognizer.add({ + path: path, + handler: config, + caseSensitive: caseSensitive + }); + if (path) { + var settings = config.settings; + delete config.settings; + var withChild = JSON.parse(JSON.stringify(config)); + config.settings = settings; + withChild.route = path + "/*childRoute"; + withChild.hasChildRouter = true; + this._childRecognizer.add({ + path: withChild.route, + handler: withChild, + caseSensitive: caseSensitive + }); + withChild.navModel = navModel; + withChild.settings = config.settings; + withChild.navigationStrategy = config.navigationStrategy; + } + config.navModel = navModel; + var navigation = this.navigation; + if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) { + if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) { + throw new Error('Invalid route config for "' + config.route + '" : dynamic routes must specify an "href:" to be included in the navigation model.'); + } + if (typeof navModel.order !== 'number') { + navModel.order = ++this._fallbackOrder; + } + navigation.push(navModel); + // this is a potential error / inconsistency between browsers + // + // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort + // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, + // but sorted with respect to all different elements. + // Note: the ECMAscript standard does not guarantee this behaviour, + // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this. + navigation.sort(function (a, b) { return a.order - b.order; }); + } }; /** - * Configures a route that will be used if there is no previous location available on navigation cancellation. - * - * @param fragment The URL fragment to use as the navigation destination. - * @chainable - */ - RouterConfiguration.prototype.fallbackRoute = function (fragment) { - this._fallbackRoute = fragment; - return this; + * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name. + * + * @param name The name of the route to check. + */ + Router.prototype.hasRoute = function (name) { + return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name)); }; /** - * Maps one or more routes to be registered with the router. - * - * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map. - * @chainable - */ - RouterConfiguration.prototype.map = function (route) { - if (Array.isArray(route)) { - route.forEach(this.map.bind(this)); - return this; - } - return this.mapRoute(route); + * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name. + * + * @param name The name of the route to check. + */ + Router.prototype.hasOwnRoute = function (name) { + return this._recognizer.hasRoute(name); }; /** - * Configures defaults to use for any view ports. + * Register a handler to use when the incoming URL fragment doesn't match any registered routes. * - * @param viewPortConfig a view port configuration object to use as a - * default, of the form { viewPortName: { moduleId } }. - * @chainable + * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]]. */ - RouterConfiguration.prototype.useViewPortDefaults = function (viewPortConfig) { - this.viewPortDefaults = viewPortConfig; - return this; + Router.prototype.handleUnknownRoutes = function (config) { + var _this = this; + if (!config) { + throw new Error('Invalid unknown route handler'); + } + this.catchAllHandler = function (instruction) { + return _this + ._createRouteConfig(config, instruction) + .then(function (c) { + instruction.config = c; + return instruction; + }); + }; }; /** - * Maps a single route to be registered with the router. - * - * @param route The [[RouteConfig]] to map. - * @chainable - */ - RouterConfiguration.prototype.mapRoute = function (config) { - this.instructions.push(function (router) { - var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); - var navModel; - for (var i = 0, ii = routeConfigs.length; i < ii; ++i) { - var routeConfig = routeConfigs[i]; - routeConfig.settings = routeConfig.settings || {}; - if (!navModel) { - navModel = router.createNavModel(routeConfig); - } - router.addRoute(routeConfig, navModel); - } - }); - return this; + * Updates the document title using the current navigation instruction. + */ + Router.prototype.updateTitle = function () { + var parentRouter = this.parent; + if (parentRouter) { + return parentRouter.updateTitle(); + } + var currentInstruction = this.currentInstruction; + if (currentInstruction) { + currentInstruction._updateTitle(); + } + return undefined; }; /** - * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes. - * - * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the - * [[NavigationInstruction]] and selects a moduleId to load. - * @chainable - */ - RouterConfiguration.prototype.mapUnknownRoutes = function (config) { - this.unknownRouteConfig = config; - return this; + * Updates the navigation routes with hrefs relative to the current location. + * Note: This method will likely move to a plugin in a future release. + */ + Router.prototype.refreshNavigation = function () { + var nav = this.navigation; + for (var i = 0, length_1 = nav.length; i < length_1; i++) { + var current = nav[i]; + if (!current.config.href) { + current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState); + } + else { + current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState); + } + } }; /** - * Applies the current configuration to the specified [[Router]]. - * - * @param router The [[Router]] to apply the configuration to. - */ - RouterConfiguration.prototype.exportToRouter = function (router) { - var instructions = this.instructions; - for (var i = 0, ii = instructions.length; i < ii; ++i) { - instructions[i](router); + * Sets the default configuration for the view ports. This specifies how to + * populate a view port for which no module is specified. The default is + * an empty view/view-model pair. + */ + Router.prototype.useViewPortDefaults = function ($viewPortDefaults) { + // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction + var viewPortDefaults = $viewPortDefaults; + for (var viewPortName in viewPortDefaults) { + var viewPortConfig = viewPortDefaults[viewPortName]; + this.viewPortDefaults[viewPortName] = { + moduleId: viewPortConfig.moduleId + }; + } + }; + /**@internal */ + Router.prototype._refreshBaseUrl = function () { + var parentRouter = this.parent; + if (parentRouter) { + this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction); + } + }; + /**@internal */ + Router.prototype._createNavigationInstruction = function (url, parentInstruction) { + if (url === void 0) { url = ''; } + if (parentInstruction === void 0) { parentInstruction = null; } + var fragment = url; + var queryString = ''; + var queryIndex = url.indexOf('?'); + if (queryIndex !== -1) { + fragment = url.substr(0, queryIndex); + queryString = url.substr(queryIndex + 1); + } + var urlRecognizationResults = this._recognizer.recognize(url); + if (!urlRecognizationResults || !urlRecognizationResults.length) { + urlRecognizationResults = this._childRecognizer.recognize(url); + } + var instructionInit = { + fragment: fragment, + queryString: queryString, + config: null, + parentInstruction: parentInstruction, + previousInstruction: this.currentInstruction, + router: this, + options: { + compareQueryParams: this.options.compareQueryParams + } + }; + var result; + if (urlRecognizationResults && urlRecognizationResults.length) { + var first = urlRecognizationResults[0]; + var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: first.params, + queryParams: first.queryParams || urlRecognizationResults.queryParams, + config: first.config || first.handler + })); + if (typeof first.handler === 'function') { + result = evaluateNavigationStrategy(instruction, first.handler, first); + } + else if (first.handler && typeof first.handler.navigationStrategy === 'function') { + result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); + } + else { + result = Promise.resolve(instruction); + } + } + else if (this.catchAllHandler) { + var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: { path: fragment }, + queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, + config: null // config will be created by the catchAllHandler + })); + result = evaluateNavigationStrategy(instruction, this.catchAllHandler); + } + else if (this.parent) { + var router = this._parentCatchAllHandler(this.parent); + if (router) { + var newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction); + var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { + params: { path: fragment }, + queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, + router: router, + parentInstruction: newParentInstruction, + parentCatchHandler: true, + config: null // config will be created by the chained parent catchAllHandler + })); + result = evaluateNavigationStrategy(instruction, router.catchAllHandler); + } } - if (this.title) { - router.title = this.title; + if (result && parentInstruction) { + this.baseUrl = generateBaseUrl(this.parent, parentInstruction); } - if (this.titleSeparator) { - router.titleSeparator = this.titleSeparator; + return result || Promise.reject(new Error("Route not found: " + url)); + }; + /**@internal */ + Router.prototype._findParentInstructionFromRouter = function (router, instruction) { + if (instruction.router === router) { + instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId + return instruction; } - if (this.unknownRouteConfig) { - router.handleUnknownRoutes(this.unknownRouteConfig); + else if (instruction.parentInstruction) { + return this._findParentInstructionFromRouter(router, instruction.parentInstruction); } - if (this._fallbackRoute) { - router.fallbackRoute = this._fallbackRoute; + return undefined; + }; + /**@internal */ + Router.prototype._parentCatchAllHandler = function (router) { + if (router.catchAllHandler) { + return router; } - if (this.viewPortDefaults) { - router.useViewPortDefaults(this.viewPortDefaults); + else if (router.parent) { + return this._parentCatchAllHandler(router.parent); } - Object.assign(router.options, this.options); - var pipelineSteps = this.pipelineSteps; - if (pipelineSteps.length) { - if (!router.isRoot) { - throw new Error('Pipeline steps can only be added to the root router'); + return false; + }; + /** + * @internal + */ + Router.prototype._createRouteConfig = function (config, instruction) { + var _this = this; + return Promise + .resolve(config) + .then(function (c) { + if (typeof c === 'string') { + return { moduleId: c }; } - var pipelineProvider = router.pipelineProvider; - for (var i = 0, ii = pipelineSteps.length; i < ii; ++i) { - var _a = pipelineSteps[i], name_1 = _a.name, step = _a.step; - pipelineProvider.addStep(name_1, step); + else if (typeof c === 'function') { + return c(instruction); + } + return c; + }) + // typing here could be either RouteConfig or RedirectConfig + // but temporarily treat both as RouteConfig + // todo: improve typings precision + .then(function (c) { return typeof c === 'string' ? { moduleId: c } : c; }) + .then(function (c) { + c.route = instruction.params.path; + validateRouteConfig(c); + if (!c.navModel) { + c.navModel = _this.createNavModel(c); + } + return c; + }); + }; + return Router; +}()); +/* @internal exported for unit testing */ +var generateBaseUrl = function (router, instruction) { + return "" + (router.baseUrl || '') + (instruction.getBaseUrl() || ''); +}; +/* @internal exported for unit testing */ +var validateRouteConfig = function (config) { + if (typeof config !== 'object') { + throw new Error('Invalid Route Config'); + } + if (typeof config.route !== 'string') { + var name_1 = config.name || '(no name)'; + throw new Error('Invalid Route Config for "' + name_1 + '": You must specify a "route:" pattern.'); + } + if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) { + throw new Error('Invalid Route Config for "' + config.route + '": You must specify a "moduleId:", "redirect:", "navigationStrategy:", or "viewPorts:".'); + } +}; +/* @internal exported for unit testing */ +var evaluateNavigationStrategy = function (instruction, evaluator, context) { + return Promise + .resolve(evaluator.call(context, instruction)) + .then(function () { + if (!('viewPorts' in instruction.config)) { + instruction.config.viewPorts = { + 'default': { + moduleId: instruction.config.moduleId + } + }; + } + return instruction; + }); +}; + +/**@internal exported for unit testing */ +var createNextFn = function (instruction, steps) { + var index = -1; + var next = function () { + index++; + if (index < steps.length) { + var currentStep = steps[index]; + try { + return currentStep(instruction, next); + } + catch (e) { + return next.reject(e); } } + else { + return next.complete(); + } }; - return RouterConfiguration; -}()); + next.complete = createCompletionHandler(next, "completed" /* Completed */); + next.cancel = createCompletionHandler(next, "canceled" /* Canceled */); + next.reject = createCompletionHandler(next, "rejected" /* Rejected */); + return next; +}; +/**@internal exported for unit testing */ +var createCompletionHandler = function (next, status) { + return function (output) { return Promise + .resolve({ + status: status, + output: output, + completed: status === "completed" /* Completed */ + }); }; +}; /** - * The primary class responsible for handling routing and navigation. + * The class responsible for managing and processing the navigation pipeline. */ -var Router = /** @class */ (function () { - /** - * @param container The [[Container]] to use when child routers. - * @param history The [[History]] implementation to delegate navigation requests to. - */ - function Router(container, history) { - var _this = this; - /** - * The parent router, or null if this instance is not a child router. - */ - this.parent = null; - this.options = {}; - /** - * The defaults used when a viewport lacks specified content - */ - this.viewPortDefaults = {}; +var Pipeline = /** @class */ (function () { + function Pipeline() { /** - * Extension point to transform the document title before it is built and displayed. - * By default, child routers delegate to the parent router, and the app router - * returns the title unchanged. - */ - this.transformTitle = function (title) { - if (_this.parent) { - return _this.parent.transformTitle(title); - } - return title; - }; - this.container = container; - this.history = history; - this.reset(); + * The pipeline steps. And steps added via addStep will be converted to a function + * The actualy running functions with correct step contexts of this pipeline + */ + this.steps = []; } /** - * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. - * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. - */ - Router.prototype.reset = function () { - var _this = this; - this.viewPorts = {}; - this.routes = []; - this.baseUrl = ''; - this.isConfigured = false; - this.isNavigating = false; - this.isExplicitNavigation = false; - this.isExplicitNavigationBack = false; - this.isNavigatingFirst = false; - this.isNavigatingNew = false; - this.isNavigatingRefresh = false; - this.isNavigatingForward = false; - this.isNavigatingBack = false; - this.couldDeactivate = false; - this.navigation = []; - this.currentInstruction = null; - this.viewPortDefaults = {}; - this._fallbackOrder = 100; - this._recognizer = new RouteRecognizer(); - this._childRecognizer = new RouteRecognizer(); - this._configuredPromise = new Promise(function (resolve) { - _this._resolveConfiguredPromise = resolve; - }); - }; - Object.defineProperty(Router.prototype, "isRoot", { - /** - * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent. - */ - get: function () { - return !this.parent; - }, - enumerable: true, - configurable: true - }); - /** - * Registers a viewPort to be used as a rendering target for activated routes. - * - * @param viewPort The viewPort. - * @param name The name of the viewPort. 'default' if unspecified. - */ - Router.prototype.registerViewPort = function (viewPort, name) { - name = name || 'default'; - this.viewPorts[name] = viewPort; - }; - /** - * Returns a Promise that resolves when the router is configured. - */ - Router.prototype.ensureConfigured = function () { - return this._configuredPromise; - }; - /** - * Configures the router. - * - * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]]. - */ - Router.prototype.configure = function (callbackOrConfig) { - var _this = this; - this.isConfigured = true; - var result = callbackOrConfig; - var config; - if (typeof callbackOrConfig === 'function') { - config = new RouterConfiguration(); - result = callbackOrConfig(config); + * Adds a step to the pipeline. + * + * @param step The pipeline step. + */ + Pipeline.prototype.addStep = function (step) { + var run; + if (typeof step === 'function') { + run = step; } - return Promise - .resolve(result) - .then(function (c) { - if (c && c.exportToRouter) { - config = c; + else if (typeof step.getSteps === 'function') { + // getSteps is to enable support open slots + // where devs can add multiple steps into the same slot name + var steps = step.getSteps(); + for (var i = 0, l = steps.length; i < l; i++) { + this.addStep(steps[i]); } - config.exportToRouter(_this); - _this.isConfigured = true; - _this._resolveConfiguredPromise(); - }); - }; - /** - * Navigates to a new location. - * - * @param fragment The URL fragment to use as the navigation destination. - * @param options The navigation options. - */ - Router.prototype.navigate = function (fragment, options) { - if (!this.isConfigured && this.parent) { - return this.parent.navigate(fragment, options); + return this; } - this.isExplicitNavigation = true; - return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options); + else { + run = step.run.bind(step); + } + this.steps.push(run); + return this; }; /** - * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed - * by [[Router.navigate]]. - * - * @param route The name of the route to use when generating the navigation location. - * @param params The route parameters to be used when populating the route pattern. - * @param options The navigation options. - */ - Router.prototype.navigateToRoute = function (route, params, options) { - var path = this.generate(route, params); - return this.navigate(path, options); + * Runs the pipeline. + * + * @param instruction The navigation instruction to process. + */ + Pipeline.prototype.run = function (instruction) { + var nextFn = createNextFn(instruction, this.steps); + return nextFn(); }; + return Pipeline; +}()); + +/** +* Determines if the provided object is a navigation command. +* A navigation command is anything with a navigate method. +* +* @param obj The object to check. +*/ +function isNavigationCommand(obj) { + return obj && typeof obj.navigate === 'function'; +} +/** +* Used during the activation lifecycle to cause a redirect. +*/ +var Redirect = /** @class */ (function () { /** - * Navigates back to the most recent location in history. - */ - Router.prototype.navigateBack = function () { - this.isExplicitNavigationBack = true; - this.history.navigateBack(); + * @param url The URL fragment to use as the navigation destination. + * @param options The navigation options. + */ + function Redirect(url, options) { + if (options === void 0) { options = {}; } + this.url = url; + this.options = Object.assign({ trigger: true, replace: true }, options); + this.shouldContinueProcessing = false; + } + /** + * Called by the activation system to set the child router. + * + * @param router The router. + */ + Redirect.prototype.setRouter = function (router) { + this.router = router; }; /** - * Creates a child router of the current router. + * Called by the navigation pipeline to navigate. * - * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified. - * @returns {Router} The new child Router. + * @param appRouter The router to be redirected. */ - Router.prototype.createChild = function (container) { - var childRouter = new Router(container || this.container.createChild(), this.history); - childRouter.parent = this; - return childRouter; + Redirect.prototype.navigate = function (appRouter) { + var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); + navigatingRouter.navigate(this.url, this.options); }; + return Redirect; +}()); +/** + * Used during the activation lifecycle to cause a redirect to a named route. + */ +var RedirectToRoute = /** @class */ (function () { /** - * Generates a URL fragment matching the specified route pattern. - * - * @param name The name of the route whose pattern should be used to generate the fragment. - * @param params The route params to be used to populate the route pattern. - * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url. - * @returns {string} A string containing the generated URL fragment. - */ - Router.prototype.generate = function (nameOrRoute, params, options) { + * @param route The name of the route. + * @param params The parameters to be sent to the activation method. + * @param options The options to use for navigation. + */ + function RedirectToRoute(route, params, options) { if (params === void 0) { params = {}; } if (options === void 0) { options = {}; } - // A child recognizer generates routes for potential child routes. Any potential child route is added - // to the childRoute property of params for the childRouter to recognize. When generating routes, we - // use the childRecognizer when childRoute params are available to generate a child router enabled route. - var recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer; - var hasRoute = recognizer.hasRoute(nameOrRoute); - if (!hasRoute) { - if (this.parent) { - return this.parent.generate(nameOrRoute, params, options); - } - throw new Error("A route with name '" + nameOrRoute + "' could not be found. Check that `name: '" + nameOrRoute + "'` was specified in the route's config."); - } - var path = recognizer.generate(nameOrRoute, params); - var rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute); - return options.absolute ? "" + this.history.getAbsoluteRoot() + rootedPath : rootedPath; - }; + this.route = route; + this.params = params; + this.options = Object.assign({ trigger: true, replace: true }, options); + this.shouldContinueProcessing = false; + } /** - * Creates a [[NavModel]] for the specified route config. - * - * @param config The route config. - */ - Router.prototype.createNavModel = function (config) { - var navModel = new NavModel(this, 'href' in config - ? config.href - // potential error when config.route is a string[] ? - : config.route); - navModel.title = config.title; - navModel.order = config.nav; - navModel.href = config.href; - navModel.settings = config.settings; - navModel.config = config; - return navModel; + * Called by the activation system to set the child router. + * + * @param router The router. + */ + RedirectToRoute.prototype.setRouter = function (router) { + this.router = router; }; /** - * Registers a new route with the router. - * - * @param config The [[RouteConfig]]. - * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes. - */ - Router.prototype.addRoute = function (config, navModel) { - if (Array.isArray(config.route)) { - var routeConfigs = _ensureArrayWithSingleRoutePerConfig(config); - // the following is wrong. todo: fix this after TS refactoring release - routeConfigs.forEach(this.addRoute.bind(this)); - return; - } - validateRouteConfig(config); - if (!('viewPorts' in config) && !config.navigationStrategy) { - config.viewPorts = { - 'default': { - moduleId: config.moduleId, - view: config.view + * Called by the navigation pipeline to navigate. + * + * @param appRouter The router to be redirected. + */ + RedirectToRoute.prototype.navigate = function (appRouter) { + var navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter); + navigatingRouter.navigateToRoute(this.route, this.params, this.options); + }; + return RedirectToRoute; +}()); + +/** + * @internal exported for unit testing + */ +function _buildNavigationPlan(instruction, forceLifecycleMinimum) { + var config = instruction.config; + if ('redirect' in config) { + return buildRedirectPlan(instruction); + } + var prevInstruction = instruction.previousInstruction; + var defaultViewPortConfigs = instruction.router.viewPortDefaults; + if (prevInstruction) { + return buildTransitionPlans(instruction, prevInstruction, defaultViewPortConfigs, forceLifecycleMinimum); + } + // first navigation, only need to prepare a few information for each viewport plan + var viewPortPlans = {}; + var viewPortConfigs = config.viewPorts; + for (var viewPortName in viewPortConfigs) { + var viewPortConfig = viewPortConfigs[viewPortName]; + if (viewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) { + viewPortConfig = defaultViewPortConfigs[viewPortName]; + } + viewPortPlans[viewPortName] = { + name: viewPortName, + strategy: "replace" /* Replace */, + config: viewPortConfig + }; + } + return Promise.resolve(viewPortPlans); +} +/** + * Build redirect plan based on config of a navigation instruction + * @internal exported for unit testing + */ +var buildRedirectPlan = function (instruction) { + var config = instruction.config; + var router = instruction.router; + return router + ._createNavigationInstruction(config.redirect) + .then(function (redirectInstruction) { + var params = {}; + var originalInstructionParams = instruction.params; + var redirectInstructionParams = redirectInstruction.params; + for (var key in redirectInstructionParams) { + // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this } + var val = redirectInstructionParams[key]; + if (typeof val === 'string' && val[0] === ':') { + val = val.slice(1); + // And if that param is found on the original instruction then use it + if (val in originalInstructionParams) { + params[key] = originalInstructionParams[val]; } - }; + } + else { + params[key] = redirectInstructionParams[key]; + } } - if (!navModel) { - navModel = this.createNavModel(config); + var redirectLocation = router.generate(redirectInstruction.config, params, instruction.options); + // Special handling for child routes + for (var key in originalInstructionParams) { + redirectLocation = redirectLocation.replace(":" + key, originalInstructionParams[key]); } - this.routes.push(config); - var path = config.route; - if (path.charAt(0) === '/') { - path = path.substr(1); + var queryString = instruction.queryString; + if (queryString) { + redirectLocation += '?' + queryString; } - var caseSensitive = config.caseSensitive === true; - var state = this._recognizer.add({ - path: path, - handler: config, - caseSensitive: caseSensitive + return Promise.resolve(new Redirect(redirectLocation)); + }); +}; +/** + * @param viewPortPlans the Plan record that holds information about built plans + * @internal exported for unit testing + */ +var buildTransitionPlans = function (currentInstruction, previousInstruction, defaultViewPortConfigs, forceLifecycleMinimum) { + var viewPortPlans = {}; + var newInstructionConfig = currentInstruction.config; + var hasNewParams = hasDifferentParameterValues(previousInstruction, currentInstruction); + var pending = []; + var previousViewPortInstructions = previousInstruction.viewPortInstructions; + var _loop_1 = function (viewPortName) { + var prevViewPortInstruction = previousViewPortInstructions[viewPortName]; + var prevViewPortComponent = prevViewPortInstruction.component; + var newInstructionViewPortConfigs = newInstructionConfig.viewPorts; + // if this is invoked on a viewport without any changes, based on new url, + // newViewPortConfig will be the existing viewport instruction + var nextViewPortConfig = viewPortName in newInstructionViewPortConfigs + ? newInstructionViewPortConfigs[viewPortName] + : prevViewPortInstruction; + if (nextViewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) { + nextViewPortConfig = defaultViewPortConfigs[viewPortName]; + } + var viewPortActivationStrategy = determineActivationStrategy(currentInstruction, prevViewPortInstruction, nextViewPortConfig, hasNewParams, forceLifecycleMinimum); + var viewPortPlan = viewPortPlans[viewPortName] = { + name: viewPortName, + // ViewPortInstruction can quack like a RouteConfig + config: nextViewPortConfig, + prevComponent: prevViewPortComponent, + prevModuleId: prevViewPortInstruction.moduleId, + strategy: viewPortActivationStrategy + }; + // recursively build nav plans for all existing child routers/viewports of this viewport + // this is possible because existing child viewports and routers already have necessary information + // to process the wildcard path from parent instruction + if (viewPortActivationStrategy !== "replace" /* Replace */ && prevViewPortInstruction.childRouter) { + var path = currentInstruction.getWildcardPath(); + var task = prevViewPortInstruction + .childRouter + ._createNavigationInstruction(path, currentInstruction) + .then(function (childInstruction) { + viewPortPlan.childNavigationInstruction = childInstruction; + return _buildNavigationPlan(childInstruction, + // is it safe to assume viewPortPlan has not been changed from previous assignment? + // if so, can just use local variable viewPortPlanStrategy + // there could be user code modifying viewport plan during _createNavigationInstruction? + viewPortPlan.strategy === "invoke-lifecycle" /* InvokeLifecycle */) + .then(function (childPlan) { + if (childPlan instanceof Redirect) { + return Promise.reject(childPlan); + } + childInstruction.plan = childPlan; + // for bluebird ? + return null; + }); + }); + pending.push(task); + } + }; + for (var viewPortName in previousViewPortInstructions) { + _loop_1(viewPortName); + } + return Promise.all(pending).then(function () { return viewPortPlans; }); +}; +/** + * @param newViewPortConfig if this is invoked on a viewport without any changes, based on new url, newViewPortConfig will be the existing viewport instruction + * @internal exported for unit testing + */ +var determineActivationStrategy = function (currentNavInstruction, prevViewPortInstruction, newViewPortConfig, +// indicates whether there is difference between old and new url params +hasNewParams, forceLifecycleMinimum) { + var newInstructionConfig = currentNavInstruction.config; + var prevViewPortViewModel = prevViewPortInstruction.component.viewModel; + var viewPortPlanStrategy; + if (prevViewPortInstruction.moduleId !== newViewPortConfig.moduleId) { + viewPortPlanStrategy = "replace" /* Replace */; + } + else if ('determineActivationStrategy' in prevViewPortViewModel) { + viewPortPlanStrategy = prevViewPortViewModel.determineActivationStrategy.apply(prevViewPortViewModel, currentNavInstruction.lifecycleArgs); + } + else if (newInstructionConfig.activationStrategy) { + viewPortPlanStrategy = newInstructionConfig.activationStrategy; + } + else if (hasNewParams || forceLifecycleMinimum) { + viewPortPlanStrategy = "invoke-lifecycle" /* InvokeLifecycle */; + } + else { + viewPortPlanStrategy = "no-change" /* NoChange */; + } + return viewPortPlanStrategy; +}; +/**@internal exported for unit testing */ +var hasDifferentParameterValues = function (prev, next) { + var prevParams = prev.params; + var nextParams = next.params; + var nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; + for (var key in nextParams) { + if (key === nextWildCardName) { + continue; + } + if (prevParams[key] !== nextParams[key]) { + return true; + } + } + for (var key in prevParams) { + if (key === nextWildCardName) { + continue; + } + if (prevParams[key] !== nextParams[key]) { + return true; + } + } + if (!next.options.compareQueryParams) { + return false; + } + var prevQueryParams = prev.queryParams; + var nextQueryParams = next.queryParams; + for (var key in nextQueryParams) { + if (prevQueryParams[key] !== nextQueryParams[key]) { + return true; + } + } + for (var key in prevQueryParams) { + if (prevQueryParams[key] !== nextQueryParams[key]) { + return true; + } + } + return false; +}; + +/** + * Transform a navigation instruction into viewport plan record object, + * or a redirect request if user viewmodel demands + */ +var BuildNavigationPlanStep = /** @class */ (function () { + function BuildNavigationPlanStep() { + } + BuildNavigationPlanStep.prototype.run = function (navigationInstruction, next) { + return _buildNavigationPlan(navigationInstruction) + .then(function (plan) { + if (plan instanceof Redirect) { + return next.cancel(plan); + } + navigationInstruction.plan = plan; + return next(); + }) + .catch(next.cancel); + }; + return BuildNavigationPlanStep; +}()); + +/** + * @internal Exported for unit testing + */ +var loadNewRoute = function (routeLoader, navigationInstruction) { + var loadingPlans = determineLoadingPlans(navigationInstruction); + var loadPromises = loadingPlans.map(function (loadingPlan) { return loadRoute(routeLoader, loadingPlan.navigationInstruction, loadingPlan.viewPortPlan); }); + return Promise.all(loadPromises); +}; +/** + * @internal Exported for unit testing + */ +var determineLoadingPlans = function (navigationInstruction, loadingPlans) { + if (loadingPlans === void 0) { loadingPlans = []; } + var viewPortPlans = navigationInstruction.plan; + for (var viewPortName in viewPortPlans) { + var viewPortPlan = viewPortPlans[viewPortName]; + var childNavInstruction = viewPortPlan.childNavigationInstruction; + if (viewPortPlan.strategy === "replace" /* Replace */) { + loadingPlans.push({ viewPortPlan: viewPortPlan, navigationInstruction: navigationInstruction }); + if (childNavInstruction) { + determineLoadingPlans(childNavInstruction, loadingPlans); + } + } + else { + var viewPortInstruction = navigationInstruction.addViewPortInstruction({ + name: viewPortName, + strategy: viewPortPlan.strategy, + moduleId: viewPortPlan.prevModuleId, + component: viewPortPlan.prevComponent + }); + if (childNavInstruction) { + viewPortInstruction.childNavigationInstruction = childNavInstruction; + determineLoadingPlans(childNavInstruction, loadingPlans); + } + } + } + return loadingPlans; +}; +/** + * @internal Exported for unit testing + */ +var loadRoute = function (routeLoader, navigationInstruction, viewPortPlan) { + var planConfig = viewPortPlan.config; + var moduleId = planConfig ? planConfig.moduleId : null; + return loadComponent(routeLoader, navigationInstruction, planConfig) + .then(function (component) { + var viewPortInstruction = navigationInstruction.addViewPortInstruction({ + name: viewPortPlan.name, + strategy: viewPortPlan.strategy, + moduleId: moduleId, + component: component }); - if (path) { - var settings = config.settings; - delete config.settings; - var withChild = JSON.parse(JSON.stringify(config)); - config.settings = settings; - withChild.route = path + "/*childRoute"; - withChild.hasChildRouter = true; - this._childRecognizer.add({ - path: withChild.route, - handler: withChild, - caseSensitive: caseSensitive + var childRouter = component.childRouter; + if (childRouter) { + var path = navigationInstruction.getWildcardPath(); + return childRouter + ._createNavigationInstruction(path, navigationInstruction) + .then(function (childInstruction) { + viewPortPlan.childNavigationInstruction = childInstruction; + return _buildNavigationPlan(childInstruction) + .then(function (childPlan) { + if (childPlan instanceof Redirect) { + return Promise.reject(childPlan); + } + childInstruction.plan = childPlan; + viewPortInstruction.childNavigationInstruction = childInstruction; + return loadNewRoute(routeLoader, childInstruction); + }); }); - withChild.navModel = navModel; - withChild.settings = config.settings; - withChild.navigationStrategy = config.navigationStrategy; } - config.navModel = navModel; - var navigation = this.navigation; - if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) { - if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) { - throw new Error('Invalid route config for "' + config.route + '" : dynamic routes must specify an "href:" to be included in the navigation model.'); - } - if (typeof navModel.order !== 'number') { - navModel.order = ++this._fallbackOrder; - } - navigation.push(navModel); - // this is a potential error / inconsistency between browsers - // - // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort - // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, - // but sorted with respect to all different elements. - // Note: the ECMAscript standard does not guarantee this behaviour, - // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this. - navigation.sort(function (a, b) { return a.order - b.order; }); + // ts complains without this, though they are same + return void 0; + }); +}; +/** + * Load a routed-component based on navigation instruction and route config + * @internal exported for unit testing only + */ +var loadComponent = function (routeLoader, navigationInstruction, config) { + var router = navigationInstruction.router; + var lifecycleArgs = navigationInstruction.lifecycleArgs; + return Promise.resolve() + .then(function () { return routeLoader.loadRoute(router, config, navigationInstruction); }) + .then( + /** + * @param component an object carrying information about loaded route + * typically contains information about view model, childContainer, view and router + */ + function (component) { + var viewModel = component.viewModel, childContainer = component.childContainer; + component.router = router; + component.config = config; + if ('configureRouter' in viewModel) { + var childRouter_1 = childContainer.getChildRouter(); + component.childRouter = childRouter_1; + return childRouter_1 + .configure(function (c) { return viewModel.configureRouter(c, childRouter_1, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]); }) + .then(function () { return component; }); } - }; + return component; + }); +}; + +/** + * Abstract class that is responsible for loading view / view model from a route config + * The default implementation can be found in `aurelia-templating-router` + */ +var RouteLoader = /** @class */ (function () { + function RouteLoader() { + } /** - * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name. - * - * @param name The name of the route to check. - */ - Router.prototype.hasRoute = function (name) { - return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name)); + * Load a route config based on its viewmodel / view configuration + */ + // return typing: return typings used to be never + // as it was a throw. Changing it to Promise should not cause any issues + RouteLoader.prototype.loadRoute = function (router, config, navigationInstruction) { + throw new Error('Route loaders must implement "loadRoute(router, config, navigationInstruction)".'); }; + return RouteLoader; +}()); + +/** + * A pipeline step responsible for loading a route config of a navigation instruction + */ +var LoadRouteStep = /** @class */ (function () { + function LoadRouteStep(routeLoader) { + this.routeLoader = routeLoader; + } + /**@internal */ + LoadRouteStep.inject = function () { return [RouteLoader]; }; /** - * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name. - * - * @param name The name of the route to check. - */ - Router.prototype.hasOwnRoute = function (name) { - return this._recognizer.hasRoute(name); + * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline + */ + LoadRouteStep.prototype.run = function (navigationInstruction, next) { + return loadNewRoute(this.routeLoader, navigationInstruction) + .then(next, next.cancel); }; - /** - * Register a handler to use when the incoming URL fragment doesn't match any registered routes. - * - * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]]. - */ - Router.prototype.handleUnknownRoutes = function (config) { - var _this = this; - if (!config) { - throw new Error('Invalid unknown route handler'); - } - this.catchAllHandler = function (instruction) { - return _this - ._createRouteConfig(config, instruction) - .then(function (c) { - instruction.config = c; - return instruction; - }); - }; + return LoadRouteStep; +}()); + +/** + * A pipeline step for instructing a piepline to commit changes on a navigation instruction + */ +var CommitChangesStep = /** @class */ (function () { + function CommitChangesStep() { + } + CommitChangesStep.prototype.run = function (navigationInstruction, next) { + return navigationInstruction + ._commitChanges(/*wait to swap?*/ true) + .then(function () { + navigationInstruction._updateTitle(); + return next(); + }); }; + return CommitChangesStep; +}()); + +/** + * An optional interface describing the available activation strategies. + * @internal Used internally. + */ +var InternalActivationStrategy; +(function (InternalActivationStrategy) { /** - * Updates the document title using the current navigation instruction. - */ - Router.prototype.updateTitle = function () { - var parentRouter = this.parent; - if (parentRouter) { - return parentRouter.updateTitle(); - } - var currentInstruction = this.currentInstruction; - if (currentInstruction) { - currentInstruction._updateTitle(); - } - return undefined; - }; + * Reuse the existing view model, without invoking Router lifecycle hooks. + */ + InternalActivationStrategy["NoChange"] = "no-change"; /** - * Updates the navigation routes with hrefs relative to the current location. - * Note: This method will likely move to a plugin in a future release. - */ - Router.prototype.refreshNavigation = function () { - var nav = this.navigation; - for (var i = 0, length_1 = nav.length; i < length_1; i++) { - var current = nav[i]; - if (!current.config.href) { - current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState); - } - else { - current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState); - } - } - }; + * Reuse the existing view model, invoking Router lifecycle hooks. + */ + InternalActivationStrategy["InvokeLifecycle"] = "invoke-lifecycle"; /** - * Sets the default configuration for the view ports. This specifies how to - * populate a view port for which no module is specified. The default is - * an empty view/view-model pair. + * Replace the existing view model, invoking Router lifecycle hooks. */ - Router.prototype.useViewPortDefaults = function ($viewPortDefaults) { - // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction - var viewPortDefaults = $viewPortDefaults; - for (var viewPortName in viewPortDefaults) { - var viewPortConfig = viewPortDefaults[viewPortName]; - this.viewPortDefaults[viewPortName] = { - moduleId: viewPortConfig.moduleId - }; - } - }; - /**@internal */ - Router.prototype._refreshBaseUrl = function () { - var parentRouter = this.parent; - if (parentRouter) { - this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction); - } - }; - /**@internal */ - Router.prototype._createNavigationInstruction = function (url, parentInstruction) { - if (url === void 0) { url = ''; } - if (parentInstruction === void 0) { parentInstruction = null; } - var fragment = url; - var queryString = ''; - var queryIndex = url.indexOf('?'); - if (queryIndex !== -1) { - fragment = url.substr(0, queryIndex); - queryString = url.substr(queryIndex + 1); - } - var urlRecognizationResults = this._recognizer.recognize(url); - if (!urlRecognizationResults || !urlRecognizationResults.length) { - urlRecognizationResults = this._childRecognizer.recognize(url); - } - var instructionInit = { - fragment: fragment, - queryString: queryString, - config: null, - parentInstruction: parentInstruction, - previousInstruction: this.currentInstruction, - router: this, - options: { - compareQueryParams: this.options.compareQueryParams - } - }; - var result; - if (urlRecognizationResults && urlRecognizationResults.length) { - var first = urlRecognizationResults[0]; - var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: first.params, - queryParams: first.queryParams || urlRecognizationResults.queryParams, - config: first.config || first.handler - })); - if (typeof first.handler === 'function') { - result = evaluateNavigationStrategy(instruction, first.handler, first); - } - else if (first.handler && typeof first.handler.navigationStrategy === 'function') { - result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); + InternalActivationStrategy["Replace"] = "replace"; +})(InternalActivationStrategy || (InternalActivationStrategy = {})); +/** + * The strategy to use when activating modules during navigation. + */ +// kept for compat reason +var activationStrategy = { + noChange: "no-change" /* NoChange */, + invokeLifecycle: "invoke-lifecycle" /* InvokeLifecycle */, + replace: "replace" /* Replace */ +}; + +/** + * Recursively find list of deactivate-able view models + * and invoke the either 'canDeactivate' or 'deactivate' on each + * @internal exported for unit testing + */ +var processDeactivatable = function (navigationInstruction, callbackName, next, ignoreResult) { + var plan = navigationInstruction.plan; + var infos = findDeactivatable(plan, callbackName); + var i = infos.length; // query from inside out + function inspect(val) { + if (ignoreResult || shouldContinue(val)) { + return iterate(); + } + return next.cancel(val); + } + function iterate() { + if (i--) { + try { + var viewModel = infos[i]; + var result = viewModel[callbackName](navigationInstruction); + return processPotential(result, inspect, next.cancel); } - else { - result = Promise.resolve(instruction); + catch (error) { + return next.cancel(error); } } - else if (this.catchAllHandler) { - var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: { path: fragment }, - queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, - config: null // config will be created by the catchAllHandler - })); - result = evaluateNavigationStrategy(instruction, this.catchAllHandler); - } - else if (this.parent) { - var router = this._parentCatchAllHandler(this.parent); - if (router) { - var newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction); - var instruction = new NavigationInstruction(Object.assign({}, instructionInit, { - params: { path: fragment }, - queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {}, - router: router, - parentInstruction: newParentInstruction, - parentCatchHandler: true, - config: null // config will be created by the chained parent catchAllHandler - })); - result = evaluateNavigationStrategy(instruction, router.catchAllHandler); + navigationInstruction.router.couldDeactivate = true; + return next(); + } + return iterate(); +}; +/** + * Recursively find and returns a list of deactivate-able view models + * @internal exported for unit testing + */ +var findDeactivatable = function (plan, callbackName, list) { + if (list === void 0) { list = []; } + for (var viewPortName in plan) { + var viewPortPlan = plan[viewPortName]; + var prevComponent = viewPortPlan.prevComponent; + if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace) + && prevComponent) { + var viewModel = prevComponent.viewModel; + if (callbackName in viewModel) { + list.push(viewModel); } } - if (result && parentInstruction) { - this.baseUrl = generateBaseUrl(this.parent, parentInstruction); - } - return result || Promise.reject(new Error("Route not found: " + url)); - }; - /**@internal */ - Router.prototype._findParentInstructionFromRouter = function (router, instruction) { - if (instruction.router === router) { - instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId - return instruction; + if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) { + addPreviousDeactivatable(prevComponent, callbackName, list); } - else if (instruction.parentInstruction) { - return this._findParentInstructionFromRouter(router, instruction.parentInstruction); + else if (viewPortPlan.childNavigationInstruction) { + findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list); } - return undefined; - }; - /**@internal */ - Router.prototype._parentCatchAllHandler = function (router) { - if (router.catchAllHandler) { - return router; + } + return list; +}; +/** + * @internal exported for unit testing + */ +var addPreviousDeactivatable = function (component, callbackName, list) { + var childRouter = component.childRouter; + if (childRouter && childRouter.currentInstruction) { + var viewPortInstructions = childRouter.currentInstruction.viewPortInstructions; + for (var viewPortName in viewPortInstructions) { + var viewPortInstruction = viewPortInstructions[viewPortName]; + var prevComponent = viewPortInstruction.component; + var prevViewModel = prevComponent.viewModel; + if (callbackName in prevViewModel) { + list.push(prevViewModel); + } + addPreviousDeactivatable(prevComponent, callbackName, list); } - else if (router.parent) { - return this._parentCatchAllHandler(router.parent); + } +}; +/** + * @internal exported for unit testing + */ +var processActivatable = function (navigationInstruction, callbackName, next, ignoreResult) { + var infos = findActivatable(navigationInstruction, callbackName); + var length = infos.length; + var i = -1; // query from top down + function inspect(val, router) { + if (ignoreResult || shouldContinue(val, router)) { + return iterate(); } - return false; - }; - /** - * @internal - */ - Router.prototype._createRouteConfig = function (config, instruction) { - var _this = this; - return Promise - .resolve(config) - .then(function (c) { - if (typeof c === 'string') { - return { moduleId: c }; - } - else if (typeof c === 'function') { - return c(instruction); + return next.cancel(val); + } + function iterate() { + var _a; + i++; + if (i < length) { + try { + var current_1 = infos[i]; + var result = (_a = current_1.viewModel)[callbackName].apply(_a, current_1.lifecycleArgs); + return processPotential(result, function (val) { return inspect(val, current_1.router); }, next.cancel); } - return c; - }) - // typing here could be either RouteConfig or RedirectConfig - // but temporarily treat both as RouteConfig - // todo: improve typings precision - .then(function (c) { return typeof c === 'string' ? { moduleId: c } : c; }) - .then(function (c) { - c.route = instruction.params.path; - validateRouteConfig(c); - if (!c.navModel) { - c.navModel = _this.createNavModel(c); + catch (error) { + return next.cancel(error); } - return c; - }); - }; - return Router; -}()); -/* @internal exported for unit testing */ -var generateBaseUrl = function (router, instruction) { - return "" + (router.baseUrl || '') + (instruction.getBaseUrl() || ''); + } + return next(); + } + return iterate(); }; -/* @internal exported for unit testing */ -var validateRouteConfig = function (config) { - if (typeof config !== 'object') { - throw new Error('Invalid Route Config'); +/** + * Find list of activatable view model and add to list (3rd parameter) + * @internal exported for unit testing + */ +var findActivatable = function (navigationInstruction, callbackName, list, router) { + if (list === void 0) { list = []; } + var plan = navigationInstruction.plan; + Object + .keys(plan) + .forEach(function (viewPortName) { + var viewPortPlan = plan[viewPortName]; + var viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName]; + var viewPortComponent = viewPortInstruction.component; + var viewModel = viewPortComponent.viewModel; + if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle + || viewPortPlan.strategy === activationStrategy.replace) + && callbackName in viewModel) { + list.push({ + viewModel: viewModel, + lifecycleArgs: viewPortInstruction.lifecycleArgs, + router: router + }); + } + var childNavInstruction = viewPortPlan.childNavigationInstruction; + if (childNavInstruction) { + findActivatable(childNavInstruction, callbackName, list, viewPortComponent.childRouter || router); + } + }); + return list; +}; +var shouldContinue = function (output, router) { + if (output instanceof Error) { + return false; } - if (typeof config.route !== 'string') { - var name_1 = config.name || '(no name)'; - throw new Error('Invalid Route Config for "' + name_1 + '": You must specify a "route:" pattern.'); + if (isNavigationCommand(output)) { + if (typeof output.setRouter === 'function') { + output.setRouter(router); + } + return !!output.shouldContinueProcessing; } - if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) { - throw new Error('Invalid Route Config for "' + config.route + '": You must specify a "moduleId:", "redirect:", "navigationStrategy:", or "viewPorts:".'); + if (output === undefined) { + return true; } + return output; }; -/* @internal exported for unit testing */ -var evaluateNavigationStrategy = function (instruction, evaluator, context) { - return Promise.resolve(evaluator.call(context, instruction)).then(function () { - if (!('viewPorts' in instruction.config)) { - instruction.config.viewPorts = { - 'default': { - moduleId: instruction.config.moduleId - } - }; - } - return instruction; - }); -}; - -/**@internal exported for unit testing */ -var createNextFn = function (instruction, steps) { - var index = -1; - var next = function () { - index++; - if (index < steps.length) { - var currentStep = steps[index]; - try { - return currentStep(instruction, next); - } - catch (e) { - return next.reject(e); - } +/** + * wraps a subscription, allowing unsubscribe calls even if + * the first value comes synchronously + */ +var SafeSubscription = /** @class */ (function () { + function SafeSubscription(subscriptionFunc) { + this._subscribed = true; + this._subscription = subscriptionFunc(this); + if (!this._subscribed) { + this.unsubscribe(); } - else { - return next.complete(); + } + Object.defineProperty(SafeSubscription.prototype, "subscribed", { + get: function () { + return this._subscribed; + }, + enumerable: true, + configurable: true + }); + SafeSubscription.prototype.unsubscribe = function () { + if (this._subscribed && this._subscription) { + this._subscription.unsubscribe(); } + this._subscribed = false; }; - next.complete = createCompletionHandler(next, "completed" /* Completed */); - next.cancel = createCompletionHandler(next, "canceled" /* Canceled */); - next.reject = createCompletionHandler(next, "rejected" /* Rejected */); - return next; -}; -/**@internal exported for unit testing */ -var createCompletionHandler = function (next, status) { - return function (output) { return Promise - .resolve({ - status: status, - output: output, - completed: status === "completed" /* Completed */ - }); }; -}; - + return SafeSubscription; +}()); /** -* The class responsible for managing and processing the navigation pipeline. -*/ -var Pipeline = /** @class */ (function () { - function Pipeline() { - /** - * The pipeline steps. And steps added via addStep will be converted to a function - * The actualy running functions with correct step contexts of this pipeline - */ - this.steps = []; + * A function to process return value from `activate`/`canActivate` steps + * Supports observable/promise + * + * For observable, resolve at first next() or on complete() + */ +var processPotential = function (obj, resolve, reject) { + // if promise like + if (obj && typeof obj.then === 'function') { + return Promise.resolve(obj).then(resolve).catch(reject); } - /** - * Adds a step to the pipeline. - * - * @param step The pipeline step. - */ - Pipeline.prototype.addStep = function (step) { - var run; - if (typeof step === 'function') { - run = step; - } - else if (typeof step.getSteps === 'function') { - // getSteps is to enable support open slots - // where devs can add multiple steps into the same slot name - var steps = step.getSteps(); - for (var i = 0, l = steps.length; i < l; i++) { - this.addStep(steps[i]); + // if observable + if (obj && typeof obj.subscribe === 'function') { + var obs_1 = obj; + return new SafeSubscription(function (sub) { return obs_1.subscribe({ + next: function () { + if (sub.subscribed) { + sub.unsubscribe(); + resolve(obj); + } + }, + error: function (error) { + if (sub.subscribed) { + sub.unsubscribe(); + reject(error); + } + }, + complete: function () { + if (sub.subscribed) { + sub.unsubscribe(); + resolve(obj); + } } - return this; - } - else { - run = step.run.bind(step); - } - this.steps.push(run); - return this; - }; - /** - * Runs the pipeline. - * - * @param instruction The navigation instruction to process. - */ - Pipeline.prototype.run = function (instruction) { - var nextFn = createNextFn(instruction, this.steps); - return nextFn(); - }; - return Pipeline; -}()); + }); }); + } + // else just resolve + try { + return resolve(obj); + } + catch (error) { + return reject(error); + } +}; /** - * Abstract class that is responsible for loading view / view model from a route config - * The default implementation can be found in `aurelia-templating-router` + * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route */ -var RouteLoader = /** @class */ (function () { - function RouteLoader() { +var CanDeactivatePreviousStep = /** @class */ (function () { + function CanDeactivatePreviousStep() { } - /** - * Load a route config based on its viewmodel / view configuration - */ - // return typing: return typings used to be never - // as it was a throw. Changing it to Promise should not cause any issues - RouteLoader.prototype.loadRoute = function (router, config, navigationInstruction) { - throw new Error('Route loaders must implement "loadRoute(router, config, navigationInstruction)".'); + CanDeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { + return processDeactivatable(navigationInstruction, 'canDeactivate', next); }; - return RouteLoader; + return CanDeactivatePreviousStep; }()); /** - * A pipeline step responsible for loading a route config of a navigation instruction + * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route */ -var LoadRouteStep = /** @class */ (function () { - function LoadRouteStep(routeLoader) { - this.routeLoader = routeLoader; +var CanActivateNextStep = /** @class */ (function () { + function CanActivateNextStep() { } - /**@internal */ - LoadRouteStep.inject = function () { return [RouteLoader]; }; - /** - * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline - */ - LoadRouteStep.prototype.run = function (navigationInstruction, next) { - return loadNewRoute(this.routeLoader, navigationInstruction) - .then(next, next.cancel); + CanActivateNextStep.prototype.run = function (navigationInstruction, next) { + return processActivatable(navigationInstruction, 'canActivate', next); }; - return LoadRouteStep; + return CanActivateNextStep; }()); /** - * @internal Exported for unit testing - */ -var loadNewRoute = function (routeLoader, navigationInstruction) { - var toLoad = determineWhatToLoad(navigationInstruction); - var loadPromises = toLoad.map(function (loadingPlan) { return loadRoute(routeLoader, loadingPlan.navigationInstruction, loadingPlan.viewPortPlan); }); - return Promise.all(loadPromises); -}; -/** - * @internal Exported for unit testing + * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route */ -var determineWhatToLoad = function (navigationInstruction, toLoad) { - if (toLoad === void 0) { toLoad = []; } - var plan = navigationInstruction.plan; - for (var viewPortName in plan) { - var viewPortPlan = plan[viewPortName]; - var child_nav_instruction = viewPortPlan.childNavigationInstruction; - if (viewPortPlan.strategy === activationStrategy.replace) { - toLoad.push({ viewPortPlan: viewPortPlan, navigationInstruction: navigationInstruction }); - if (child_nav_instruction) { - determineWhatToLoad(child_nav_instruction, toLoad); - } - } - else { - var viewPortInstruction = navigationInstruction.addViewPortInstruction(viewPortName, viewPortPlan.strategy, viewPortPlan.prevModuleId, viewPortPlan.prevComponent); - if (child_nav_instruction) { - viewPortInstruction.childNavigationInstruction = child_nav_instruction; - determineWhatToLoad(child_nav_instruction, toLoad); - } - } +var DeactivatePreviousStep = /** @class */ (function () { + function DeactivatePreviousStep() { } - return toLoad; -}; -/** - * @internal Exported for unit testing - */ -var loadRoute = function (routeLoader, navigationInstruction, viewPortPlan) { - var moduleId = viewPortPlan.config ? viewPortPlan.config.moduleId : null; - return loadComponent(routeLoader, navigationInstruction, viewPortPlan.config) - .then(function (component) { - var viewPortInstruction = navigationInstruction.addViewPortInstruction(viewPortPlan.name, viewPortPlan.strategy, moduleId, component); - var childRouter = component.childRouter; - if (childRouter) { - var path = navigationInstruction.getWildcardPath(); - return childRouter - ._createNavigationInstruction(path, navigationInstruction) - .then(function (childInstruction) { - viewPortPlan.childNavigationInstruction = childInstruction; - return _buildNavigationPlan(childInstruction) - .then(function (childPlan) { - if (childPlan instanceof Redirect) { - return Promise.reject(childPlan); - } - childInstruction.plan = childPlan; - viewPortInstruction.childNavigationInstruction = childInstruction; - return loadNewRoute(routeLoader, childInstruction); - }); - }); - } - // ts complains without this, though they are same - return void 0; - }); -}; + DeactivatePreviousStep.prototype.run = function (navigationInstruction, next) { + return processDeactivatable(navigationInstruction, 'deactivate', next, true); + }; + return DeactivatePreviousStep; +}()); /** - * Load a routed-component based on navigation instruction and route config - * @internal exported for unit testing only + * A pipeline step responsible for finding and activating method `activate` on a view model of a route */ -var loadComponent = function (routeLoader, navigationInstruction, config) { - var router = navigationInstruction.router; - var lifecycleArgs = navigationInstruction.lifecycleArgs; - return Promise.resolve() - .then(function () { return routeLoader.loadRoute(router, config, navigationInstruction); }) - .then( - /** - * @param component an object carrying information about loaded route - * typically contains information about view model, childContainer, view and router - */ - function (component) { - var viewModel = component.viewModel, childContainer = component.childContainer; - component.router = router; - component.config = config; - if ('configureRouter' in viewModel) { - var childRouter_1 = childContainer.getChildRouter(); - component.childRouter = childRouter_1; - return childRouter_1 - .configure(function (c) { return viewModel.configureRouter(c, childRouter_1, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]); }) - .then(function () { return component; }); - } - return component; - }); -}; +var ActivateNextStep = /** @class */ (function () { + function ActivateNextStep() { + } + ActivateNextStep.prototype.run = function (navigationInstruction, next) { + return processActivatable(navigationInstruction, 'activate', next, true); + }; + return ActivateNextStep; +}()); /** * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution @@ -1769,8 +1887,8 @@ var PipelineSlot = /** @class */ (function () { return PipelineSlot; }()); /** -* Class responsible for creating the navigation pipeline. -*/ + * Class responsible for creating the navigation pipeline. + */ var PipelineProvider = /** @class */ (function () { function PipelineProvider(container) { this.container = container; @@ -1778,22 +1896,22 @@ var PipelineProvider = /** @class */ (function () { BuildNavigationPlanStep, CanDeactivatePreviousStep, LoadRouteStep, - this._createPipelineSlot("authorize" /* Authorize */), + createPipelineSlot(container, "authorize" /* Authorize */), CanActivateNextStep, - this._createPipelineSlot("preActivate" /* PreActivate */, 'modelbind'), + createPipelineSlot(container, "preActivate" /* PreActivate */, 'modelbind'), // NOTE: app state changes start below - point of no return DeactivatePreviousStep, ActivateNextStep, - this._createPipelineSlot("preRender" /* PreRender */, 'precommit'), + createPipelineSlot(container, "preRender" /* PreRender */, 'precommit'), CommitChangesStep, - this._createPipelineSlot("postRender" /* PostRender */, 'postcomplete') + createPipelineSlot(container, "postRender" /* PostRender */, 'postcomplete') ]; } /**@internal */ PipelineProvider.inject = function () { return [Container]; }; /** - * Create the navigation pipeline. - */ + * Create the navigation pipeline. + */ PipelineProvider.prototype.createPipeline = function (useCanDeactivateStep) { var _this = this; if (useCanDeactivateStep === void 0) { useCanDeactivateStep = true; } @@ -1811,14 +1929,15 @@ var PipelineProvider = /** @class */ (function () { return this.steps.find(function (x) { return x.slotName === name || x.slotAlias === name; }); }; /** - * Adds a step into the pipeline at a known slot location. - */ + * Adds a step into the pipeline at a known slot location. + */ PipelineProvider.prototype.addStep = function (name, step) { var found = this._findStep(name); if (found) { + var slotSteps = found.steps; // prevent duplicates - if (!found.steps.includes(step)) { - found.steps.push(step); + if (!slotSteps.includes(step)) { + slotSteps.push(step); } } else { @@ -1831,13 +1950,13 @@ var PipelineProvider = /** @class */ (function () { PipelineProvider.prototype.removeStep = function (name, step) { var slot = this._findStep(name); if (slot) { - var steps = slot.steps; - steps.splice(steps.indexOf(step), 1); + var slotSteps = slot.steps; + slotSteps.splice(slotSteps.indexOf(step), 1); } }; /** - * @internal * Clears all steps from a slot in the pipeline + * @internal */ PipelineProvider.prototype._clearSteps = function (name) { if (name === void 0) { name = ''; } @@ -1850,22 +1969,22 @@ var PipelineProvider = /** @class */ (function () { * Resets all pipeline slots */ PipelineProvider.prototype.reset = function () { - this._clearSteps('authorize'); - this._clearSteps('preActivate'); - this._clearSteps('preRender'); - this._clearSteps('postRender'); - }; - /**@internal */ - PipelineProvider.prototype._createPipelineSlot = function (name, alias) { - return new PipelineSlot(this.container, name, alias); + this._clearSteps("authorize" /* Authorize */); + this._clearSteps("preActivate" /* PreActivate */); + this._clearSteps("preRender" /* PreRender */); + this._clearSteps("postRender" /* PostRender */); }; return PipelineProvider; -}()); +}()); +/**@internal */ +var createPipelineSlot = function (container, name, alias) { + return new PipelineSlot(container, name, alias); +}; var logger = getLogger('app-router'); /** -* The main application router. -*/ + * The main application router. + */ var AppRouter = /** @class */ (function (_super) { __extends(AppRouter, _super); function AppRouter(container, history, pipelineProvider, events) { @@ -1877,9 +1996,9 @@ var AppRouter = /** @class */ (function (_super) { /**@internal */ AppRouter.inject = function () { return [Container, History, PipelineProvider, EventAggregator]; }; /** - * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. - * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. - */ + * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made. + * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model. + */ AppRouter.prototype.reset = function () { _super.prototype.reset.call(this); this.maxInstructionCount = 10; @@ -1891,10 +2010,10 @@ var AppRouter = /** @class */ (function (_super) { } }; /** - * Loads the specified URL. - * - * @param url The URL fragment to load. - */ + * Loads the specified URL. + * + * @param url The URL fragment to load. + */ AppRouter.prototype.loadUrl = function (url) { var _this = this; return this @@ -1906,11 +2025,11 @@ var AppRouter = /** @class */ (function (_super) { }); }; /** - * Registers a viewPort to be used as a rendering target for activated routes. - * - * @param viewPort The viewPort. This is typically a element in Aurelia default impl - * @param name The name of the viewPort. 'default' if unspecified. - */ + * Registers a viewPort to be used as a rendering target for activated routes. + * + * @param viewPort The viewPort. This is typically a element in Aurelia default impl + * @param name The name of the viewPort. 'default' if unspecified. + */ AppRouter.prototype.registerViewPort = function (viewPort, name) { var _this = this; // having strong typing without changing public API @@ -1954,10 +2073,10 @@ var AppRouter = /** @class */ (function (_super) { return Promise.resolve(); }; /** - * Activates the router. This instructs the router to begin listening for history changes and processing instructions. - * - * @params options The set of options to activate the router with. - */ + * Activates the router. This instructs the router to begin listening for history changes and processing instructions. + * + * @params options The set of options to activate the router with. + */ AppRouter.prototype.activate = function (options) { if (this.isActive) { return; @@ -1970,8 +2089,8 @@ var AppRouter = /** @class */ (function (_super) { this._dequeueInstruction(); }; /** - * Deactivates the router. - */ + * Deactivates the router. + */ AppRouter.prototype.deactivate = function () { this.isActive = false; this.history.deactivate(); @@ -2002,20 +2121,21 @@ var AppRouter = /** @class */ (function (_super) { } _this.isNavigating = true; var navtracker = _this.history.getState('NavigationTracker'); - if (!navtracker && !_this.currentNavigationTracker) { + var currentNavTracker = _this.currentNavigationTracker; + if (!navtracker && !currentNavTracker) { _this.isNavigatingFirst = true; _this.isNavigatingNew = true; } else if (!navtracker) { _this.isNavigatingNew = true; } - else if (!_this.currentNavigationTracker) { + else if (!currentNavTracker) { _this.isNavigatingRefresh = true; } - else if (_this.currentNavigationTracker < navtracker) { + else if (currentNavTracker < navtracker) { _this.isNavigatingForward = true; } - else if (_this.currentNavigationTracker > navtracker) { + else if (currentNavTracker > navtracker) { _this.isNavigatingBack = true; } if (!navtracker) { @@ -2024,15 +2144,16 @@ var AppRouter = /** @class */ (function (_super) { } _this.currentNavigationTracker = navtracker; instruction.previousInstruction = _this.currentInstruction; + var maxInstructionCount = _this.maxInstructionCount; if (!instructionCount) { _this.events.publish("router:navigation:processing" /* Processing */, { instruction: instruction }); } - else if (instructionCount === _this.maxInstructionCount - 1) { + else if (instructionCount === maxInstructionCount - 1) { logger.error(instructionCount + 1 + " navigation instructions have been attempted without success. Restoring last known good location."); restorePreviousLocation(_this); return _this._dequeueInstruction(instructionCount + 1); } - else if (instructionCount > _this.maxInstructionCount) { + else if (instructionCount > maxInstructionCount) { throw new Error('Maximum navigation attempts exceeded. Giving up.'); } var pipeline = _this.pipelineProvider.createPipeline(!_this.couldDeactivate); @@ -2089,6 +2210,7 @@ var processResult = function (instruction, result, instructionCount, router) { }; var resolveInstruction = function (instruction, result, isInnerInstruction, router) { instruction.resolve(result); + var eventAggregator = router.events; var eventArgs = { instruction: instruction, result: result }; if (!isInnerInstruction) { router.isNavigating = false; @@ -2112,18 +2234,18 @@ var resolveInstruction = function (instruction, result, isInnerInstruction, rout router.history.previousLocation = instruction.fragment + queryString; eventName = "router:navigation:success" /* Success */; } - router.events.publish(eventName, eventArgs); - router.events.publish("router:navigation:complete" /* Complete */, eventArgs); + eventAggregator.publish(eventName, eventArgs); + eventAggregator.publish("router:navigation:complete" /* Complete */, eventArgs); } else { - router.events.publish("router:navigation:child:complete" /* ChildComplete */, eventArgs); + eventAggregator.publish("router:navigation:child:complete" /* ChildComplete */, eventArgs); } return result; }; var restorePreviousLocation = function (router) { var previousLocation = router.history.previousLocation; if (previousLocation) { - router.navigate(router.history.previousLocation, { trigger: false, replace: true }); + router.navigate(previousLocation, { trigger: false, replace: true }); } else if (router.fallbackRoute) { router.navigate(router.fallbackRoute, { trigger: true, replace: true }); diff --git a/dist/native-modules/aurelia-router.js.map b/dist/native-modules/aurelia-router.js.map index af45ee39..0144b744 100644 --- a/dist/native-modules/aurelia-router.js.map +++ b/dist/native-modules/aurelia-router.js.map @@ -1 +1 @@ -{"version":3,"file":"aurelia-router.js","sources":["../../src/navigation-commands.ts","../../src/navigation-plan.ts","../../src/activation.ts","../../src/navigation-instruction.ts","../../src/nav-model.ts","../../src/util.ts","../../src/router-configuration.ts","../../src/router.ts","../../src/next.ts","../../src/pipeline.ts","../../src/route-loading.ts","../../src/pipeline-provider.ts","../../src/app-router.ts","../../src/pipeline-status.ts","../../src/router-event.ts","../../src/pipeline-slot-name.ts"],"sourcesContent":["import { NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface NavigationOptions {\n useAppRouter?: boolean;\n }\n}\n\n/**\n* When a navigation command is encountered, the current navigation\n* will be cancelled and control will be passed to the navigation\n* command so it can determine the correct action.\n*/\nexport interface NavigationCommand {\n navigate: (router: Router) => void;\n /**@internal */\n shouldContinueProcessing?: boolean;\n /**@internal */\n setRouter?: (router: Router) => void;\n}\n\n/**\n* Determines if the provided object is a navigation command.\n* A navigation command is anything with a navigate method.\n*\n* @param obj The object to check.\n*/\nexport function isNavigationCommand(obj: any): obj is NavigationCommand {\n return obj && typeof obj.navigate === 'function';\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect.\n*/\nexport class Redirect implements NavigationCommand {\n\n url: string;\n /**@internal */\n options: NavigationOptions;\n /**@internal */\n shouldContinueProcessing: boolean;\n\n private router: Router;\n\n /**\n * @param url The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n constructor(url: string, options: NavigationOptions = {}) {\n this.url = url;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigate(this.url, this.options);\n }\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect to a named route.\n*/\nexport class RedirectToRoute implements NavigationCommand {\n\n route: string;\n params: any;\n /**@internal */\n options: NavigationOptions;\n\n /**@internal */\n shouldContinueProcessing: boolean;\n\n /**@internal */\n router: Router;\n\n /**\n * @param route The name of the route.\n * @param params The parameters to be sent to the activation method.\n * @param options The options to use for navigation.\n */\n constructor(route: string, params: any = {}, options: NavigationOptions = {}) {\n this.route = route;\n this.params = params;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigateToRoute(this.route, this.params, this.options);\n }\n}\n","import { ActivationStrategy, Next, ViewPortPlan } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\n\n/**\n* The strategy to use when activating modules during navigation.\n*/\nexport const activationStrategy: ActivationStrategy = {\n noChange: 'no-change',\n invokeLifecycle: 'invoke-lifecycle',\n replace: 'replace'\n};\n\n/**\n * Transform a navigation instruction into viewport plan record object,\n * or a redirect request if user viewmodel demands\n */\nexport class BuildNavigationPlanStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return _buildNavigationPlan(navigationInstruction)\n .then(plan => {\n if (plan instanceof Redirect) {\n return next.cancel(plan);\n }\n navigationInstruction.plan = plan;\n return next();\n })\n .catch(next.cancel);\n }\n}\n\nexport function _buildNavigationPlan(\n instruction: NavigationInstruction,\n forceLifecycleMinimum?: boolean\n): Promise | Redirect> {\n let config = instruction.config;\n\n // todo: separate and export for unit tests\n if ('redirect' in config) {\n const router = instruction.router;\n return router\n ._createNavigationInstruction(config.redirect)\n .then(newInstruction => {\n const params: Record = {};\n for (let key in newInstruction.params) {\n // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this }\n let val = newInstruction.params[key];\n if (typeof val === 'string' && val[0] === ':') {\n val = val.slice(1);\n // And if that param is found on the original instruction then use it\n if (val in instruction.params) {\n params[key] = instruction.params[val];\n }\n } else {\n params[key] = newInstruction.params[key];\n }\n }\n let redirectLocation = router.generate(newInstruction.config, params, instruction.options);\n\n // Special handling for child routes\n for (let key in instruction.params) {\n redirectLocation = redirectLocation.replace(`:${key}`, instruction.params[key]);\n }\n\n if (instruction.queryString) {\n redirectLocation += '?' + instruction.queryString;\n }\n\n return Promise.resolve(new Redirect(redirectLocation));\n });\n }\n\n const prev = instruction.previousInstruction;\n const plan: Record = {};\n const defaults = instruction.router.viewPortDefaults;\n\n if (prev) {\n let newParams = hasDifferentParameterValues(prev, instruction);\n let pending: Promise[] = [];\n\n for (let viewPortName in prev.viewPortInstructions) {\n const prevViewPortInstruction = prev.viewPortInstructions[viewPortName];\n let nextViewPortConfig = viewPortName in config.viewPorts ? config.viewPorts[viewPortName] : prevViewPortInstruction;\n if (nextViewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) {\n nextViewPortConfig = defaults[viewPortName];\n }\n\n const viewPortPlan = plan[viewPortName] = {\n name: viewPortName,\n config: nextViewPortConfig,\n prevComponent: prevViewPortInstruction.component,\n prevModuleId: prevViewPortInstruction.moduleId\n } as ViewPortPlan;\n\n if (prevViewPortInstruction.moduleId !== nextViewPortConfig.moduleId) {\n viewPortPlan.strategy = activationStrategy.replace;\n } else if ('determineActivationStrategy' in prevViewPortInstruction.component.viewModel) {\n viewPortPlan.strategy = prevViewPortInstruction.component.viewModel\n .determineActivationStrategy(...instruction.lifecycleArgs);\n } else if (config.activationStrategy) {\n viewPortPlan.strategy = config.activationStrategy;\n } else if (newParams || forceLifecycleMinimum) {\n viewPortPlan.strategy = activationStrategy.invokeLifecycle;\n } else {\n viewPortPlan.strategy = activationStrategy.noChange;\n }\n\n if (viewPortPlan.strategy !== activationStrategy.replace && prevViewPortInstruction.childRouter) {\n const path = instruction.getWildcardPath();\n const task: Promise = prevViewPortInstruction\n .childRouter\n ._createNavigationInstruction(path, instruction)\n .then((childInstruction: any) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(\n childInstruction,\n viewPortPlan.strategy === activationStrategy.invokeLifecycle\n )\n .then(childPlan => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n // for bluebird ?\n return null;\n });\n });\n\n pending.push(task);\n }\n }\n\n return Promise.all(pending).then(() => plan);\n }\n\n for (let viewPortName in config.viewPorts) {\n let viewPortConfig = config.viewPorts[viewPortName];\n if (viewPortConfig.moduleId === null && viewPortName in instruction.router.viewPortDefaults) {\n viewPortConfig = defaults[viewPortName];\n }\n plan[viewPortName] = {\n name: viewPortName,\n strategy: activationStrategy.replace,\n config: viewPortConfig\n };\n }\n\n return Promise.resolve(plan);\n}\n\nfunction hasDifferentParameterValues(prev: NavigationInstruction, next: NavigationInstruction): boolean {\n let prevParams = prev.params;\n let nextParams = next.params;\n let nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null;\n\n for (let key in nextParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n for (let key in prevParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n if (!next.options.compareQueryParams) {\n return false;\n }\n\n let prevQueryParams = prev.queryParams;\n let nextQueryParams = next.queryParams;\n for (let key in nextQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n for (let key in prevQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n return false;\n}\n","import { Next, ViewPortComponent, ViewPortPlan, ViewPortInstruction, LifecycleArguments } from './interfaces';\nimport { isNavigationCommand } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy } from './navigation-plan';\nimport { Router } from './router';\n\n/**\n * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route\n */\nexport class CanDeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'canDeactivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route\n */\nexport class CanActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'canActivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route\n */\nexport class DeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'deactivate', next, true);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `activate` on a view model of a route\n */\nexport class ActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'activate', next, true);\n }\n}\n\n/**\n * Recursively find list of deactivate-able view models\n * and invoke the either 'canDeactivate' or 'deactivate' on each\n */\nconst processDeactivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canDeactivate' | 'deactivate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let plan: Record = navigationInstruction.plan;\n let infos = findDeactivatable(plan, callbackName);\n let i = infos.length; // query from inside out\n\n function inspect(val: any): Promise {\n if (ignoreResult || shouldContinue(val)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n if (i--) {\n try {\n let viewModel = infos[i];\n let result = viewModel[callbackName](navigationInstruction);\n return processPotential(result, inspect, next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n navigationInstruction.router.couldDeactivate = true;\n\n return next();\n }\n\n return iterate();\n};\n\n/**\n * Recursively find and returns a list of deactivate-able view models\n */\nconst findDeactivatable = (\n plan: Record,\n callbackName: string,\n list: IActivatableInfo[] = []\n): any[] => {\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let prevComponent = viewPortPlan.prevComponent;\n\n if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace)\n && prevComponent\n ) {\n let viewModel = prevComponent.viewModel;\n\n if (callbackName in viewModel) {\n list.push(viewModel);\n }\n }\n\n if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) {\n addPreviousDeactivatable(prevComponent, callbackName, list);\n } else if (viewPortPlan.childNavigationInstruction) {\n findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list);\n }\n }\n\n return list;\n};\n\nconst addPreviousDeactivatable = (\n component: ViewPortComponent,\n callbackName: string,\n list: IActivatableInfo[]\n): void => {\n let childRouter = component.childRouter;\n\n if (childRouter && childRouter.currentInstruction) {\n let viewPortInstructions = childRouter.currentInstruction.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let prevComponent = viewPortInstruction.component;\n let prevViewModel = prevComponent.viewModel;\n\n if (callbackName in prevViewModel) {\n list.push(prevViewModel);\n }\n\n addPreviousDeactivatable(prevComponent, callbackName, list);\n }\n }\n};\n\nconst processActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let infos = findActivatable(navigationInstruction, callbackName);\n let length = infos.length;\n let i = -1; // query from top down\n\n function inspect(val: any, router: Router): Promise {\n if (ignoreResult || shouldContinue(val, router)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n i++;\n\n if (i < length) {\n try {\n let current = infos[i];\n let result = current.viewModel[callbackName](...current.lifecycleArgs);\n return processPotential(result, (val: any) => inspect(val, current.router), next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n return next();\n }\n\n return iterate();\n};\n\ninterface IActivatableInfo {\n viewModel: any;\n lifecycleArgs: LifecycleArguments;\n router: Router;\n}\n\n/**\n * Find list of activatable view model and add to list (3rd parameter)\n */\nconst findActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n list: IActivatableInfo[] = [],\n router?: Router\n): IActivatableInfo[] => {\n let plan: Record = navigationInstruction.plan;\n\n Object\n .keys(plan)\n .forEach((viewPortName) => {\n let viewPortPlan = plan[viewPortName];\n let viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName] as ViewPortInstruction;\n let viewPortComponent = viewPortInstruction.component;\n let viewModel = viewPortComponent.viewModel;\n\n if (\n (viewPortPlan.strategy === activationStrategy.invokeLifecycle\n || viewPortPlan.strategy === activationStrategy.replace\n )\n && callbackName in viewModel\n ) {\n list.push({\n viewModel,\n lifecycleArgs: viewPortInstruction.lifecycleArgs,\n router\n });\n }\n\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (childNavInstruction) {\n findActivatable(\n childNavInstruction,\n callbackName,\n list,\n viewPortComponent.childRouter || router\n );\n }\n });\n\n return list;\n};\n\nconst shouldContinue = (output: T, router?: Router): boolean | T => {\n if (output instanceof Error) {\n return false;\n }\n\n if (isNavigationCommand(output)) {\n if (typeof output.setRouter === 'function') {\n output.setRouter(router);\n }\n\n return !!output.shouldContinueProcessing;\n }\n\n if (output === undefined) {\n return true;\n }\n\n return output;\n};\n\n/**\n * A basic interface for an Observable type\n */\nexport interface IObservable {\n subscribe(sub?: IObservableConfig): ISubscription;\n}\n\nexport interface IObservableConfig {\n next(): void;\n error(err?: any): void;\n complete(): void;\n}\n\n/**\n * A basic interface for a Subscription to an Observable\n */\ninterface ISubscription {\n unsubscribe(): void;\n}\n\ntype SafeSubscriptionFunc = (sub: SafeSubscription) => ISubscription;\n\n/**\n * wraps a subscription, allowing unsubscribe calls even if\n * the first value comes synchronously\n */\nclass SafeSubscription {\n\n private _subscribed: boolean;\n private _subscription: ISubscription;\n\n constructor(subscriptionFunc: SafeSubscriptionFunc) {\n this._subscribed = true;\n this._subscription = subscriptionFunc(this);\n\n if (!this._subscribed) {\n this.unsubscribe();\n }\n }\n\n get subscribed(): boolean {\n return this._subscribed;\n }\n\n unsubscribe(): void {\n if (this._subscribed && this._subscription) {\n this._subscription.unsubscribe();\n }\n\n this._subscribed = false;\n }\n}\n\n/**\n * A function to process return value from `activate`/`canActivate` steps\n * Supports observable/promise\n *\n * For observable, resolve at first next() or on complete()\n */\nconst processPotential = (obj: any, resolve: (val?: any) => any, reject: (err?: any) => any): any => {\n // if promise like\n if (obj && typeof obj.then === 'function') {\n return Promise.resolve(obj).then(resolve).catch(reject);\n }\n\n // if observable\n if (obj && typeof obj.subscribe === 'function') {\n let obs: IObservable = obj;\n return new SafeSubscription(sub => obs.subscribe({\n next() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n },\n error(error) {\n if (sub.subscribed) {\n sub.unsubscribe();\n reject(error);\n }\n },\n complete() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n }\n }));\n }\n\n // else just resolve\n try {\n return resolve(obj);\n } catch (error) {\n return reject(error);\n }\n};\n","import { ViewPortInstruction, RouteConfig, ViewPort, LifecycleArguments, ActivationStrategyType } from './interfaces';\nimport { Router } from './router';\nimport { activationStrategy } from './navigation-plan';\n\n/**\n * Initialization options for a navigation instruction\n */\nexport interface NavigationInstructionInit {\n fragment: string;\n queryString?: string;\n params?: Record;\n queryParams?: Record;\n config: RouteConfig;\n parentInstruction?: NavigationInstruction;\n previousInstruction?: NavigationInstruction;\n router: Router;\n options?: Object;\n plan?: Record;\n}\n\n/**\n * A pipeline step for instructing a piepline to commit changes on a navigation instruction\n */\nexport class CommitChangesStep {\n run(navigationInstruction: NavigationInstruction, next: Function): Promise {\n return navigationInstruction\n ._commitChanges(/*wait to swap?*/true)\n .then(() => {\n navigationInstruction._updateTitle();\n return next();\n });\n }\n}\n\n/**\n* Class used to represent an instruction during a navigation.\n*/\nexport class NavigationInstruction {\n /**\n * The URL fragment.\n */\n fragment: string;\n\n /**\n * The query string.\n */\n queryString: string;\n\n /**\n * Parameters extracted from the route pattern.\n */\n params: any;\n\n /**\n * Parameters extracted from the query string.\n */\n queryParams: any;\n\n /**\n * The route config for the route matching this instruction.\n */\n config: RouteConfig;\n\n /**\n * The parent instruction, if this instruction was created by a child router.\n */\n parentInstruction: NavigationInstruction;\n\n parentCatchHandler: any;\n\n /**\n * The instruction being replaced by this instruction in the current router.\n */\n previousInstruction: NavigationInstruction;\n\n /**\n * viewPort instructions to used activation.\n */\n viewPortInstructions: Record;\n\n /**\n * The router instance.\n */\n router: Router;\n\n /**\n * Current built viewport plan of this nav instruction\n */\n plan: Record = null;\n\n options: Record = {};\n\n /**@internal */\n lifecycleArgs: LifecycleArguments;\n /**@internal */\n resolve?: (val?: any) => void;\n\n constructor(init: NavigationInstructionInit) {\n Object.assign(this, init);\n\n this.params = this.params || {};\n this.viewPortInstructions = {};\n\n let ancestorParams = [];\n let current: NavigationInstruction = this;\n do {\n let currentParams = Object.assign({}, current.params);\n if (current.config && current.config.hasChildRouter) {\n // remove the param for the injected child route segment\n delete currentParams[current.getWildCardName()];\n }\n\n ancestorParams.unshift(currentParams);\n current = current.parentInstruction;\n } while (current);\n\n let allParams = Object.assign({}, this.queryParams, ...ancestorParams);\n this.lifecycleArgs = [allParams, this.config, this];\n }\n\n /**\n * Gets an array containing this instruction and all child instructions for the current navigation.\n */\n getAllInstructions(): Array {\n let instructions: NavigationInstruction[] = [this];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let key in viewPortInstructions) {\n let childInstruction = viewPortInstructions[key].childNavigationInstruction;\n if (childInstruction) {\n instructions.push(...childInstruction.getAllInstructions());\n }\n }\n\n return instructions;\n }\n\n /**\n * Gets an array containing the instruction and all child instructions for the previous navigation.\n * Previous instructions are no longer available after navigation completes.\n */\n getAllPreviousInstructions(): Array {\n return this.getAllInstructions().map(c => c.previousInstruction).filter(c => c);\n }\n\n /**\n * Adds a viewPort instruction. Returns the newly created instruction based on parameters\n */\n addViewPortInstruction(name: string, strategy: ActivationStrategyType, moduleId: string, component: any): /*ViewPortInstruction*/ any {\n const lifecycleArgs = this.lifecycleArgs;\n const config: RouteConfig = Object.assign({}, lifecycleArgs[1], { currentViewPort: name });\n const viewportInstruction = this.viewPortInstructions[name] = {\n name: name,\n strategy: strategy,\n moduleId: moduleId,\n component: component,\n childRouter: component.childRouter,\n lifecycleArgs: [].concat(lifecycleArgs[0], config, lifecycleArgs[2]) as LifecycleArguments\n };\n\n return viewportInstruction;\n }\n\n /**\n * Gets the name of the route pattern's wildcard parameter, if applicable.\n */\n getWildCardName(): string {\n // todo: potential issue, or at least unsafe typings\n let configRoute = this.config.route as string;\n let wildcardIndex = configRoute.lastIndexOf('*');\n return configRoute.substr(wildcardIndex + 1);\n }\n\n /**\n * Gets the path and query string created by filling the route\n * pattern's wildcard parameter with the matching param.\n */\n getWildcardPath(): string {\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n let queryString = this.queryString;\n\n if (queryString) {\n path += '?' + queryString;\n }\n\n return path;\n }\n\n /**\n * Gets the instruction's base URL, accounting for wildcard route parameters.\n */\n getBaseUrl(): string {\n let $encodeURI = encodeURI;\n let fragment = decodeURI(this.fragment);\n\n if (fragment === '') {\n let nonEmptyRoute = this.router.routes.find(route => {\n return route.name === this.config.name &&\n route.route !== '';\n });\n if (nonEmptyRoute) {\n fragment = nonEmptyRoute.route as any;\n }\n }\n\n if (!this.params) {\n return $encodeURI(fragment);\n }\n\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n\n if (!path) {\n return $encodeURI(fragment);\n }\n\n return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path)));\n }\n\n /**@internal */\n _commitChanges(waitToSwap: boolean): Promise {\n let router = this.router;\n router.currentInstruction = this;\n\n const previousInstruction = this.previousInstruction;\n if (previousInstruction) {\n previousInstruction.config.navModel.isActive = false;\n }\n\n this.config.navModel.isActive = true;\n\n router.refreshNavigation();\n\n let loads: Promise[] = [];\n let delaySwaps: ISwapPlan[] = [];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let viewPort = router.viewPorts[viewPortName];\n\n if (!viewPort) {\n throw new Error(`There was no router-view found in the view for ${viewPortInstruction.moduleId}.`);\n }\n\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n if (viewPortInstruction.strategy === activationStrategy.replace) {\n if (child_nav_instruction && child_nav_instruction.parentCatchHandler) {\n loads.push(child_nav_instruction._commitChanges(waitToSwap));\n } else {\n if (waitToSwap) {\n delaySwaps.push({ viewPort, viewPortInstruction });\n }\n loads.push(\n viewPort\n .process(viewPortInstruction, waitToSwap)\n .then(() => child_nav_instruction\n ? child_nav_instruction._commitChanges(waitToSwap)\n : Promise.resolve()\n )\n );\n }\n } else {\n if (child_nav_instruction) {\n loads.push(child_nav_instruction._commitChanges(waitToSwap));\n }\n }\n }\n\n return Promise\n .all(loads)\n .then(() => {\n delaySwaps.forEach(x => x.viewPort.swap(x.viewPortInstruction));\n return null;\n })\n .then(() => prune(this));\n }\n\n /**@internal */\n _updateTitle(): void {\n let router = this.router;\n let title = this._buildTitle(router.titleSeparator);\n if (title) {\n router.history.setTitle(title);\n }\n }\n\n /**@internal */\n _buildTitle(separator: string = ' | '): string {\n let title = '';\n let childTitles = [];\n let navModelTitle = this.config.navModel.title;\n let instructionRouter = this.router;\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n if (navModelTitle) {\n title = instructionRouter.transformTitle(navModelTitle);\n }\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n\n if (child_nav_instruction) {\n let childTitle = child_nav_instruction._buildTitle(separator);\n if (childTitle) {\n childTitles.push(childTitle);\n }\n }\n }\n\n if (childTitles.length) {\n title = childTitles.join(separator) + (title ? separator : '') + title;\n }\n\n if (instructionRouter.title) {\n title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title);\n }\n\n return title;\n }\n}\n\nconst prune = (instruction: NavigationInstruction): void => {\n instruction.previousInstruction = null;\n instruction.plan = null;\n};\n\ninterface ISwapPlan {\n viewPort: ViewPort;\n viewPortInstruction: ViewPortInstruction;\n}\n","import { Router } from './router';\nimport { RouteConfig } from './interfaces';\n\n/**\n* Class for storing and interacting with a route's navigation settings.\n*/\nexport class NavModel {\n\n /**\n * True if this nav item is currently active.\n */\n isActive: boolean = false;\n\n /**\n * The title.\n */\n title: string = null;\n\n /**\n * This nav item's absolute href.\n */\n href: string = null;\n\n /**\n * This nav item's relative href.\n */\n relativeHref: string = null;\n\n /**\n * Data attached to the route at configuration time.\n */\n settings: any = {};\n\n /**\n * The route config.\n */\n config: RouteConfig = null;\n\n /**\n * The router associated with this navigation model.\n */\n router: Router;\n\n order: number | boolean;\n\n constructor(router: Router, relativeHref: string) {\n this.router = router;\n this.relativeHref = relativeHref;\n }\n\n /**\n * Sets the route's title and updates document.title.\n * If the a navigation is in progress, the change will be applied\n * to document.title when the navigation completes.\n *\n * @param title The new title.\n */\n setTitle(title: string): void {\n this.title = title;\n\n if (this.isActive) {\n this.router.updateTitle();\n }\n }\n}\n","import { RouteConfig } from './interfaces';\n\nexport function _normalizeAbsolutePath(path: string, hasPushState: boolean, absolute: boolean = false) {\n if (!hasPushState && path[0] !== '#') {\n path = '#' + path;\n }\n\n if (hasPushState && absolute) {\n path = path.substring(1, path.length);\n }\n\n return path;\n}\n\nexport function _createRootedPath(fragment: string, baseUrl: string, hasPushState: boolean, absolute?: boolean) {\n if (isAbsoluteUrl.test(fragment)) {\n return fragment;\n }\n\n let path = '';\n\n if (baseUrl.length && baseUrl[0] !== '/') {\n path += '/';\n }\n\n path += baseUrl;\n\n if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') {\n path += '/';\n }\n\n if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') {\n path = path.substring(0, path.length - 1);\n }\n\n return _normalizeAbsolutePath(path + fragment, hasPushState, absolute);\n}\n\nexport function _resolveUrl(fragment: string, baseUrl: string, hasPushState?: boolean) {\n if (isRootedPath.test(fragment)) {\n return _normalizeAbsolutePath(fragment, hasPushState);\n }\n\n return _createRootedPath(fragment, baseUrl, hasPushState);\n}\n\nexport function _ensureArrayWithSingleRoutePerConfig(config: RouteConfig) {\n let routeConfigs = [];\n\n if (Array.isArray(config.route)) {\n for (let i = 0, ii = config.route.length; i < ii; ++i) {\n let current = Object.assign({}, config);\n current.route = config.route[i];\n routeConfigs.push(current);\n }\n } else {\n routeConfigs.push(Object.assign({}, config));\n }\n\n return routeConfigs;\n}\n\nconst isRootedPath = /^#?\\//;\nconst isAbsoluteUrl = /^([a-z][a-z0-9+\\-.]*:)?\\/\\//i;\n","import { RouteConfig, PipelineStep, RouteConfigSpecifier } from './interfaces';\nimport { _ensureArrayWithSingleRoutePerConfig } from './util';\nimport { Router } from './router';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * Class used to configure a [[Router]] instance.\n *\n * @constructor\n */\nexport class RouterConfiguration {\n instructions: Array<(router: Router) => void> = [];\n options: {\n [key: string]: any;\n compareQueryParams?: boolean;\n root?: string;\n pushState?: boolean;\n hashChange?: boolean;\n silent?: boolean;\n } = {};\n pipelineSteps: Array<{ name: string, step: Function | PipelineStep }> = [];\n title: string;\n titleSeparator: string;\n unknownRouteConfig: RouteConfigSpecifier;\n viewPortDefaults: Record;\n\n /**@internal */\n _fallbackRoute: string;\n\n /**\n * Adds a step to be run during the [[Router]]'s navigation pipeline.\n *\n * @param name The name of the pipeline slot to insert the step into.\n * @param step The pipeline step.\n * @chainable\n */\n addPipelineStep(name: string, step: Function | PipelineStep): RouterConfiguration {\n if (step === null || step === undefined) {\n throw new Error('Pipeline step cannot be null or undefined.');\n }\n this.pipelineSteps.push({ name, step });\n return this;\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s authorize pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addAuthorizeStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.Authorize, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preActivate pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreActivateStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreActivate, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreRender, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s postRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPostRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PostRender, step);\n }\n\n /**\n * Configures a route that will be used if there is no previous location available on navigation cancellation.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @chainable\n */\n fallbackRoute(fragment: string): RouterConfiguration {\n this._fallbackRoute = fragment;\n return this;\n }\n\n /**\n * Maps one or more routes to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map.\n * @chainable\n */\n map(route: RouteConfig | RouteConfig[]): RouterConfiguration {\n if (Array.isArray(route)) {\n route.forEach(this.map.bind(this));\n return this;\n }\n\n return this.mapRoute(route);\n }\n\n /**\n * Configures defaults to use for any view ports.\n *\n * @param viewPortConfig a view port configuration object to use as a\n * default, of the form { viewPortName: { moduleId } }.\n * @chainable\n */\n useViewPortDefaults(viewPortConfig: Record): RouterConfiguration {\n this.viewPortDefaults = viewPortConfig;\n return this;\n }\n\n /**\n * Maps a single route to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map.\n * @chainable\n */\n mapRoute(config: RouteConfig): RouterConfiguration {\n this.instructions.push(router => {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n\n let navModel;\n for (let i = 0, ii = routeConfigs.length; i < ii; ++i) {\n let routeConfig = routeConfigs[i];\n routeConfig.settings = routeConfig.settings || {};\n if (!navModel) {\n navModel = router.createNavModel(routeConfig);\n }\n\n router.addRoute(routeConfig, navModel);\n }\n });\n\n return this;\n }\n\n /**\n * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes.\n *\n * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the\n * [[NavigationInstruction]] and selects a moduleId to load.\n * @chainable\n */\n mapUnknownRoutes(config: RouteConfigSpecifier): RouterConfiguration {\n this.unknownRouteConfig = config;\n return this;\n }\n\n /**\n * Applies the current configuration to the specified [[Router]].\n *\n * @param router The [[Router]] to apply the configuration to.\n */\n exportToRouter(router: Router): void {\n let instructions = this.instructions;\n for (let i = 0, ii = instructions.length; i < ii; ++i) {\n instructions[i](router);\n }\n\n if (this.title) {\n router.title = this.title;\n }\n\n if (this.titleSeparator) {\n router.titleSeparator = this.titleSeparator;\n }\n\n if (this.unknownRouteConfig) {\n router.handleUnknownRoutes(this.unknownRouteConfig);\n }\n\n if (this._fallbackRoute) {\n router.fallbackRoute = this._fallbackRoute;\n }\n\n if (this.viewPortDefaults) {\n router.useViewPortDefaults(this.viewPortDefaults);\n }\n\n Object.assign(router.options, this.options);\n\n let pipelineSteps = this.pipelineSteps;\n if (pipelineSteps.length) {\n if (!router.isRoot) {\n throw new Error('Pipeline steps can only be added to the root router');\n }\n\n let pipelineProvider = router.pipelineProvider;\n for (let i = 0, ii = pipelineSteps.length; i < ii; ++i) {\n let { name, step } = pipelineSteps[i];\n pipelineProvider.addStep(name, step);\n }\n }\n }\n}\n","import { RouteRecognizer, RouteHandler, ConfigurableRoute, State, RecognizedRoute } from 'aurelia-route-recognizer';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { NavigationInstruction, NavigationInstructionInit } from './navigation-instruction';\nimport { NavModel } from './nav-model';\nimport { RouterConfiguration } from './router-configuration';\nimport {\n _ensureArrayWithSingleRoutePerConfig,\n _normalizeAbsolutePath,\n _createRootedPath,\n _resolveUrl\n} from './util';\nimport { RouteConfig, NavigationResult, RouteConfigSpecifier, ViewPort, ViewPortInstruction } from './interfaces';\nimport { PipelineProvider } from './pipeline-provider';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface History {\n // This is wrong, as it's an implementation detail from aurelia-history-browser\n // but we are poking it in here so probably will need to make it official in `aurelia-history`\n /**\n * A private flag of Aurelia History implementation to indicate if push state should be used\n */\n _hasPushState: boolean;\n\n previousLocation: string;\n }\n}\n\n/**@internal */\ndeclare module 'aurelia-route-recognizer' {\n interface State {\n types: {\n dynamics: DynamicSegment;\n stars: StarSegment;\n };\n }\n\n interface RouteHandler {\n navigationStrategy?: (instruction: NavigationInstruction) => any;\n }\n\n interface RecognizedRoute {\n config?: RouteConfig;\n queryParams?: Record;\n }\n}\n\ntype RouterConfigurationResolution = RouterConfiguration | ((cfg: RouterConfiguration) => void | RouterConfiguration | Promise);\n\n/**\n * The primary class responsible for handling routing and navigation.\n */\nexport class Router {\n\n /**\n * Container associated with this router. Also used to create child container for creating child router.\n */\n container: Container;\n\n /**\n * History instance of Aurelia abstract class for wrapping platform history global object\n */\n history: History;\n\n /**\n * A registry of registered viewport. Will be used to handle process navigation instruction route loading\n * and dom swapping\n */\n viewPorts: Record;\n\n /**\n * List of route configs registered with this router\n */\n routes: RouteConfig[];\n\n /**\n * The [[Router]]'s current base URL, typically based on the [[Router.currentInstruction]].\n */\n baseUrl: string;\n\n /**\n * If defined, used in generation of document title for [[Router]]'s routes.\n */\n title: string | undefined;\n\n /**\n * The separator used in the document title between [[Router]]'s routes.\n */\n titleSeparator: string | undefined;\n\n /**\n * True if the [[Router]] has been configured.\n */\n isConfigured: boolean;\n\n /**\n * True if the [[Router]] is currently processing a navigation.\n */\n isNavigating: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigate function(s).\n */\n isExplicitNavigation: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigateBack function.\n */\n isExplicitNavigationBack: boolean;\n\n /**\n * True if the [[Router]] is navigating into the app for the first time in the browser session.\n */\n isNavigatingFirst: boolean;\n\n /**\n * True if the [[Router]] is navigating to a page instance not in the browser session history.\n */\n isNavigatingNew: boolean;\n\n /**\n * True if the [[Router]] is navigating forward in the browser session history.\n */\n isNavigatingForward: boolean;\n\n /**\n * True if the [[Router]] is navigating back in the browser session history.\n */\n isNavigatingBack: boolean;\n\n /**\n * True if the [[Router]] is navigating due to a browser refresh.\n */\n isNavigatingRefresh: boolean;\n\n /**\n * True if the previous instruction successfully completed the CanDeactivatePreviousStep in the current navigation.\n */\n couldDeactivate: boolean;\n\n /**\n * The currently active navigation tracker.\n */\n currentNavigationTracker: number;\n\n /**\n * The navigation models for routes that specified [[RouteConfig.nav]].\n */\n navigation: NavModel[];\n\n /**\n * The currently active navigation instruction.\n */\n currentInstruction: NavigationInstruction;\n\n /**\n * The parent router, or null if this instance is not a child router.\n */\n parent: Router = null;\n\n options: any = {};\n\n /**\n * The defaults used when a viewport lacks specified content\n */\n viewPortDefaults: Record = {};\n\n /**@internal */\n catchAllHandler: (instruction: NavigationInstruction) => NavigationInstruction | Promise;\n /**@internal */\n fallbackRoute: string;\n /**@internal */\n pipelineProvider: PipelineProvider;\n /**@internal */\n _fallbackOrder: number;\n /**@internal */\n _recognizer: RouteRecognizer;\n /**@internal */\n _childRecognizer: RouteRecognizer;\n /**@internal */\n _configuredPromise: Promise;\n /**@internal */\n _resolveConfiguredPromise: (value?: any) => void;\n\n /**\n * Extension point to transform the document title before it is built and displayed.\n * By default, child routers delegate to the parent router, and the app router\n * returns the title unchanged.\n */\n transformTitle: (title: string) => string = (title: string) => {\n if (this.parent) {\n return this.parent.transformTitle(title);\n }\n return title;\n }\n\n /**\n * @param container The [[Container]] to use when child routers.\n * @param history The [[History]] implementation to delegate navigation requests to.\n */\n constructor(container: Container, history: History) {\n this.container = container;\n this.history = history;\n this.reset();\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset() {\n this.viewPorts = {};\n this.routes = [];\n this.baseUrl = '';\n this.isConfigured = false;\n this.isNavigating = false;\n this.isExplicitNavigation = false;\n this.isExplicitNavigationBack = false;\n this.isNavigatingFirst = false;\n this.isNavigatingNew = false;\n this.isNavigatingRefresh = false;\n this.isNavigatingForward = false;\n this.isNavigatingBack = false;\n this.couldDeactivate = false;\n this.navigation = [];\n this.currentInstruction = null;\n this.viewPortDefaults = {};\n this._fallbackOrder = 100;\n this._recognizer = new RouteRecognizer();\n this._childRecognizer = new RouteRecognizer();\n this._configuredPromise = new Promise(resolve => {\n this._resolveConfiguredPromise = resolve;\n });\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent.\n */\n get isRoot(): boolean {\n return !this.parent;\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort.\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/any, name?: string): void {\n name = name || 'default';\n this.viewPorts[name] = viewPort;\n }\n\n /**\n * Returns a Promise that resolves when the router is configured.\n */\n ensureConfigured(): Promise {\n return this._configuredPromise;\n }\n\n /**\n * Configures the router.\n *\n * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]].\n */\n configure(callbackOrConfig: RouterConfiguration | ((config: RouterConfiguration) => RouterConfiguration)): Promise {\n this.isConfigured = true;\n\n let result: RouterConfigurationResolution = callbackOrConfig as RouterConfiguration;\n let config: RouterConfiguration;\n if (typeof callbackOrConfig === 'function') {\n config = new RouterConfiguration();\n result = callbackOrConfig(config);\n }\n\n return Promise\n .resolve(result)\n .then((c) => {\n if (c && (c as RouterConfiguration).exportToRouter) {\n config = c;\n }\n\n config.exportToRouter(this);\n this.isConfigured = true;\n this._resolveConfiguredPromise();\n });\n }\n\n /**\n * Navigates to a new location.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n navigate(fragment: string, options?: NavigationOptions): boolean {\n if (!this.isConfigured && this.parent) {\n return this.parent.navigate(fragment, options);\n }\n\n this.isExplicitNavigation = true;\n return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options);\n }\n\n /**\n * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed\n * by [[Router.navigate]].\n *\n * @param route The name of the route to use when generating the navigation location.\n * @param params The route parameters to be used when populating the route pattern.\n * @param options The navigation options.\n */\n navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean {\n let path = this.generate(route, params);\n return this.navigate(path, options);\n }\n\n /**\n * Navigates back to the most recent location in history.\n */\n navigateBack(): void {\n this.isExplicitNavigationBack = true;\n this.history.navigateBack();\n }\n\n /**\n * Creates a child router of the current router.\n *\n * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified.\n * @returns {Router} The new child Router.\n */\n createChild(container?: Container): Router {\n let childRouter = new Router(container || this.container.createChild(), this.history);\n childRouter.parent = this;\n return childRouter;\n }\n\n /**\n * Generates a URL fragment matching the specified route pattern.\n *\n * @param name The name of the route whose pattern should be used to generate the fragment.\n * @param params The route params to be used to populate the route pattern.\n * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url.\n * @returns {string} A string containing the generated URL fragment.\n */\n generate(nameOrRoute: string | RouteConfig, params: any = {}, options: any = {}): string {\n // A child recognizer generates routes for potential child routes. Any potential child route is added\n // to the childRoute property of params for the childRouter to recognize. When generating routes, we\n // use the childRecognizer when childRoute params are available to generate a child router enabled route.\n let recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer;\n let hasRoute = recognizer.hasRoute(nameOrRoute as string | RouteHandler);\n if (!hasRoute) {\n if (this.parent) {\n return this.parent.generate(nameOrRoute, params, options);\n }\n throw new Error(`A route with name '${nameOrRoute}' could not be found. Check that \\`name: '${nameOrRoute}'\\` was specified in the route's config.`);\n }\n let path = recognizer.generate(nameOrRoute as string | RouteHandler, params);\n let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute);\n return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath;\n }\n\n /**\n * Creates a [[NavModel]] for the specified route config.\n *\n * @param config The route config.\n */\n createNavModel(config: RouteConfig): NavModel {\n let navModel = new NavModel(\n this,\n 'href' in config\n ? config.href\n // potential error when config.route is a string[] ?\n : config.route as string);\n navModel.title = config.title;\n navModel.order = config.nav;\n navModel.href = config.href;\n navModel.settings = config.settings;\n navModel.config = config;\n\n return navModel;\n }\n\n /**\n * Registers a new route with the router.\n *\n * @param config The [[RouteConfig]].\n * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes.\n */\n addRoute(config: RouteConfig, navModel?: NavModel): void {\n if (Array.isArray(config.route)) {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n // the following is wrong. todo: fix this after TS refactoring release\n routeConfigs.forEach(this.addRoute.bind(this));\n return;\n }\n\n validateRouteConfig(config);\n\n if (!('viewPorts' in config) && !config.navigationStrategy) {\n config.viewPorts = {\n 'default': {\n moduleId: config.moduleId,\n view: config.view\n }\n };\n }\n\n if (!navModel) {\n navModel = this.createNavModel(config);\n }\n\n this.routes.push(config);\n\n let path = config.route;\n if (path.charAt(0) === '/') {\n path = path.substr(1);\n }\n let caseSensitive = config.caseSensitive === true;\n let state: State = this._recognizer.add({\n path: path,\n handler: config as RouteHandler,\n caseSensitive: caseSensitive\n } as ConfigurableRoute);\n\n if (path) {\n let settings = config.settings;\n delete config.settings;\n let withChild = JSON.parse(JSON.stringify(config));\n config.settings = settings;\n withChild.route = `${path}/*childRoute`;\n withChild.hasChildRouter = true;\n this._childRecognizer.add({\n path: withChild.route,\n handler: withChild,\n caseSensitive: caseSensitive\n });\n\n withChild.navModel = navModel;\n withChild.settings = config.settings;\n withChild.navigationStrategy = config.navigationStrategy;\n }\n\n config.navModel = navModel;\n\n let navigation = this.navigation;\n\n if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) {\n if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) {\n throw new Error('Invalid route config for \"' + config.route + '\" : dynamic routes must specify an \"href:\" to be included in the navigation model.');\n }\n\n if (typeof navModel.order !== 'number') {\n navModel.order = ++this._fallbackOrder;\n }\n\n navigation.push(navModel);\n // this is a potential error / inconsistency between browsers\n //\n // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\n // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other,\n // but sorted with respect to all different elements.\n // Note: the ECMAscript standard does not guarantee this behaviour,\n // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.\n navigation.sort((a, b) => a.order - b.order);\n }\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasRoute(name: string): boolean {\n return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name));\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasOwnRoute(name: string): boolean {\n return this._recognizer.hasRoute(name);\n }\n\n /**\n * Register a handler to use when the incoming URL fragment doesn't match any registered routes.\n *\n * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]].\n */\n handleUnknownRoutes(config?: RouteConfigSpecifier): void {\n if (!config) {\n throw new Error('Invalid unknown route handler');\n }\n\n this.catchAllHandler = instruction => {\n return this\n ._createRouteConfig(config, instruction)\n .then(c => {\n instruction.config = c;\n return instruction;\n });\n };\n }\n\n /**\n * Updates the document title using the current navigation instruction.\n */\n updateTitle(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n return parentRouter.updateTitle();\n }\n\n let currentInstruction = this.currentInstruction;\n if (currentInstruction) {\n currentInstruction._updateTitle();\n }\n return undefined;\n }\n\n /**\n * Updates the navigation routes with hrefs relative to the current location.\n * Note: This method will likely move to a plugin in a future release.\n */\n refreshNavigation(): void {\n let nav = this.navigation;\n\n for (let i = 0, length = nav.length; i < length; i++) {\n let current = nav[i];\n if (!current.config.href) {\n current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState);\n } else {\n current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState);\n }\n }\n }\n\n /**\n * Sets the default configuration for the view ports. This specifies how to\n * populate a view port for which no module is specified. The default is\n * an empty view/view-model pair.\n */\n useViewPortDefaults($viewPortDefaults: Record): void {\n // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction\n let viewPortDefaults: Record = $viewPortDefaults;\n for (let viewPortName in viewPortDefaults) {\n let viewPortConfig = viewPortDefaults[viewPortName];\n this.viewPortDefaults[viewPortName] = {\n moduleId: viewPortConfig.moduleId\n };\n }\n }\n\n /**@internal */\n _refreshBaseUrl(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction);\n }\n }\n\n /**@internal */\n _createNavigationInstruction(url: string = '', parentInstruction: NavigationInstruction = null): Promise {\n let fragment = url;\n let queryString = '';\n\n let queryIndex = url.indexOf('?');\n if (queryIndex !== -1) {\n fragment = url.substr(0, queryIndex);\n queryString = url.substr(queryIndex + 1);\n }\n\n let urlRecognizationResults = this._recognizer.recognize(url) as IRouteRecognizationResults;\n if (!urlRecognizationResults || !urlRecognizationResults.length) {\n urlRecognizationResults = this._childRecognizer.recognize(url) as IRouteRecognizationResults;\n }\n\n let instructionInit: NavigationInstructionInit = {\n fragment,\n queryString,\n config: null,\n parentInstruction,\n previousInstruction: this.currentInstruction,\n router: this,\n options: {\n compareQueryParams: this.options.compareQueryParams\n }\n };\n\n let result: Promise;\n\n if (urlRecognizationResults && urlRecognizationResults.length) {\n let first = urlRecognizationResults[0];\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: first.params,\n queryParams: first.queryParams || urlRecognizationResults.queryParams,\n config: first.config || first.handler\n }));\n\n if (typeof first.handler === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler, first);\n } else if (first.handler && typeof first.handler.navigationStrategy === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler);\n } else {\n result = Promise.resolve(instruction);\n }\n } else if (this.catchAllHandler) {\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n config: null // config will be created by the catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, this.catchAllHandler);\n } else if (this.parent) {\n let router = this._parentCatchAllHandler(this.parent);\n\n if (router) {\n let newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction);\n\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n router: router,\n parentInstruction: newParentInstruction,\n parentCatchHandler: true,\n config: null // config will be created by the chained parent catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, router.catchAllHandler);\n }\n }\n\n if (result && parentInstruction) {\n this.baseUrl = generateBaseUrl(this.parent, parentInstruction);\n }\n\n return result || Promise.reject(new Error(`Route not found: ${url}`));\n }\n\n /**@internal */\n _findParentInstructionFromRouter(router: Router, instruction: NavigationInstruction): NavigationInstruction {\n if (instruction.router === router) {\n instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId\n return instruction;\n } else if (instruction.parentInstruction) {\n return this._findParentInstructionFromRouter(router, instruction.parentInstruction);\n }\n return undefined;\n }\n\n /**@internal */\n _parentCatchAllHandler(router: Router): Router | false {\n if (router.catchAllHandler) {\n return router;\n } else if (router.parent) {\n return this._parentCatchAllHandler(router.parent);\n }\n return false;\n }\n\n /**\n * @internal\n */\n _createRouteConfig(config: RouteConfigSpecifier, instruction: NavigationInstruction): Promise {\n return Promise\n .resolve(config)\n .then((c: any) => {\n if (typeof c === 'string') {\n return { moduleId: c } as RouteConfig;\n } else if (typeof c === 'function') {\n return c(instruction);\n }\n\n return c;\n })\n // typing here could be either RouteConfig or RedirectConfig\n // but temporarily treat both as RouteConfig\n // todo: improve typings precision\n .then((c: string | RouteConfig) => typeof c === 'string' ? { moduleId: c } as RouteConfig : c)\n .then((c: RouteConfig) => {\n c.route = instruction.params.path;\n validateRouteConfig(c);\n\n if (!c.navModel) {\n c.navModel = this.createNavModel(c);\n }\n\n return c;\n });\n }\n}\n\n/* @internal exported for unit testing */\nexport const generateBaseUrl = (router: Router, instruction: NavigationInstruction): string => {\n return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`;\n};\n\n/* @internal exported for unit testing */\nexport const validateRouteConfig = (config: RouteConfig): void => {\n if (typeof config !== 'object') {\n throw new Error('Invalid Route Config');\n }\n\n if (typeof config.route !== 'string') {\n let name = config.name || '(no name)';\n throw new Error('Invalid Route Config for \"' + name + '\": You must specify a \"route:\" pattern.');\n }\n\n if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) {\n throw new Error('Invalid Route Config for \"' + config.route + '\": You must specify a \"moduleId:\", \"redirect:\", \"navigationStrategy:\", or \"viewPorts:\".');\n }\n};\n\n/* @internal exported for unit testing */\nexport const evaluateNavigationStrategy = (\n instruction: NavigationInstruction,\n evaluator: Function,\n context?: any\n): Promise => {\n return Promise.resolve(evaluator.call(context, instruction)).then(() => {\n if (!('viewPorts' in instruction.config)) {\n instruction.config.viewPorts = {\n 'default': {\n moduleId: instruction.config.moduleId\n }\n };\n }\n\n return instruction;\n });\n};\n\ninterface IRouteRecognizationResults extends Array {\n queryParams: Record;\n}\n","import { PipelineStatus } from './pipeline-status';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Next, StepRunnerFunction, NextCompletionHandler } from './interfaces';\n\n/**@internal exported for unit testing */\nexport const createNextFn = (instruction: NavigationInstruction, steps: StepRunnerFunction[]): Next => {\n let index = -1;\n const next: Next = function() {\n index++;\n\n if (index < steps.length) {\n let currentStep = steps[index];\n\n try {\n return currentStep(instruction, next);\n } catch (e) {\n return next.reject(e);\n }\n } else {\n return next.complete();\n }\n } as Next;\n\n next.complete = createCompletionHandler(next, PipelineStatus.Completed);\n next.cancel = createCompletionHandler(next, PipelineStatus.Canceled);\n next.reject = createCompletionHandler(next, PipelineStatus.Rejected);\n\n return next;\n};\n\n/**@internal exported for unit testing */\nexport const createCompletionHandler = (next: Next, status: PipelineStatus): NextCompletionHandler => {\n return (output: any) => Promise\n .resolve({\n status,\n output,\n completed: status === PipelineStatus.Completed\n });\n};\n","import { PipelineStep, PipelineResult, Next, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { createNextFn } from './next';\n\n/**\n* The class responsible for managing and processing the navigation pipeline.\n*/\nexport class Pipeline {\n /**\n * The pipeline steps. And steps added via addStep will be converted to a function\n * The actualy running functions with correct step contexts of this pipeline\n */\n steps: StepRunnerFunction[] = [];\n\n /**\n * Adds a step to the pipeline.\n *\n * @param step The pipeline step.\n */\n addStep(step: StepRunnerFunction | PipelineStep | IPipelineSlot): Pipeline {\n let run;\n\n if (typeof step === 'function') {\n run = step;\n } else if (typeof step.getSteps === 'function') {\n // getSteps is to enable support open slots\n // where devs can add multiple steps into the same slot name\n let steps = step.getSteps();\n for (let i = 0, l = steps.length; i < l; i++) {\n this.addStep(steps[i]);\n }\n\n return this;\n } else {\n run = (step as PipelineStep).run.bind(step);\n }\n\n this.steps.push(run);\n\n return this;\n }\n\n /**\n * Runs the pipeline.\n *\n * @param instruction The navigation instruction to process.\n */\n run(instruction: NavigationInstruction): Promise {\n const nextFn = createNextFn(instruction, this.steps);\n return nextFn();\n }\n}\n","import { Next, RouteConfig, ViewPortComponent, ViewPortPlan, ViewPortInstruction } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy, _buildNavigationPlan } from './navigation-plan';\nimport { Router } from './router';\n\n/**\n * Loading plan calculated based on a navigration-instruction and a viewport plan\n */\ninterface ILoadingPlan {\n viewPortPlan: ViewPortPlan;\n navigationInstruction: NavigationInstruction;\n}\n\n/**\n * Abstract class that is responsible for loading view / view model from a route config\n * The default implementation can be found in `aurelia-templating-router`\n */\nexport class RouteLoader {\n /**\n * Load a route config based on its viewmodel / view configuration\n */\n // return typing: return typings used to be never\n // as it was a throw. Changing it to Promise should not cause any issues\n loadRoute(router: Router, config: RouteConfig, navigationInstruction: NavigationInstruction): Promise {\n throw new Error('Route loaders must implement \"loadRoute(router, config, navigationInstruction)\".');\n }\n}\n\n/**\n * A pipeline step responsible for loading a route config of a navigation instruction\n */\nexport class LoadRouteStep {\n /**@internal */\n static inject() { return [RouteLoader]; }\n /**\n * Route loader isntance that will handle loading route config\n * @internal\n */\n routeLoader: RouteLoader;\n\n constructor(routeLoader: RouteLoader) {\n this.routeLoader = routeLoader;\n }\n\n /**\n * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline\n */\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return loadNewRoute(this.routeLoader, navigationInstruction)\n .then(next, next.cancel);\n }\n}\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadNewRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction\n): Promise => {\n let toLoad = determineWhatToLoad(navigationInstruction);\n let loadPromises = toLoad.map((loadingPlan: ILoadingPlan) => loadRoute(\n routeLoader,\n loadingPlan.navigationInstruction,\n loadingPlan.viewPortPlan\n ));\n\n return Promise.all(loadPromises);\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const determineWhatToLoad = (\n navigationInstruction: NavigationInstruction,\n toLoad: ILoadingPlan[] = []\n): ILoadingPlan[] => {\n let plan: Record = navigationInstruction.plan;\n\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let child_nav_instruction = viewPortPlan.childNavigationInstruction;\n\n if (viewPortPlan.strategy === activationStrategy.replace) {\n toLoad.push({ viewPortPlan, navigationInstruction } as ILoadingPlan);\n\n if (child_nav_instruction) {\n determineWhatToLoad(child_nav_instruction, toLoad);\n }\n } else {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction(\n viewPortName,\n viewPortPlan.strategy,\n viewPortPlan.prevModuleId,\n viewPortPlan.prevComponent\n ) as ViewPortInstruction;\n\n if (child_nav_instruction) {\n viewPortInstruction.childNavigationInstruction = child_nav_instruction;\n determineWhatToLoad(child_nav_instruction, toLoad);\n }\n }\n }\n\n return toLoad;\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n viewPortPlan: ViewPortPlan\n): Promise => {\n let moduleId = viewPortPlan.config ? viewPortPlan.config.moduleId : null;\n\n return loadComponent(routeLoader, navigationInstruction, viewPortPlan.config)\n .then((component) => {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction(\n viewPortPlan.name,\n viewPortPlan.strategy,\n moduleId,\n component\n ) as ViewPortInstruction;\n\n let childRouter = component.childRouter;\n if (childRouter) {\n let path = navigationInstruction.getWildcardPath();\n\n return childRouter\n ._createNavigationInstruction(path, navigationInstruction)\n .then((childInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(childInstruction)\n .then((childPlan) => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n viewPortInstruction.childNavigationInstruction = childInstruction;\n\n return loadNewRoute(routeLoader, childInstruction);\n });\n });\n }\n // ts complains without this, though they are same\n return void 0;\n });\n};\n\n/**\n * Load a routed-component based on navigation instruction and route config\n * @internal exported for unit testing only\n */\nexport const loadComponent = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n config: RouteConfig\n): Promise => {\n let router = navigationInstruction.router;\n let lifecycleArgs = navigationInstruction.lifecycleArgs;\n\n return Promise.resolve()\n .then(() => routeLoader.loadRoute(router, config, navigationInstruction))\n .then(\n /**\n * @param component an object carrying information about loaded route\n * typically contains information about view model, childContainer, view and router\n */\n (component: ViewPortComponent) => {\n let { viewModel, childContainer } = component;\n component.router = router;\n component.config = config;\n\n if ('configureRouter' in viewModel) {\n let childRouter = childContainer.getChildRouter();\n component.childRouter = childRouter;\n\n return childRouter\n .configure(c => viewModel.configureRouter(c, childRouter, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]))\n .then(() => component);\n }\n\n return component;\n });\n};\n","import { Container } from 'aurelia-dependency-injection';\nimport { Pipeline } from './pipeline';\nimport { BuildNavigationPlanStep } from './navigation-plan';\nimport { LoadRouteStep } from './route-loading';\nimport { CommitChangesStep } from './navigation-instruction';\nimport {\n CanDeactivatePreviousStep,\n CanActivateNextStep,\n DeactivatePreviousStep,\n ActivateNextStep\n} from './activation';\nimport { PipelineStep, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution\n */\nclass PipelineSlot implements IPipelineSlot {\n\n /**@internal */\n container: Container;\n /**@internal */\n slotName: string;\n /**@internal */\n slotAlias?: string;\n\n steps: (Function | PipelineStep)[] = [];\n\n constructor(container: Container, name: string, alias?: string) {\n this.container = container;\n this.slotName = name;\n this.slotAlias = alias;\n }\n\n getSteps(): (StepRunnerFunction | IPipelineSlot | PipelineStep)[] {\n return this.steps.map(x => this.container.get(x));\n }\n}\n\n/**\n* Class responsible for creating the navigation pipeline.\n*/\nexport class PipelineProvider {\n\n /**@internal */\n static inject() { return [Container]; }\n /**@internal */\n container: Container;\n /**@internal */\n steps: (Function | PipelineSlot)[];\n\n constructor(container: Container) {\n this.container = container;\n this.steps = [\n BuildNavigationPlanStep,\n CanDeactivatePreviousStep, // optional\n LoadRouteStep,\n this._createPipelineSlot(PipelineSlotName.Authorize),\n CanActivateNextStep, // optional\n this._createPipelineSlot(PipelineSlotName.PreActivate, 'modelbind'),\n // NOTE: app state changes start below - point of no return\n DeactivatePreviousStep, // optional\n ActivateNextStep, // optional\n this._createPipelineSlot(PipelineSlotName.PreRender, 'precommit'),\n CommitChangesStep,\n this._createPipelineSlot(PipelineSlotName.PostRender, 'postcomplete')\n ];\n }\n\n /**\n * Create the navigation pipeline.\n */\n createPipeline(useCanDeactivateStep: boolean = true): Pipeline {\n let pipeline = new Pipeline();\n this.steps.forEach(step => {\n if (useCanDeactivateStep || step !== CanDeactivatePreviousStep) {\n pipeline.addStep(this.container.get(step));\n }\n });\n return pipeline;\n }\n\n /**@internal */\n _findStep(name: string): PipelineSlot {\n // Steps that are not PipelineSlots are constructor functions, and they will automatically fail. Probably.\n return this.steps.find(x => (x as PipelineSlot).slotName === name || (x as PipelineSlot).slotAlias === name) as PipelineSlot;\n }\n\n /**\n * Adds a step into the pipeline at a known slot location.\n */\n addStep(name: string, step: PipelineStep | Function): void {\n let found = this._findStep(name);\n if (found) {\n // prevent duplicates\n if (!found.steps.includes(step)) {\n found.steps.push(step);\n }\n } else {\n throw new Error(`Invalid pipeline slot name: ${name}.`);\n }\n }\n\n /**\n * Removes a step from a slot in the pipeline\n */\n removeStep(name: string, step: PipelineStep): void {\n let slot = this._findStep(name);\n if (slot) {\n let steps = slot.steps;\n steps.splice(steps.indexOf(step), 1);\n }\n }\n\n /**\n * @internal\n * Clears all steps from a slot in the pipeline\n */\n _clearSteps(name: string = ''): void {\n let slot = this._findStep(name);\n if (slot) {\n slot.steps = [];\n }\n }\n\n /**\n * Resets all pipeline slots\n */\n reset(): void {\n this._clearSteps('authorize');\n this._clearSteps('preActivate');\n this._clearSteps('preRender');\n this._clearSteps('postRender');\n }\n\n /**@internal */\n _createPipelineSlot(name: string, alias?: string): PipelineSlot {\n return new PipelineSlot(this.container, name, alias);\n }\n}\n","import * as LogManager from 'aurelia-logging';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\nimport { PipelineProvider } from './pipeline-provider';\nimport { isNavigationCommand } from './navigation-commands';\nimport { EventAggregator } from 'aurelia-event-aggregator';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { ViewPort, ConfiguresRouter, PipelineResult } from './interfaces';\nimport { RouterEvent } from './router-event';\n\n/**@internal */\ndeclare module 'aurelia-dependency-injection' {\n interface Container {\n viewModel?: any;\n }\n}\n\nconst logger = LogManager.getLogger('app-router');\n\n/**\n* The main application router.\n*/\nexport class AppRouter extends Router {\n\n /**@internal */\n static inject() { return [Container, History, PipelineProvider, EventAggregator]; }\n\n events: EventAggregator;\n /**@internal */\n maxInstructionCount: number;\n /**@internal */\n _queue: NavigationInstruction[];\n /**@internal */\n isActive: boolean;\n\n constructor(container: Container, history: History, pipelineProvider: PipelineProvider, events: EventAggregator) {\n super(container, history); // Note the super will call reset internally.\n this.pipelineProvider = pipelineProvider;\n this.events = events;\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset(): void {\n super.reset();\n this.maxInstructionCount = 10;\n if (!this._queue) {\n this._queue = [];\n } else {\n this._queue.length = 0;\n }\n }\n\n /**\n * Loads the specified URL.\n *\n * @param url The URL fragment to load.\n */\n loadUrl(url: string): Promise {\n return this\n ._createNavigationInstruction(url)\n .then(instruction => this._queueInstruction(instruction))\n .catch(error => {\n logger.error(error);\n restorePreviousLocation(this);\n });\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort. This is typically a element in Aurelia default impl\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/ any, name?: string): Promise {\n // having strong typing without changing public API\n const $viewPort: ViewPort = viewPort;\n super.registerViewPort($viewPort, name);\n\n // beside adding viewport to the registry of this instance\n // AppRouter also configure routing/history to start routing functionality\n // There are situation where there are more than 1 element at root view\n // in that case, still only activate once via the following guard\n if (!this.isActive) {\n const viewModel = this._findViewModel($viewPort);\n if ('configureRouter' in viewModel) {\n // If there are more than one element at root view\n // use this flag to guard against configure method being invoked multiple times\n // this flag is set inside method configure\n if (!this.isConfigured) {\n // replace the real resolve with a noop to guarantee that any action in base class Router\n // won't resolve the configurePromise prematurely\n const resolveConfiguredPromise = this._resolveConfiguredPromise;\n this._resolveConfiguredPromise = () => {/**/};\n return this\n .configure(config => {\n viewModel.configureRouter(config, this);\n return config;\n })\n .then(() => {\n this.activate();\n resolveConfiguredPromise();\n });\n }\n } else {\n this.activate();\n }\n }\n // when a viewport is added dynamically to a root view that is already activated\n // just process the navigation instruction\n else {\n this._dequeueInstruction();\n }\n\n return Promise.resolve();\n }\n\n /**\n * Activates the router. This instructs the router to begin listening for history changes and processing instructions.\n *\n * @params options The set of options to activate the router with.\n */\n activate(options?: NavigationOptions): void {\n if (this.isActive) {\n return;\n }\n\n this.isActive = true;\n // route handler property is responsible for handling url change\n // the interface of aurelia-history isn't clear on this perspective\n this.options = Object.assign({ routeHandler: this.loadUrl.bind(this) }, this.options, options);\n this.history.activate(this.options);\n this._dequeueInstruction();\n }\n\n /**\n * Deactivates the router.\n */\n deactivate(): void {\n this.isActive = false;\n this.history.deactivate();\n }\n\n /**@internal */\n _queueInstruction(instruction: NavigationInstruction): Promise {\n return new Promise((resolve) => {\n instruction.resolve = resolve;\n this._queue.unshift(instruction);\n this._dequeueInstruction();\n });\n }\n\n /**@internal */\n _dequeueInstruction(instructionCount: number = 0): Promise {\n return Promise.resolve().then(() => {\n if (this.isNavigating && !instructionCount) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n let instruction = this._queue.shift();\n this._queue.length = 0;\n\n if (!instruction) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n this.isNavigating = true;\n\n let navtracker: number = this.history.getState('NavigationTracker');\n if (!navtracker && !this.currentNavigationTracker) {\n this.isNavigatingFirst = true;\n this.isNavigatingNew = true;\n } else if (!navtracker) {\n this.isNavigatingNew = true;\n } else if (!this.currentNavigationTracker) {\n this.isNavigatingRefresh = true;\n } else if (this.currentNavigationTracker < navtracker) {\n this.isNavigatingForward = true;\n } else if (this.currentNavigationTracker > navtracker) {\n this.isNavigatingBack = true;\n } if (!navtracker) {\n navtracker = Date.now();\n this.history.setState('NavigationTracker', navtracker);\n }\n this.currentNavigationTracker = navtracker;\n\n instruction.previousInstruction = this.currentInstruction;\n\n if (!instructionCount) {\n this.events.publish(RouterEvent.Processing, { instruction });\n } else if (instructionCount === this.maxInstructionCount - 1) {\n logger.error(`${instructionCount + 1} navigation instructions have been attempted without success. Restoring last known good location.`);\n restorePreviousLocation(this);\n return this._dequeueInstruction(instructionCount + 1);\n } else if (instructionCount > this.maxInstructionCount) {\n throw new Error('Maximum navigation attempts exceeded. Giving up.');\n }\n\n let pipeline = this.pipelineProvider.createPipeline(!this.couldDeactivate);\n\n return pipeline\n .run(instruction)\n .then(result => processResult(instruction, result, instructionCount, this))\n .catch(error => {\n return { output: error instanceof Error ? error : new Error(error) } as PipelineResult;\n })\n .then(result => resolveInstruction(instruction, result, !!instructionCount, this));\n });\n }\n\n /**@internal */\n _findViewModel(viewPort: ViewPort): ConfiguresRouter | undefined {\n if (this.container.viewModel) {\n return this.container.viewModel;\n }\n\n if (viewPort.container) {\n let container = viewPort.container;\n\n while (container) {\n if (container.viewModel) {\n this.container.viewModel = container.viewModel;\n return container.viewModel;\n }\n\n container = container.parent;\n }\n }\n\n return undefined;\n }\n}\n\nconst processResult = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n instructionCount: number,\n router: AppRouter\n): Promise => {\n if (!(result && 'completed' in result && 'output' in result)) {\n result = result || {} as PipelineResult;\n result.output = new Error(`Expected router pipeline to return a navigation result, but got [${JSON.stringify(result)}] instead.`);\n }\n\n let finalResult: PipelineResult = null;\n let navigationCommandResult = null;\n if (isNavigationCommand(result.output)) {\n navigationCommandResult = result.output.navigate(router);\n } else {\n finalResult = result;\n\n if (!result.completed) {\n if (result.output instanceof Error) {\n logger.error(result.output.toString());\n }\n\n restorePreviousLocation(router);\n }\n }\n\n return Promise.resolve(navigationCommandResult)\n .then(_ => router._dequeueInstruction(instructionCount + 1))\n .then(innerResult => finalResult || innerResult || result);\n};\n\nconst resolveInstruction = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n isInnerInstruction: boolean,\n router: AppRouter\n): PipelineResult => {\n instruction.resolve(result);\n\n let eventArgs = { instruction, result };\n if (!isInnerInstruction) {\n router.isNavigating = false;\n router.isExplicitNavigation = false;\n router.isExplicitNavigationBack = false;\n router.isNavigatingFirst = false;\n router.isNavigatingNew = false;\n router.isNavigatingRefresh = false;\n router.isNavigatingForward = false;\n router.isNavigatingBack = false;\n router.couldDeactivate = false;\n\n let eventName: string;\n\n if (result.output instanceof Error) {\n eventName = RouterEvent.Error;\n } else if (!result.completed) {\n eventName = RouterEvent.Canceled;\n } else {\n let queryString = instruction.queryString ? ('?' + instruction.queryString) : '';\n router.history.previousLocation = instruction.fragment + queryString;\n eventName = RouterEvent.Success;\n }\n\n router.events.publish(eventName, eventArgs);\n router.events.publish(RouterEvent.Complete, eventArgs);\n } else {\n router.events.publish(RouterEvent.ChildComplete, eventArgs);\n }\n\n return result;\n};\n\nconst restorePreviousLocation = (router: AppRouter): void => {\n let previousLocation = router.history.previousLocation;\n if (previousLocation) {\n router.navigate(router.history.previousLocation, { trigger: false, replace: true });\n } else if (router.fallbackRoute) {\n router.navigate(router.fallbackRoute, { trigger: true, replace: true });\n } else {\n logger.error('Router navigation failed, and no previous location or fallbackRoute could be restored.');\n }\n};\n","/**\n* The status of a Pipeline.\n*/\nexport const enum PipelineStatus {\n Completed = 'completed',\n Canceled = 'canceled',\n Rejected = 'rejected',\n Running = 'running'\n}\n","/**\n * A list of known router events used by the Aurelia router\n * to signal the pipeline has come to a certain state\n */\n// const enum is preserved in tsconfig\nexport const enum RouterEvent {\n Processing = 'router:navigation:processing',\n Error = 'router:navigation:error',\n Canceled = 'router:navigation:canceled',\n Complete = 'router:navigation:complete',\n Success = 'router:navigation:success',\n ChildComplete = 'router:navigation:child:complete'\n}\n","/**\n * Available pipeline slot names to insert interceptor into router pipeline\n */\n// const enum is preserved in tsconfig\nexport const enum PipelineSlotName {\n /**\n * Authorization slot. Invoked early in the pipeline,\n * before `canActivate` hook of incoming route\n */\n Authorize = 'authorize',\n /**\n * Pre-activation slot. Invoked early in the pipeline,\n * Invoked timing:\n * - after Authorization slot\n * - after canActivate hook on new view model\n * - before deactivate hook on old view model\n * - before activate hook on new view model\n */\n PreActivate = 'preActivate',\n /**\n * Pre-render slot. Invoked later in the pipeline\n * Invokcation timing:\n * - after activate hook on new view model\n * - before commit step on new navigation instruction\n */\n PreRender = 'preRender',\n /**\n * Post-render slot. Invoked last in the pipeline\n */\n PostRender = 'postRender'\n}\n"],"names":["LogManager.getLogger","tslib_1.__extends"],"mappings":";;;;;;AAuBA;;;;;;AAMA,SAAgB,mBAAmB,CAAC,GAAQ;IAC1C,OAAO,GAAG,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,UAAU,CAAC;CAClD;;;;AAKD;;;;;IAcE,kBAAY,GAAW,EAAE,OAA+B;QAA/B,wBAAA,EAAA,YAA+B;QACtD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;QACxE,IAAI,CAAC,wBAAwB,GAAG,KAAK,CAAC;KACvC;;;;;;IAOD,4BAAS,GAAT,UAAU,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;KACtB;;;;;;IAOD,2BAAQ,GAAR,UAAS,SAAiB;QACxB,IAAI,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,SAAS,IAAI,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC;QAC1F,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;KACnD;IACH,eAAC;CAAA,IAAA;AAED;;;AAGA;;;;;;IAkBE,yBAAY,KAAa,EAAE,MAAgB,EAAE,OAA+B;QAAjD,uBAAA,EAAA,WAAgB;QAAE,wBAAA,EAAA,YAA+B;QAC1E,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,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C9B,yCAAuB,CAAA;IACvB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,qCAAmB,CAAA;CACpB,EALiB,cAAc,KAAd,cAAc,QAK/B;;ACRD;;;;;AAKA,IAAkB,WAOjB;AAPD,WAAkB,WAAW;IAC3B,0DAA2C,CAAA;IAC3C,gDAAiC,CAAA;IACjC,sDAAuC,CAAA;IACvC,sDAAuC,CAAA;IACvC,oDAAqC,CAAA;IACrC,iEAAkD,CAAA;CACnD,EAPiB,WAAW,KAAX,WAAW,QAO5B;;ACZD;;;;AAIA,IAAkB,gBA0BjB;AA1BD,WAAkB,gBAAgB;;;;;IAKhC,2CAAuB,CAAA;;;;;;;;;IASvB,+CAA2B,CAAA;;;;;;;IAO3B,2CAAuB,CAAA;;;;IAIvB,6CAAyB,CAAA;CAC1B,EA1BiB,gBAAgB,KAAhB,gBAAgB,QA0BjC;;;;"} \ No newline at end of file +{"version":3,"file":"aurelia-router.js","sources":["../../src/navigation-instruction.ts","../../src/nav-model.ts","../../src/util.ts","../../src/router-configuration.ts","../../src/router.ts","../../src/next.ts","../../src/pipeline.ts","../../src/navigation-commands.ts","../../src/navigation-plan.ts","../../src/step-build-navigation-plan.ts","../../src/utilities-route-loading.ts","../../src/route-loader.ts","../../src/step-load-route.ts","../../src/step-commit-changes.ts","../../src/activation-strategy.ts","../../src/utilities-activation.ts","../../src/step-activation.ts","../../src/pipeline-provider.ts","../../src/app-router.ts","../../src/pipeline-status.ts","../../src/router-event.ts","../../src/pipeline-slot-name.ts"],"sourcesContent":["import { ViewPortInstruction, RouteConfig, ViewPort, LifecycleArguments, ViewPortComponent } from './interfaces';\nimport { Router } from './router';\nimport { ActivationStrategyType, InternalActivationStrategy } from './activation-strategy';\n\n/**\n * Initialization options for a navigation instruction\n */\nexport interface NavigationInstructionInit {\n fragment: string;\n queryString?: string;\n params?: Record;\n queryParams?: Record;\n config: RouteConfig;\n parentInstruction?: NavigationInstruction;\n previousInstruction?: NavigationInstruction;\n router: Router;\n options?: Object;\n plan?: Record;\n}\n\nexport interface ViewPortInstructionInit {\n name: string;\n strategy: ActivationStrategyType;\n moduleId: string;\n component: ViewPortComponent;\n}\n\n/**\n * Class used to represent an instruction during a navigation.\n */\nexport class NavigationInstruction {\n /**\n * The URL fragment.\n */\n fragment: string;\n\n /**\n * The query string.\n */\n queryString: string;\n\n /**\n * Parameters extracted from the route pattern.\n */\n params: any;\n\n /**\n * Parameters extracted from the query string.\n */\n queryParams: any;\n\n /**\n * The route config for the route matching this instruction.\n */\n config: RouteConfig;\n\n /**\n * The parent instruction, if this instruction was created by a child router.\n */\n parentInstruction: NavigationInstruction;\n\n parentCatchHandler: any;\n\n /**\n * The instruction being replaced by this instruction in the current router.\n */\n previousInstruction: NavigationInstruction;\n\n /**\n * viewPort instructions to used activation.\n */\n viewPortInstructions: Record;\n\n /**\n * The router instance.\n */\n router: Router;\n\n /**\n * Current built viewport plan of this nav instruction\n */\n plan: Record = null;\n\n options: Record = {};\n\n /**@internal */\n lifecycleArgs: LifecycleArguments;\n /**@internal */\n resolve?: (val?: any) => void;\n\n constructor(init: NavigationInstructionInit) {\n Object.assign(this, init);\n\n this.params = this.params || {};\n this.viewPortInstructions = {};\n\n let ancestorParams = [];\n let current: NavigationInstruction = this;\n do {\n let currentParams = Object.assign({}, current.params);\n if (current.config && current.config.hasChildRouter) {\n // remove the param for the injected child route segment\n delete currentParams[current.getWildCardName()];\n }\n\n ancestorParams.unshift(currentParams);\n current = current.parentInstruction;\n } while (current);\n\n let allParams = Object.assign({}, this.queryParams, ...ancestorParams);\n this.lifecycleArgs = [allParams, this.config, this];\n }\n\n /**\n * Gets an array containing this instruction and all child instructions for the current navigation.\n */\n getAllInstructions(): Array {\n let instructions: NavigationInstruction[] = [this];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let key in viewPortInstructions) {\n let childInstruction = viewPortInstructions[key].childNavigationInstruction;\n if (childInstruction) {\n instructions.push(...childInstruction.getAllInstructions());\n }\n }\n\n return instructions;\n }\n\n /**\n * Gets an array containing the instruction and all child instructions for the previous navigation.\n * Previous instructions are no longer available after navigation completes.\n */\n getAllPreviousInstructions(): Array {\n return this.getAllInstructions().map(c => c.previousInstruction).filter(c => c);\n }\n\n /**\n * Adds a viewPort instruction. Returns the newly created instruction based on parameters\n */\n addViewPortInstruction(initOptions: ViewPortInstructionInit): /*ViewPortInstruction*/ any;\n addViewPortInstruction(viewPortName: string, strategy: ActivationStrategyType, moduleId: string, component: any): /*ViewPortInstruction*/ any;\n addViewPortInstruction(\n nameOrInitOptions: string | ViewPortInstructionInit,\n strategy?: ActivationStrategyType,\n moduleId?: string,\n component?: any\n ): /*ViewPortInstruction*/ any {\n\n let viewPortInstruction: ViewPortInstruction;\n let viewPortName = typeof nameOrInitOptions === 'string' ? nameOrInitOptions : nameOrInitOptions.name;\n const lifecycleArgs = this.lifecycleArgs;\n const config: RouteConfig = Object.assign({}, lifecycleArgs[1], { currentViewPort: viewPortName });\n\n if (typeof nameOrInitOptions === 'string') {\n viewPortInstruction = {\n name: nameOrInitOptions,\n strategy: strategy,\n moduleId: moduleId,\n component: component,\n childRouter: component.childRouter,\n lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] as LifecycleArguments\n };\n } else {\n viewPortInstruction = {\n name: viewPortName,\n strategy: nameOrInitOptions.strategy,\n component: nameOrInitOptions.component,\n moduleId: nameOrInitOptions.moduleId,\n childRouter: nameOrInitOptions.component.childRouter,\n lifecycleArgs: [lifecycleArgs[0], config, lifecycleArgs[2]] as LifecycleArguments\n };\n }\n\n return this.viewPortInstructions[viewPortName] = viewPortInstruction;\n }\n\n /**\n * Gets the name of the route pattern's wildcard parameter, if applicable.\n */\n getWildCardName(): string {\n // todo: potential issue, or at least unsafe typings\n let configRoute = this.config.route as string;\n let wildcardIndex = configRoute.lastIndexOf('*');\n return configRoute.substr(wildcardIndex + 1);\n }\n\n /**\n * Gets the path and query string created by filling the route\n * pattern's wildcard parameter with the matching param.\n */\n getWildcardPath(): string {\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n let queryString = this.queryString;\n\n if (queryString) {\n path += '?' + queryString;\n }\n\n return path;\n }\n\n /**\n * Gets the instruction's base URL, accounting for wildcard route parameters.\n */\n getBaseUrl(): string {\n let $encodeURI = encodeURI;\n let fragment = decodeURI(this.fragment);\n\n if (fragment === '') {\n let nonEmptyRoute = this.router.routes.find(route => {\n return route.name === this.config.name &&\n route.route !== '';\n });\n if (nonEmptyRoute) {\n fragment = nonEmptyRoute.route as any;\n }\n }\n\n if (!this.params) {\n return $encodeURI(fragment);\n }\n\n let wildcardName = this.getWildCardName();\n let path = this.params[wildcardName] || '';\n\n if (!path) {\n return $encodeURI(fragment);\n }\n\n return $encodeURI(fragment.substr(0, fragment.lastIndexOf(path)));\n }\n\n /**\n * Finalize a viewport instruction\n * @internal\n */\n _commitChanges(waitToSwap: boolean): Promise {\n let router = this.router;\n router.currentInstruction = this;\n\n const previousInstruction = this.previousInstruction;\n if (previousInstruction) {\n previousInstruction.config.navModel.isActive = false;\n }\n\n this.config.navModel.isActive = true;\n\n router.refreshNavigation();\n\n let loads: Promise[] = [];\n let delaySwaps: ISwapPlan[] = [];\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let viewPort = router.viewPorts[viewPortName];\n\n if (!viewPort) {\n throw new Error(`There was no router-view found in the view for ${viewPortInstruction.moduleId}.`);\n }\n\n let childNavInstruction = viewPortInstruction.childNavigationInstruction;\n if (viewPortInstruction.strategy === InternalActivationStrategy.Replace) {\n if (childNavInstruction && childNavInstruction.parentCatchHandler) {\n loads.push(childNavInstruction._commitChanges(waitToSwap));\n } else {\n if (waitToSwap) {\n delaySwaps.push({ viewPort, viewPortInstruction });\n }\n loads.push(\n viewPort\n .process(viewPortInstruction, waitToSwap)\n .then(() => childNavInstruction\n ? childNavInstruction._commitChanges(waitToSwap)\n : Promise.resolve()\n )\n );\n }\n } else {\n if (childNavInstruction) {\n loads.push(childNavInstruction._commitChanges(waitToSwap));\n }\n }\n }\n\n return Promise\n .all(loads)\n .then(() => {\n delaySwaps.forEach(x => x.viewPort.swap(x.viewPortInstruction));\n return null;\n })\n .then(() => prune(this));\n }\n\n /**@internal */\n _updateTitle(): void {\n let router = this.router;\n let title = this._buildTitle(router.titleSeparator);\n if (title) {\n router.history.setTitle(title);\n }\n }\n\n /**@internal */\n _buildTitle(separator: string = ' | '): string {\n let title = '';\n let childTitles = [];\n let navModelTitle = this.config.navModel.title;\n let instructionRouter = this.router;\n let viewPortInstructions: Record = this.viewPortInstructions;\n\n if (navModelTitle) {\n title = instructionRouter.transformTitle(navModelTitle);\n }\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let child_nav_instruction = viewPortInstruction.childNavigationInstruction;\n\n if (child_nav_instruction) {\n let childTitle = child_nav_instruction._buildTitle(separator);\n if (childTitle) {\n childTitles.push(childTitle);\n }\n }\n }\n\n if (childTitles.length) {\n title = childTitles.join(separator) + (title ? separator : '') + title;\n }\n\n if (instructionRouter.title) {\n title += (title ? separator : '') + instructionRouter.transformTitle(instructionRouter.title);\n }\n\n return title;\n }\n}\n\nconst prune = (instruction: NavigationInstruction): void => {\n instruction.previousInstruction = null;\n instruction.plan = null;\n};\n\ninterface ISwapPlan {\n viewPort: ViewPort;\n viewPortInstruction: ViewPortInstruction;\n}\n","import { Router } from './router';\nimport { RouteConfig } from './interfaces';\n\n/**\n* Class for storing and interacting with a route's navigation settings.\n*/\nexport class NavModel {\n\n /**\n * True if this nav item is currently active.\n */\n isActive: boolean = false;\n\n /**\n * The title.\n */\n title: string = null;\n\n /**\n * This nav item's absolute href.\n */\n href: string = null;\n\n /**\n * This nav item's relative href.\n */\n relativeHref: string = null;\n\n /**\n * Data attached to the route at configuration time.\n */\n settings: any = {};\n\n /**\n * The route config.\n */\n config: RouteConfig = null;\n\n /**\n * The router associated with this navigation model.\n */\n router: Router;\n\n order: number | boolean;\n\n constructor(router: Router, relativeHref: string) {\n this.router = router;\n this.relativeHref = relativeHref;\n }\n\n /**\n * Sets the route's title and updates document.title.\n * If the a navigation is in progress, the change will be applied\n * to document.title when the navigation completes.\n *\n * @param title The new title.\n */\n setTitle(title: string): void {\n this.title = title;\n\n if (this.isActive) {\n this.router.updateTitle();\n }\n }\n}\n","import { RouteConfig } from './interfaces';\n\nexport function _normalizeAbsolutePath(path: string, hasPushState: boolean, absolute: boolean = false) {\n if (!hasPushState && path[0] !== '#') {\n path = '#' + path;\n }\n\n if (hasPushState && absolute) {\n path = path.substring(1, path.length);\n }\n\n return path;\n}\n\nexport function _createRootedPath(fragment: string, baseUrl: string, hasPushState: boolean, absolute?: boolean) {\n if (isAbsoluteUrl.test(fragment)) {\n return fragment;\n }\n\n let path = '';\n\n if (baseUrl.length && baseUrl[0] !== '/') {\n path += '/';\n }\n\n path += baseUrl;\n\n if ((!path.length || path[path.length - 1] !== '/') && fragment[0] !== '/') {\n path += '/';\n }\n\n if (path.length && path[path.length - 1] === '/' && fragment[0] === '/') {\n path = path.substring(0, path.length - 1);\n }\n\n return _normalizeAbsolutePath(path + fragment, hasPushState, absolute);\n}\n\nexport function _resolveUrl(fragment: string, baseUrl: string, hasPushState?: boolean) {\n if (isRootedPath.test(fragment)) {\n return _normalizeAbsolutePath(fragment, hasPushState);\n }\n\n return _createRootedPath(fragment, baseUrl, hasPushState);\n}\n\nexport function _ensureArrayWithSingleRoutePerConfig(config: RouteConfig) {\n let routeConfigs = [];\n\n if (Array.isArray(config.route)) {\n for (let i = 0, ii = config.route.length; i < ii; ++i) {\n let current = Object.assign({}, config);\n current.route = config.route[i];\n routeConfigs.push(current);\n }\n } else {\n routeConfigs.push(Object.assign({}, config));\n }\n\n return routeConfigs;\n}\n\nconst isRootedPath = /^#?\\//;\nconst isAbsoluteUrl = /^([a-z][a-z0-9+\\-.]*:)?\\/\\//i;\n","import { RouteConfig, PipelineStep, RouteConfigSpecifier } from './interfaces';\nimport { _ensureArrayWithSingleRoutePerConfig } from './util';\nimport { Router } from './router';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * Class used to configure a [[Router]] instance.\n *\n * @constructor\n */\nexport class RouterConfiguration {\n instructions: Array<(router: Router) => void> = [];\n options: {\n [key: string]: any;\n compareQueryParams?: boolean;\n root?: string;\n pushState?: boolean;\n hashChange?: boolean;\n silent?: boolean;\n } = {};\n pipelineSteps: Array<{ name: string, step: Function | PipelineStep }> = [];\n title: string;\n titleSeparator: string;\n unknownRouteConfig: RouteConfigSpecifier;\n viewPortDefaults: Record;\n\n /**@internal */\n _fallbackRoute: string;\n\n /**\n * Adds a step to be run during the [[Router]]'s navigation pipeline.\n *\n * @param name The name of the pipeline slot to insert the step into.\n * @param step The pipeline step.\n * @chainable\n */\n addPipelineStep(name: string, step: Function | PipelineStep): RouterConfiguration {\n if (step === null || step === undefined) {\n throw new Error('Pipeline step cannot be null or undefined.');\n }\n this.pipelineSteps.push({ name, step });\n return this;\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s authorize pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addAuthorizeStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.Authorize, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preActivate pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreActivateStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreActivate, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s preRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPreRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PreRender, step);\n }\n\n /**\n * Adds a step to be run during the [[Router]]'s postRender pipeline slot.\n *\n * @param step The pipeline step.\n * @chainable\n */\n addPostRenderStep(step: Function | PipelineStep): RouterConfiguration {\n return this.addPipelineStep(PipelineSlotName.PostRender, step);\n }\n\n /**\n * Configures a route that will be used if there is no previous location available on navigation cancellation.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @chainable\n */\n fallbackRoute(fragment: string): RouterConfiguration {\n this._fallbackRoute = fragment;\n return this;\n }\n\n /**\n * Maps one or more routes to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map.\n * @chainable\n */\n map(route: RouteConfig | RouteConfig[]): RouterConfiguration {\n if (Array.isArray(route)) {\n route.forEach(r => this.map(r));\n return this;\n }\n\n return this.mapRoute(route);\n }\n\n /**\n * Configures defaults to use for any view ports.\n *\n * @param viewPortConfig a view port configuration object to use as a\n * default, of the form { viewPortName: { moduleId } }.\n * @chainable\n */\n useViewPortDefaults(viewPortConfig: Record): RouterConfiguration {\n this.viewPortDefaults = viewPortConfig;\n return this;\n }\n\n /**\n * Maps a single route to be registered with the router.\n *\n * @param route The [[RouteConfig]] to map.\n * @chainable\n */\n mapRoute(config: RouteConfig): RouterConfiguration {\n this.instructions.push(router => {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n\n let navModel;\n for (let i = 0, ii = routeConfigs.length; i < ii; ++i) {\n let routeConfig = routeConfigs[i];\n routeConfig.settings = routeConfig.settings || {};\n if (!navModel) {\n navModel = router.createNavModel(routeConfig);\n }\n\n router.addRoute(routeConfig, navModel);\n }\n });\n\n return this;\n }\n\n /**\n * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes.\n *\n * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the\n * [[NavigationInstruction]] and selects a moduleId to load.\n * @chainable\n */\n mapUnknownRoutes(config: RouteConfigSpecifier): RouterConfiguration {\n this.unknownRouteConfig = config;\n return this;\n }\n\n /**\n * Applies the current configuration to the specified [[Router]].\n *\n * @param router The [[Router]] to apply the configuration to.\n */\n exportToRouter(router: Router): void {\n let instructions = this.instructions;\n for (let i = 0, ii = instructions.length; i < ii; ++i) {\n instructions[i](router);\n }\n\n let { title, titleSeparator, unknownRouteConfig, _fallbackRoute, viewPortDefaults } = this;\n\n if (title) {\n router.title = title;\n }\n\n if (titleSeparator) {\n router.titleSeparator = titleSeparator;\n }\n\n if (unknownRouteConfig) {\n router.handleUnknownRoutes(unknownRouteConfig);\n }\n\n if (_fallbackRoute) {\n router.fallbackRoute = _fallbackRoute;\n }\n\n if (viewPortDefaults) {\n router.useViewPortDefaults(viewPortDefaults);\n }\n\n Object.assign(router.options, this.options);\n\n let pipelineSteps = this.pipelineSteps;\n let pipelineStepCount = pipelineSteps.length;\n if (pipelineStepCount) {\n if (!router.isRoot) {\n throw new Error('Pipeline steps can only be added to the root router');\n }\n\n let pipelineProvider = router.pipelineProvider;\n for (let i = 0, ii = pipelineStepCount; i < ii; ++i) {\n let { name, step } = pipelineSteps[i];\n pipelineProvider.addStep(name, step);\n }\n }\n }\n}\n","import { RouteRecognizer, RouteHandler, ConfigurableRoute, State, RecognizedRoute } from 'aurelia-route-recognizer';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { NavigationInstruction, NavigationInstructionInit } from './navigation-instruction';\nimport { NavModel } from './nav-model';\nimport { RouterConfiguration } from './router-configuration';\nimport {\n _ensureArrayWithSingleRoutePerConfig,\n _normalizeAbsolutePath,\n _createRootedPath,\n _resolveUrl\n} from './util';\nimport { RouteConfig, RouteConfigSpecifier, ViewPortInstruction } from './interfaces';\nimport { PipelineProvider } from './pipeline-provider';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface History {\n // This is wrong, as it's an implementation detail from aurelia-history-browser\n // but we are poking it in here so probably will need to make it official in `aurelia-history`\n /**\n * A private flag of Aurelia History implementation to indicate if push state should be used\n */\n _hasPushState: boolean;\n\n previousLocation: string;\n }\n}\n\n/**@internal */\ndeclare module 'aurelia-route-recognizer' {\n interface State {\n types: {\n dynamics: DynamicSegment;\n stars: StarSegment;\n };\n }\n\n interface RouteHandler {\n navigationStrategy?: (instruction: NavigationInstruction) => any;\n }\n\n interface RecognizedRoute {\n config?: RouteConfig;\n queryParams?: Record;\n }\n}\n\ntype RouterConfigurationResolution = RouterConfiguration | ((cfg: RouterConfiguration) => void | RouterConfiguration | Promise);\n\n/**\n * The primary class responsible for handling routing and navigation.\n */\nexport class Router {\n\n /**\n * Container associated with this router. Also used to create child container for creating child router.\n */\n container: Container;\n\n /**\n * History instance of Aurelia abstract class for wrapping platform history global object\n */\n history: History;\n\n /**\n * A registry of registered viewport. Will be used to handle process navigation instruction route loading\n * and dom swapping\n */\n viewPorts: Record;\n\n /**\n * List of route configs registered with this router\n */\n routes: RouteConfig[];\n\n /**\n * The [[Router]]'s current base URL, typically based on the [[Router.currentInstruction]].\n */\n baseUrl: string;\n\n /**\n * If defined, used in generation of document title for [[Router]]'s routes.\n */\n title: string | undefined;\n\n /**\n * The separator used in the document title between [[Router]]'s routes.\n */\n titleSeparator: string | undefined;\n\n /**\n * True if the [[Router]] has been configured.\n */\n isConfigured: boolean;\n\n /**\n * True if the [[Router]] is currently processing a navigation.\n */\n isNavigating: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigate function(s).\n */\n isExplicitNavigation: boolean;\n\n /**\n * True if the [[Router]] is navigating due to explicit call to navigateBack function.\n */\n isExplicitNavigationBack: boolean;\n\n /**\n * True if the [[Router]] is navigating into the app for the first time in the browser session.\n */\n isNavigatingFirst: boolean;\n\n /**\n * True if the [[Router]] is navigating to a page instance not in the browser session history.\n */\n isNavigatingNew: boolean;\n\n /**\n * True if the [[Router]] is navigating forward in the browser session history.\n */\n isNavigatingForward: boolean;\n\n /**\n * True if the [[Router]] is navigating back in the browser session history.\n */\n isNavigatingBack: boolean;\n\n /**\n * True if the [[Router]] is navigating due to a browser refresh.\n */\n isNavigatingRefresh: boolean;\n\n /**\n * True if the previous instruction successfully completed the CanDeactivatePreviousStep in the current navigation.\n */\n couldDeactivate: boolean;\n\n /**\n * The currently active navigation tracker.\n */\n currentNavigationTracker: number;\n\n /**\n * The navigation models for routes that specified [[RouteConfig.nav]].\n */\n navigation: NavModel[];\n\n /**\n * The currently active navigation instruction.\n */\n currentInstruction: NavigationInstruction;\n\n /**\n * The parent router, or null if this instance is not a child router.\n */\n parent: Router = null;\n\n options: any = {};\n\n /**\n * The defaults used when a viewport lacks specified content\n */\n viewPortDefaults: Record = {};\n\n /**@internal */\n catchAllHandler: (instruction: NavigationInstruction) => NavigationInstruction | Promise;\n /**@internal */\n fallbackRoute: string;\n /**@internal */\n pipelineProvider: PipelineProvider;\n /**@internal */\n _fallbackOrder: number;\n /**@internal */\n _recognizer: RouteRecognizer;\n /**@internal */\n _childRecognizer: RouteRecognizer;\n /**@internal */\n _configuredPromise: Promise;\n /**@internal */\n _resolveConfiguredPromise: (value?: any) => void;\n\n /**\n * Extension point to transform the document title before it is built and displayed.\n * By default, child routers delegate to the parent router, and the app router\n * returns the title unchanged.\n */\n transformTitle: (title: string) => string = (title: string) => {\n if (this.parent) {\n return this.parent.transformTitle(title);\n }\n return title;\n }\n\n /**\n * @param container The [[Container]] to use when child routers.\n * @param history The [[History]] implementation to delegate navigation requests to.\n */\n constructor(container: Container, history: History) {\n this.container = container;\n this.history = history;\n this.reset();\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset() {\n this.viewPorts = {};\n this.routes = [];\n this.baseUrl = '';\n this.isConfigured = false;\n this.isNavigating = false;\n this.isExplicitNavigation = false;\n this.isExplicitNavigationBack = false;\n this.isNavigatingFirst = false;\n this.isNavigatingNew = false;\n this.isNavigatingRefresh = false;\n this.isNavigatingForward = false;\n this.isNavigatingBack = false;\n this.couldDeactivate = false;\n this.navigation = [];\n this.currentInstruction = null;\n this.viewPortDefaults = {};\n this._fallbackOrder = 100;\n this._recognizer = new RouteRecognizer();\n this._childRecognizer = new RouteRecognizer();\n this._configuredPromise = new Promise(resolve => {\n this._resolveConfiguredPromise = resolve;\n });\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent.\n */\n get isRoot(): boolean {\n return !this.parent;\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort.\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/any, name?: string): void {\n name = name || 'default';\n this.viewPorts[name] = viewPort;\n }\n\n /**\n * Returns a Promise that resolves when the router is configured.\n */\n ensureConfigured(): Promise {\n return this._configuredPromise;\n }\n\n /**\n * Configures the router.\n *\n * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]].\n */\n configure(callbackOrConfig: RouterConfiguration | ((config: RouterConfiguration) => RouterConfiguration)): Promise {\n this.isConfigured = true;\n\n let result: RouterConfigurationResolution = callbackOrConfig as RouterConfiguration;\n let config: RouterConfiguration;\n if (typeof callbackOrConfig === 'function') {\n config = new RouterConfiguration();\n result = callbackOrConfig(config);\n }\n\n return Promise\n .resolve(result)\n .then((c) => {\n if (c && (c as RouterConfiguration).exportToRouter) {\n config = c;\n }\n\n config.exportToRouter(this);\n this.isConfigured = true;\n this._resolveConfiguredPromise();\n });\n }\n\n /**\n * Navigates to a new location.\n *\n * @param fragment The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n navigate(fragment: string, options?: NavigationOptions): boolean {\n if (!this.isConfigured && this.parent) {\n return this.parent.navigate(fragment, options);\n }\n\n this.isExplicitNavigation = true;\n return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options);\n }\n\n /**\n * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed\n * by [[Router.navigate]].\n *\n * @param route The name of the route to use when generating the navigation location.\n * @param params The route parameters to be used when populating the route pattern.\n * @param options The navigation options.\n */\n navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean {\n let path = this.generate(route, params);\n return this.navigate(path, options);\n }\n\n /**\n * Navigates back to the most recent location in history.\n */\n navigateBack(): void {\n this.isExplicitNavigationBack = true;\n this.history.navigateBack();\n }\n\n /**\n * Creates a child router of the current router.\n *\n * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified.\n * @returns {Router} The new child Router.\n */\n createChild(container?: Container): Router {\n let childRouter = new Router(container || this.container.createChild(), this.history);\n childRouter.parent = this;\n return childRouter;\n }\n\n /**\n * Generates a URL fragment matching the specified route pattern.\n *\n * @param name The name of the route whose pattern should be used to generate the fragment.\n * @param params The route params to be used to populate the route pattern.\n * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url.\n * @returns {string} A string containing the generated URL fragment.\n */\n generate(nameOrRoute: string | RouteConfig, params: any = {}, options: any = {}): string {\n // A child recognizer generates routes for potential child routes. Any potential child route is added\n // to the childRoute property of params for the childRouter to recognize. When generating routes, we\n // use the childRecognizer when childRoute params are available to generate a child router enabled route.\n let recognizer = 'childRoute' in params ? this._childRecognizer : this._recognizer;\n let hasRoute = recognizer.hasRoute(nameOrRoute as string | RouteHandler);\n if (!hasRoute) {\n if (this.parent) {\n return this.parent.generate(nameOrRoute, params, options);\n }\n throw new Error(`A route with name '${nameOrRoute}' could not be found. Check that \\`name: '${nameOrRoute}'\\` was specified in the route's config.`);\n }\n let path = recognizer.generate(nameOrRoute as string | RouteHandler, params);\n let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute);\n return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath;\n }\n\n /**\n * Creates a [[NavModel]] for the specified route config.\n *\n * @param config The route config.\n */\n createNavModel(config: RouteConfig): NavModel {\n let navModel = new NavModel(\n this,\n 'href' in config\n ? config.href\n // potential error when config.route is a string[] ?\n : config.route as string);\n navModel.title = config.title;\n navModel.order = config.nav;\n navModel.href = config.href;\n navModel.settings = config.settings;\n navModel.config = config;\n\n return navModel;\n }\n\n /**\n * Registers a new route with the router.\n *\n * @param config The [[RouteConfig]].\n * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes.\n */\n addRoute(config: RouteConfig, navModel?: NavModel): void {\n if (Array.isArray(config.route)) {\n let routeConfigs = _ensureArrayWithSingleRoutePerConfig(config);\n // the following is wrong. todo: fix this after TS refactoring release\n routeConfigs.forEach(this.addRoute.bind(this));\n return;\n }\n\n validateRouteConfig(config);\n\n if (!('viewPorts' in config) && !config.navigationStrategy) {\n config.viewPorts = {\n 'default': {\n moduleId: config.moduleId,\n view: config.view\n }\n };\n }\n\n if (!navModel) {\n navModel = this.createNavModel(config);\n }\n\n this.routes.push(config);\n\n let path = config.route;\n if (path.charAt(0) === '/') {\n path = path.substr(1);\n }\n let caseSensitive = config.caseSensitive === true;\n let state: State = this._recognizer.add({\n path: path,\n handler: config as RouteHandler,\n caseSensitive: caseSensitive\n } as ConfigurableRoute);\n\n if (path) {\n let settings = config.settings;\n delete config.settings;\n let withChild = JSON.parse(JSON.stringify(config));\n config.settings = settings;\n withChild.route = `${path}/*childRoute`;\n withChild.hasChildRouter = true;\n this._childRecognizer.add({\n path: withChild.route,\n handler: withChild,\n caseSensitive: caseSensitive\n });\n\n withChild.navModel = navModel;\n withChild.settings = config.settings;\n withChild.navigationStrategy = config.navigationStrategy;\n }\n\n config.navModel = navModel;\n\n let navigation = this.navigation;\n\n if ((navModel.order || navModel.order === 0) && navigation.indexOf(navModel) === -1) {\n if ((!navModel.href && navModel.href !== '') && (state.types.dynamics || state.types.stars)) {\n throw new Error('Invalid route config for \"' + config.route + '\" : dynamic routes must specify an \"href:\" to be included in the navigation model.');\n }\n\n if (typeof navModel.order !== 'number') {\n navModel.order = ++this._fallbackOrder;\n }\n\n navigation.push(navModel);\n // this is a potential error / inconsistency between browsers\n //\n // MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\n // If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other,\n // but sorted with respect to all different elements.\n // Note: the ECMAscript standard does not guarantee this behaviour,\n // and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.\n navigation.sort((a, b) => a.order - b.order);\n }\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasRoute(name: string): boolean {\n return !!(this._recognizer.hasRoute(name) || this.parent && this.parent.hasRoute(name));\n }\n\n /**\n * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name.\n *\n * @param name The name of the route to check.\n */\n hasOwnRoute(name: string): boolean {\n return this._recognizer.hasRoute(name);\n }\n\n /**\n * Register a handler to use when the incoming URL fragment doesn't match any registered routes.\n *\n * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]].\n */\n handleUnknownRoutes(config?: RouteConfigSpecifier): void {\n if (!config) {\n throw new Error('Invalid unknown route handler');\n }\n\n this.catchAllHandler = instruction => {\n return this\n ._createRouteConfig(config, instruction)\n .then(c => {\n instruction.config = c;\n return instruction;\n });\n };\n }\n\n /**\n * Updates the document title using the current navigation instruction.\n */\n updateTitle(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n return parentRouter.updateTitle();\n }\n\n let currentInstruction = this.currentInstruction;\n if (currentInstruction) {\n currentInstruction._updateTitle();\n }\n return undefined;\n }\n\n /**\n * Updates the navigation routes with hrefs relative to the current location.\n * Note: This method will likely move to a plugin in a future release.\n */\n refreshNavigation(): void {\n let nav = this.navigation;\n\n for (let i = 0, length = nav.length; i < length; i++) {\n let current = nav[i];\n if (!current.config.href) {\n current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState);\n } else {\n current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState);\n }\n }\n }\n\n /**\n * Sets the default configuration for the view ports. This specifies how to\n * populate a view port for which no module is specified. The default is\n * an empty view/view-model pair.\n */\n useViewPortDefaults($viewPortDefaults: Record): void {\n // a workaround to have strong typings while not requiring to expose interface ViewPortInstruction\n let viewPortDefaults: Record = $viewPortDefaults;\n for (let viewPortName in viewPortDefaults) {\n let viewPortConfig = viewPortDefaults[viewPortName];\n this.viewPortDefaults[viewPortName] = {\n moduleId: viewPortConfig.moduleId\n };\n }\n }\n\n /**@internal */\n _refreshBaseUrl(): void {\n let parentRouter = this.parent;\n if (parentRouter) {\n this.baseUrl = generateBaseUrl(parentRouter, parentRouter.currentInstruction);\n }\n }\n\n /**@internal */\n _createNavigationInstruction(url: string = '', parentInstruction: NavigationInstruction = null): Promise {\n let fragment = url;\n let queryString = '';\n\n let queryIndex = url.indexOf('?');\n if (queryIndex !== -1) {\n fragment = url.substr(0, queryIndex);\n queryString = url.substr(queryIndex + 1);\n }\n\n let urlRecognizationResults = this._recognizer.recognize(url) as IRouteRecognizationResults;\n if (!urlRecognizationResults || !urlRecognizationResults.length) {\n urlRecognizationResults = this._childRecognizer.recognize(url) as IRouteRecognizationResults;\n }\n\n let instructionInit: NavigationInstructionInit = {\n fragment,\n queryString,\n config: null,\n parentInstruction,\n previousInstruction: this.currentInstruction,\n router: this,\n options: {\n compareQueryParams: this.options.compareQueryParams\n }\n };\n\n let result: Promise;\n\n if (urlRecognizationResults && urlRecognizationResults.length) {\n let first = urlRecognizationResults[0];\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: first.params,\n queryParams: first.queryParams || urlRecognizationResults.queryParams,\n config: first.config || first.handler\n }));\n\n if (typeof first.handler === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler, first);\n } else if (first.handler && typeof first.handler.navigationStrategy === 'function') {\n result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler);\n } else {\n result = Promise.resolve(instruction);\n }\n } else if (this.catchAllHandler) {\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n config: null // config will be created by the catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, this.catchAllHandler);\n } else if (this.parent) {\n let router = this._parentCatchAllHandler(this.parent);\n\n if (router) {\n let newParentInstruction = this._findParentInstructionFromRouter(router, parentInstruction);\n\n let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {\n params: { path: fragment },\n queryParams: urlRecognizationResults ? urlRecognizationResults.queryParams : {},\n router: router,\n parentInstruction: newParentInstruction,\n parentCatchHandler: true,\n config: null // config will be created by the chained parent catchAllHandler\n }));\n\n result = evaluateNavigationStrategy(instruction, router.catchAllHandler);\n }\n }\n\n if (result && parentInstruction) {\n this.baseUrl = generateBaseUrl(this.parent, parentInstruction);\n }\n\n return result || Promise.reject(new Error(`Route not found: ${url}`));\n }\n\n /**@internal */\n _findParentInstructionFromRouter(router: Router, instruction: NavigationInstruction): NavigationInstruction {\n if (instruction.router === router) {\n instruction.fragment = router.baseUrl; // need to change the fragment in case of a redirect instead of moduleId\n return instruction;\n } else if (instruction.parentInstruction) {\n return this._findParentInstructionFromRouter(router, instruction.parentInstruction);\n }\n return undefined;\n }\n\n /**@internal */\n _parentCatchAllHandler(router: Router): Router | false {\n if (router.catchAllHandler) {\n return router;\n } else if (router.parent) {\n return this._parentCatchAllHandler(router.parent);\n }\n return false;\n }\n\n /**\n * @internal\n */\n _createRouteConfig(config: RouteConfigSpecifier, instruction: NavigationInstruction): Promise {\n return Promise\n .resolve(config)\n .then((c: any) => {\n if (typeof c === 'string') {\n return { moduleId: c } as RouteConfig;\n } else if (typeof c === 'function') {\n return c(instruction);\n }\n\n return c;\n })\n // typing here could be either RouteConfig or RedirectConfig\n // but temporarily treat both as RouteConfig\n // todo: improve typings precision\n .then((c: string | RouteConfig) => typeof c === 'string' ? { moduleId: c } as RouteConfig : c)\n .then((c: RouteConfig) => {\n c.route = instruction.params.path;\n validateRouteConfig(c);\n\n if (!c.navModel) {\n c.navModel = this.createNavModel(c);\n }\n\n return c;\n });\n }\n}\n\n/* @internal exported for unit testing */\nexport const generateBaseUrl = (router: Router, instruction: NavigationInstruction): string => {\n return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`;\n};\n\n/* @internal exported for unit testing */\nexport const validateRouteConfig = (config: RouteConfig): void => {\n if (typeof config !== 'object') {\n throw new Error('Invalid Route Config');\n }\n\n if (typeof config.route !== 'string') {\n let name = config.name || '(no name)';\n throw new Error('Invalid Route Config for \"' + name + '\": You must specify a \"route:\" pattern.');\n }\n\n if (!('redirect' in config || config.moduleId || config.navigationStrategy || config.viewPorts)) {\n throw new Error('Invalid Route Config for \"' + config.route + '\": You must specify a \"moduleId:\", \"redirect:\", \"navigationStrategy:\", or \"viewPorts:\".');\n }\n};\n\n/* @internal exported for unit testing */\nexport const evaluateNavigationStrategy = (\n instruction: NavigationInstruction,\n evaluator: Function,\n context?: any\n): Promise => {\n return Promise\n .resolve(evaluator.call(context, instruction))\n .then(() => {\n if (!('viewPorts' in instruction.config)) {\n instruction.config.viewPorts = {\n 'default': {\n moduleId: instruction.config.moduleId\n }\n };\n }\n\n return instruction;\n });\n};\n\ninterface IRouteRecognizationResults extends Array {\n queryParams: Record;\n}\n","import { PipelineStatus } from './pipeline-status';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Next, StepRunnerFunction, NextCompletionHandler } from './interfaces';\n\n/**@internal exported for unit testing */\nexport const createNextFn = (instruction: NavigationInstruction, steps: StepRunnerFunction[]): Next => {\n let index = -1;\n const next: Next = function() {\n index++;\n\n if (index < steps.length) {\n let currentStep = steps[index];\n\n try {\n return currentStep(instruction, next);\n } catch (e) {\n return next.reject(e);\n }\n } else {\n return next.complete();\n }\n } as Next;\n\n next.complete = createCompletionHandler(next, PipelineStatus.Completed);\n next.cancel = createCompletionHandler(next, PipelineStatus.Canceled);\n next.reject = createCompletionHandler(next, PipelineStatus.Rejected);\n\n return next;\n};\n\n/**@internal exported for unit testing */\nexport const createCompletionHandler = (next: Next, status: PipelineStatus): NextCompletionHandler => {\n return (output: any) => Promise\n .resolve({\n status,\n output,\n completed: status === PipelineStatus.Completed\n });\n};\n","import { PipelineStep, PipelineResult, Next, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { createNextFn } from './next';\n\n/**\n * The class responsible for managing and processing the navigation pipeline.\n */\nexport class Pipeline {\n /**\n * The pipeline steps. And steps added via addStep will be converted to a function\n * The actualy running functions with correct step contexts of this pipeline\n */\n steps: StepRunnerFunction[] = [];\n\n /**\n * Adds a step to the pipeline.\n *\n * @param step The pipeline step.\n */\n addStep(step: StepRunnerFunction | PipelineStep | IPipelineSlot): Pipeline {\n let run;\n\n if (typeof step === 'function') {\n run = step;\n } else if (typeof step.getSteps === 'function') {\n // getSteps is to enable support open slots\n // where devs can add multiple steps into the same slot name\n let steps = step.getSteps();\n for (let i = 0, l = steps.length; i < l; i++) {\n this.addStep(steps[i]);\n }\n\n return this;\n } else {\n run = (step as PipelineStep).run.bind(step);\n }\n\n this.steps.push(run);\n\n return this;\n }\n\n /**\n * Runs the pipeline.\n *\n * @param instruction The navigation instruction to process.\n */\n run(instruction: NavigationInstruction): Promise {\n const nextFn = createNextFn(instruction, this.steps);\n return nextFn();\n }\n}\n","import { NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\n\n/**@internal */\ndeclare module 'aurelia-history' {\n interface NavigationOptions {\n useAppRouter?: boolean;\n }\n}\n\n/**\n* When a navigation command is encountered, the current navigation\n* will be cancelled and control will be passed to the navigation\n* command so it can determine the correct action.\n*/\nexport interface NavigationCommand {\n navigate: (router: Router) => void;\n /**@internal */\n shouldContinueProcessing?: boolean;\n /**@internal */\n setRouter?: (router: Router) => void;\n}\n\n/**\n* Determines if the provided object is a navigation command.\n* A navigation command is anything with a navigate method.\n*\n* @param obj The object to check.\n*/\nexport function isNavigationCommand(obj: any): obj is NavigationCommand {\n return obj && typeof obj.navigate === 'function';\n}\n\n/**\n* Used during the activation lifecycle to cause a redirect.\n*/\nexport class Redirect implements NavigationCommand {\n\n url: string;\n /**@internal */\n options: NavigationOptions;\n /**@internal */\n shouldContinueProcessing: boolean;\n\n private router: Router;\n\n /**\n * @param url The URL fragment to use as the navigation destination.\n * @param options The navigation options.\n */\n constructor(url: string, options: NavigationOptions = {}) {\n this.url = url;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigate(this.url, this.options);\n }\n}\n\n/**\n * Used during the activation lifecycle to cause a redirect to a named route.\n */\nexport class RedirectToRoute implements NavigationCommand {\n\n route: string;\n params: any;\n /**@internal */\n options: NavigationOptions;\n\n /**@internal */\n shouldContinueProcessing: boolean;\n\n /**@internal */\n router: Router;\n\n /**\n * @param route The name of the route.\n * @param params The parameters to be sent to the activation method.\n * @param options The options to use for navigation.\n */\n constructor(route: string, params: any = {}, options: NavigationOptions = {}) {\n this.route = route;\n this.params = params;\n this.options = Object.assign({ trigger: true, replace: true }, options);\n this.shouldContinueProcessing = false;\n }\n\n /**\n * Called by the activation system to set the child router.\n *\n * @param router The router.\n */\n setRouter(router: Router): void {\n this.router = router;\n }\n\n /**\n * Called by the navigation pipeline to navigate.\n *\n * @param appRouter The router to be redirected.\n */\n navigate(appRouter: Router): void {\n let navigatingRouter = this.options.useAppRouter ? appRouter : (this.router || appRouter);\n navigatingRouter.navigateToRoute(this.route, this.params, this.options);\n }\n}\n","import { ViewPortPlan, ViewPortInstruction, RouteConfig, ViewPort } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { InternalActivationStrategy, ActivationStrategyType } from './activation-strategy';\n\ntype ViewPortPlansRecord = Record;\n\n/**\n * @internal exported for unit testing\n */\nexport function _buildNavigationPlan(\n instruction: NavigationInstruction,\n forceLifecycleMinimum?: boolean\n): Promise {\n let config = instruction.config;\n\n if ('redirect' in config) {\n return buildRedirectPlan(instruction);\n }\n\n const prevInstruction = instruction.previousInstruction;\n const defaultViewPortConfigs = instruction.router.viewPortDefaults;\n\n if (prevInstruction) {\n return buildTransitionPlans(instruction, prevInstruction, defaultViewPortConfigs, forceLifecycleMinimum);\n }\n\n // first navigation, only need to prepare a few information for each viewport plan\n const viewPortPlans: ViewPortPlansRecord = {};\n let viewPortConfigs = config.viewPorts;\n for (let viewPortName in viewPortConfigs) {\n let viewPortConfig = viewPortConfigs[viewPortName];\n if (viewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) {\n viewPortConfig = defaultViewPortConfigs[viewPortName];\n }\n viewPortPlans[viewPortName] = {\n name: viewPortName,\n strategy: InternalActivationStrategy.Replace,\n config: viewPortConfig\n };\n }\n\n return Promise.resolve(viewPortPlans);\n}\n\n/**\n * Build redirect plan based on config of a navigation instruction\n * @internal exported for unit testing\n */\nexport const buildRedirectPlan = (instruction: NavigationInstruction) => {\n const config = instruction.config;\n const router = instruction.router;\n return router\n ._createNavigationInstruction(config.redirect)\n .then(redirectInstruction => {\n\n const params: Record = {};\n const originalInstructionParams = instruction.params;\n const redirectInstructionParams = redirectInstruction.params;\n\n for (let key in redirectInstructionParams) {\n // If the param on the redirect points to another param, e.g. { route: first/:this, redirect: second/:this }\n let val = redirectInstructionParams[key];\n if (typeof val === 'string' && val[0] === ':') {\n val = val.slice(1);\n // And if that param is found on the original instruction then use it\n if (val in originalInstructionParams) {\n params[key] = originalInstructionParams[val];\n }\n } else {\n params[key] = redirectInstructionParams[key];\n }\n }\n let redirectLocation = router.generate(redirectInstruction.config, params, instruction.options);\n\n // Special handling for child routes\n for (let key in originalInstructionParams) {\n redirectLocation = redirectLocation.replace(`:${key}`, originalInstructionParams[key]);\n }\n\n let queryString = instruction.queryString;\n if (queryString) {\n redirectLocation += '?' + queryString;\n }\n\n return Promise.resolve(new Redirect(redirectLocation));\n });\n};\n\n/**\n * @param viewPortPlans the Plan record that holds information about built plans\n * @internal exported for unit testing\n */\nexport const buildTransitionPlans = (\n currentInstruction: NavigationInstruction,\n previousInstruction: NavigationInstruction,\n defaultViewPortConfigs: Record,\n forceLifecycleMinimum?: boolean\n): Promise => {\n\n let viewPortPlans: ViewPortPlansRecord = {};\n let newInstructionConfig = currentInstruction.config;\n let hasNewParams = hasDifferentParameterValues(previousInstruction, currentInstruction);\n let pending: Promise[] = [];\n let previousViewPortInstructions = previousInstruction.viewPortInstructions as Record;\n\n for (let viewPortName in previousViewPortInstructions) {\n\n const prevViewPortInstruction = previousViewPortInstructions[viewPortName];\n const prevViewPortComponent = prevViewPortInstruction.component;\n const newInstructionViewPortConfigs = newInstructionConfig.viewPorts as Record;\n\n // if this is invoked on a viewport without any changes, based on new url,\n // newViewPortConfig will be the existing viewport instruction\n let nextViewPortConfig = viewPortName in newInstructionViewPortConfigs\n ? newInstructionViewPortConfigs[viewPortName]\n : prevViewPortInstruction;\n\n if (nextViewPortConfig.moduleId === null && viewPortName in defaultViewPortConfigs) {\n nextViewPortConfig = defaultViewPortConfigs[viewPortName];\n }\n\n const viewPortActivationStrategy = determineActivationStrategy(\n currentInstruction,\n prevViewPortInstruction,\n nextViewPortConfig,\n hasNewParams,\n forceLifecycleMinimum\n );\n const viewPortPlan = viewPortPlans[viewPortName] = {\n name: viewPortName,\n // ViewPortInstruction can quack like a RouteConfig\n config: nextViewPortConfig as RouteConfig,\n prevComponent: prevViewPortComponent,\n prevModuleId: prevViewPortInstruction.moduleId,\n strategy: viewPortActivationStrategy\n } as ViewPortPlan;\n\n // recursively build nav plans for all existing child routers/viewports of this viewport\n // this is possible because existing child viewports and routers already have necessary information\n // to process the wildcard path from parent instruction\n if (viewPortActivationStrategy !== InternalActivationStrategy.Replace && prevViewPortInstruction.childRouter) {\n const path = currentInstruction.getWildcardPath();\n const task: Promise = prevViewPortInstruction\n .childRouter\n ._createNavigationInstruction(path, currentInstruction)\n .then((childInstruction: NavigationInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(\n childInstruction,\n // is it safe to assume viewPortPlan has not been changed from previous assignment?\n // if so, can just use local variable viewPortPlanStrategy\n // there could be user code modifying viewport plan during _createNavigationInstruction?\n viewPortPlan.strategy === InternalActivationStrategy.InvokeLifecycle\n )\n .then(childPlan => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n // for bluebird ?\n return null;\n });\n });\n\n pending.push(task);\n }\n }\n\n return Promise.all(pending).then(() => viewPortPlans);\n};\n\n/**\n * @param newViewPortConfig if this is invoked on a viewport without any changes, based on new url, newViewPortConfig will be the existing viewport instruction\n * @internal exported for unit testing\n */\nexport const determineActivationStrategy = (\n currentNavInstruction: NavigationInstruction,\n prevViewPortInstruction: ViewPortInstruction,\n newViewPortConfig: RouteConfig | ViewPortInstruction,\n // indicates whether there is difference between old and new url params\n hasNewParams: boolean,\n forceLifecycleMinimum?: boolean\n): ActivationStrategyType => {\n\n let newInstructionConfig = currentNavInstruction.config;\n let prevViewPortViewModel = prevViewPortInstruction.component.viewModel;\n let viewPortPlanStrategy: ActivationStrategyType;\n\n if (prevViewPortInstruction.moduleId !== newViewPortConfig.moduleId) {\n viewPortPlanStrategy = InternalActivationStrategy.Replace;\n } else if ('determineActivationStrategy' in prevViewPortViewModel) {\n viewPortPlanStrategy = prevViewPortViewModel.determineActivationStrategy(...currentNavInstruction.lifecycleArgs);\n } else if (newInstructionConfig.activationStrategy) {\n viewPortPlanStrategy = newInstructionConfig.activationStrategy;\n } else if (hasNewParams || forceLifecycleMinimum) {\n viewPortPlanStrategy = InternalActivationStrategy.InvokeLifecycle;\n } else {\n viewPortPlanStrategy = InternalActivationStrategy.NoChange;\n }\n return viewPortPlanStrategy;\n};\n\n/**@internal exported for unit testing */\nexport const hasDifferentParameterValues = (prev: NavigationInstruction, next: NavigationInstruction): boolean => {\n let prevParams = prev.params;\n let nextParams = next.params;\n let nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null;\n\n for (let key in nextParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n for (let key in prevParams) {\n if (key === nextWildCardName) {\n continue;\n }\n\n if (prevParams[key] !== nextParams[key]) {\n return true;\n }\n }\n\n if (!next.options.compareQueryParams) {\n return false;\n }\n\n let prevQueryParams = prev.queryParams;\n let nextQueryParams = next.queryParams;\n for (let key in nextQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n for (let key in prevQueryParams) {\n if (prevQueryParams[key] !== nextQueryParams[key]) {\n return true;\n }\n }\n\n return false;\n};\n","import { Next } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { _buildNavigationPlan } from './navigation-plan';\n\n/**\n * Transform a navigation instruction into viewport plan record object,\n * or a redirect request if user viewmodel demands\n */\nexport class BuildNavigationPlanStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return _buildNavigationPlan(navigationInstruction)\n .then(plan => {\n if (plan instanceof Redirect) {\n return next.cancel(plan);\n }\n navigationInstruction.plan = plan;\n return next();\n })\n .catch(next.cancel);\n }\n}\n","import { RouteConfig, ViewPortComponent, ViewPortPlan, ViewPortInstruction } from './interfaces';\nimport { Redirect } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { _buildNavigationPlan } from './navigation-plan';\nimport { InternalActivationStrategy } from './activation-strategy';\nimport { RouteLoader } from './route-loader';\n\n/**\n * Loading plan calculated based on a navigration-instruction and a viewport plan\n */\ninterface ILoadingPlan {\n viewPortPlan: ViewPortPlan;\n navigationInstruction: NavigationInstruction;\n}\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadNewRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction\n): Promise => {\n let loadingPlans = determineLoadingPlans(navigationInstruction);\n let loadPromises = loadingPlans.map((loadingPlan: ILoadingPlan) => loadRoute(\n routeLoader,\n loadingPlan.navigationInstruction,\n loadingPlan.viewPortPlan\n ));\n\n return Promise.all(loadPromises);\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const determineLoadingPlans = (\n navigationInstruction: NavigationInstruction,\n loadingPlans: ILoadingPlan[] = []\n): ILoadingPlan[] => {\n let viewPortPlans: Record = navigationInstruction.plan;\n\n for (let viewPortName in viewPortPlans) {\n let viewPortPlan = viewPortPlans[viewPortName];\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (viewPortPlan.strategy === InternalActivationStrategy.Replace) {\n loadingPlans.push({ viewPortPlan, navigationInstruction } as ILoadingPlan);\n\n if (childNavInstruction) {\n determineLoadingPlans(childNavInstruction, loadingPlans);\n }\n } else {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction({\n name: viewPortName,\n strategy: viewPortPlan.strategy,\n moduleId: viewPortPlan.prevModuleId,\n component: viewPortPlan.prevComponent\n }) as ViewPortInstruction;\n\n if (childNavInstruction) {\n viewPortInstruction.childNavigationInstruction = childNavInstruction;\n determineLoadingPlans(childNavInstruction, loadingPlans);\n }\n }\n }\n\n return loadingPlans;\n};\n\n/**\n * @internal Exported for unit testing\n */\nexport const loadRoute = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n viewPortPlan: ViewPortPlan\n): Promise => {\n let planConfig = viewPortPlan.config;\n let moduleId = planConfig ? planConfig.moduleId : null;\n\n return loadComponent(routeLoader, navigationInstruction, planConfig)\n .then((component) => {\n let viewPortInstruction = navigationInstruction.addViewPortInstruction({\n name: viewPortPlan.name,\n strategy: viewPortPlan.strategy,\n moduleId: moduleId,\n component: component\n }) as ViewPortInstruction;\n\n let childRouter = component.childRouter;\n if (childRouter) {\n let path = navigationInstruction.getWildcardPath();\n\n return childRouter\n ._createNavigationInstruction(path, navigationInstruction)\n .then((childInstruction) => {\n viewPortPlan.childNavigationInstruction = childInstruction;\n\n return _buildNavigationPlan(childInstruction)\n .then((childPlan) => {\n if (childPlan instanceof Redirect) {\n return Promise.reject(childPlan);\n }\n childInstruction.plan = childPlan;\n viewPortInstruction.childNavigationInstruction = childInstruction;\n\n return loadNewRoute(routeLoader, childInstruction);\n });\n });\n }\n // ts complains without this, though they are same\n return void 0;\n });\n};\n\n/**\n * Load a routed-component based on navigation instruction and route config\n * @internal exported for unit testing only\n */\nexport const loadComponent = (\n routeLoader: RouteLoader,\n navigationInstruction: NavigationInstruction,\n config: RouteConfig\n): Promise => {\n let router = navigationInstruction.router;\n let lifecycleArgs = navigationInstruction.lifecycleArgs;\n\n return Promise.resolve()\n .then(() => routeLoader.loadRoute(router, config, navigationInstruction))\n .then(\n /**\n * @param component an object carrying information about loaded route\n * typically contains information about view model, childContainer, view and router\n */\n (component: ViewPortComponent) => {\n let { viewModel, childContainer } = component;\n component.router = router;\n component.config = config;\n\n if ('configureRouter' in viewModel) {\n let childRouter = childContainer.getChildRouter();\n component.childRouter = childRouter;\n\n return childRouter\n .configure(c => viewModel.configureRouter(c, childRouter, lifecycleArgs[0], lifecycleArgs[1], lifecycleArgs[2]))\n .then(() => component);\n }\n\n return component;\n }\n );\n};\n","import { RouteConfig } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { Router } from './router';\n\n/**\n * Abstract class that is responsible for loading view / view model from a route config\n * The default implementation can be found in `aurelia-templating-router`\n */\nexport class RouteLoader {\n /**\n * Load a route config based on its viewmodel / view configuration\n */\n // return typing: return typings used to be never\n // as it was a throw. Changing it to Promise should not cause any issues\n loadRoute(router: Router, config: RouteConfig, navigationInstruction: NavigationInstruction): Promise {\n throw new Error('Route loaders must implement \"loadRoute(router, config, navigationInstruction)\".');\n }\n}\n","import { Next } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { loadNewRoute } from './utilities-route-loading';\nimport { RouteLoader } from './route-loader';\n/**\n * A pipeline step responsible for loading a route config of a navigation instruction\n */\nexport class LoadRouteStep {\n /**@internal */\n static inject() { return [RouteLoader]; }\n /**\n * Route loader isntance that will handle loading route config\n * @internal\n */\n routeLoader: RouteLoader;\n constructor(routeLoader: RouteLoader) {\n this.routeLoader = routeLoader;\n }\n /**\n * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline\n */\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return loadNewRoute(this.routeLoader, navigationInstruction)\n .then(next, next.cancel);\n }\n}\n","import { NavigationInstruction } from './navigation-instruction';\n\n/**\n * A pipeline step for instructing a piepline to commit changes on a navigation instruction\n */\nexport class CommitChangesStep {\n run(navigationInstruction: NavigationInstruction, next: Function): Promise {\n return navigationInstruction\n ._commitChanges(/*wait to swap?*/ true)\n .then(() => {\n navigationInstruction._updateTitle();\n return next();\n });\n }\n}\n","/**\n * An optional interface describing the available activation strategies.\n * @internal Used internally.\n */\nexport const enum InternalActivationStrategy {\n /**\n * Reuse the existing view model, without invoking Router lifecycle hooks.\n */\n NoChange = 'no-change',\n /**\n * Reuse the existing view model, invoking Router lifecycle hooks.\n */\n InvokeLifecycle = 'invoke-lifecycle',\n /**\n * Replace the existing view model, invoking Router lifecycle hooks.\n */\n Replace = 'replace'\n}\n\n/**\n * The strategy to use when activating modules during navigation.\n */\n// kept for compat reason\nexport const activationStrategy: ActivationStrategy = {\n noChange: InternalActivationStrategy.NoChange,\n invokeLifecycle: InternalActivationStrategy.InvokeLifecycle,\n replace: InternalActivationStrategy.Replace\n};\n\n/**\n * An optional interface describing the available activation strategies.\n */\nexport interface ActivationStrategy {\n /**\n * Reuse the existing view model, without invoking Router lifecycle hooks.\n */\n noChange: 'no-change';\n /**\n * Reuse the existing view model, invoking Router lifecycle hooks.\n */\n invokeLifecycle: 'invoke-lifecycle';\n /**\n * Replace the existing view model, invoking Router lifecycle hooks.\n */\n replace: 'replace';\n}\n\n/**\n * Enum like type for activation strategy built-in values\n */\nexport type ActivationStrategyType = ActivationStrategy[keyof ActivationStrategy];\n","import { Next, ViewPortComponent, ViewPortPlan, ViewPortInstruction, LifecycleArguments } from './interfaces';\nimport { isNavigationCommand } from './navigation-commands';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { activationStrategy } from './activation-strategy';\nimport { Router } from './router';\n\n/**\n * Recursively find list of deactivate-able view models\n * and invoke the either 'canDeactivate' or 'deactivate' on each\n * @internal exported for unit testing\n */\nexport const processDeactivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canDeactivate' | 'deactivate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let plan: Record = navigationInstruction.plan;\n let infos = findDeactivatable(plan, callbackName);\n let i = infos.length; // query from inside out\n\n function inspect(val: any): Promise {\n if (ignoreResult || shouldContinue(val)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n if (i--) {\n try {\n let viewModel = infos[i];\n let result = viewModel[callbackName](navigationInstruction);\n return processPotential(result, inspect, next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n navigationInstruction.router.couldDeactivate = true;\n\n return next();\n }\n\n return iterate();\n};\n\n/**\n * Recursively find and returns a list of deactivate-able view models\n * @internal exported for unit testing\n */\nexport const findDeactivatable = (\n plan: Record,\n callbackName: string,\n list: IActivatableInfo[] = []\n): any[] => {\n for (let viewPortName in plan) {\n let viewPortPlan = plan[viewPortName];\n let prevComponent = viewPortPlan.prevComponent;\n\n if ((viewPortPlan.strategy === activationStrategy.invokeLifecycle || viewPortPlan.strategy === activationStrategy.replace)\n && prevComponent\n ) {\n let viewModel = prevComponent.viewModel;\n\n if (callbackName in viewModel) {\n list.push(viewModel);\n }\n }\n\n if (viewPortPlan.strategy === activationStrategy.replace && prevComponent) {\n addPreviousDeactivatable(prevComponent, callbackName, list);\n } else if (viewPortPlan.childNavigationInstruction) {\n findDeactivatable(viewPortPlan.childNavigationInstruction.plan, callbackName, list);\n }\n }\n\n return list;\n};\n\n/**\n * @internal exported for unit testing\n */\nexport const addPreviousDeactivatable = (\n component: ViewPortComponent,\n callbackName: string,\n list: IActivatableInfo[]\n): void => {\n let childRouter = component.childRouter;\n\n if (childRouter && childRouter.currentInstruction) {\n let viewPortInstructions = childRouter.currentInstruction.viewPortInstructions;\n\n for (let viewPortName in viewPortInstructions) {\n let viewPortInstruction = viewPortInstructions[viewPortName];\n let prevComponent = viewPortInstruction.component;\n let prevViewModel = prevComponent.viewModel;\n\n if (callbackName in prevViewModel) {\n list.push(prevViewModel);\n }\n\n addPreviousDeactivatable(prevComponent, callbackName, list);\n }\n }\n};\n\n/**\n * @internal exported for unit testing\n */\nexport const processActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n next: Next,\n ignoreResult?: boolean\n): Promise => {\n let infos = findActivatable(navigationInstruction, callbackName);\n let length = infos.length;\n let i = -1; // query from top down\n\n function inspect(val: any, router: Router): Promise {\n if (ignoreResult || shouldContinue(val, router)) {\n return iterate();\n }\n\n return next.cancel(val);\n }\n\n function iterate(): Promise {\n i++;\n\n if (i < length) {\n try {\n let current = infos[i];\n let result = current.viewModel[callbackName](...current.lifecycleArgs);\n return processPotential(result, (val: any) => inspect(val, current.router), next.cancel);\n } catch (error) {\n return next.cancel(error);\n }\n }\n\n return next();\n }\n\n return iterate();\n};\n\ninterface IActivatableInfo {\n viewModel: any;\n lifecycleArgs: LifecycleArguments;\n router: Router;\n}\n\n/**\n * Find list of activatable view model and add to list (3rd parameter)\n * @internal exported for unit testing\n */\nexport const findActivatable = (\n navigationInstruction: NavigationInstruction,\n callbackName: 'canActivate' | 'activate',\n list: IActivatableInfo[] = [],\n router?: Router\n): IActivatableInfo[] => {\n let plan: Record = navigationInstruction.plan;\n\n Object\n .keys(plan)\n .forEach((viewPortName) => {\n let viewPortPlan = plan[viewPortName];\n let viewPortInstruction = navigationInstruction.viewPortInstructions[viewPortName] as ViewPortInstruction;\n let viewPortComponent = viewPortInstruction.component;\n let viewModel = viewPortComponent.viewModel;\n\n if (\n (viewPortPlan.strategy === activationStrategy.invokeLifecycle\n || viewPortPlan.strategy === activationStrategy.replace\n )\n && callbackName in viewModel\n ) {\n list.push({\n viewModel,\n lifecycleArgs: viewPortInstruction.lifecycleArgs,\n router\n });\n }\n\n let childNavInstruction = viewPortPlan.childNavigationInstruction;\n\n if (childNavInstruction) {\n findActivatable(\n childNavInstruction,\n callbackName,\n list,\n viewPortComponent.childRouter || router\n );\n }\n });\n\n return list;\n};\n\nconst shouldContinue = (output: T, router?: Router): boolean | T => {\n if (output instanceof Error) {\n return false;\n }\n\n if (isNavigationCommand(output)) {\n if (typeof output.setRouter === 'function') {\n output.setRouter(router);\n }\n\n return !!output.shouldContinueProcessing;\n }\n\n if (output === undefined) {\n return true;\n }\n\n return output;\n};\n\n/**\n * A basic interface for an Observable type\n */\nexport interface IObservable {\n subscribe(sub?: IObservableConfig): ISubscription;\n}\n\nexport interface IObservableConfig {\n next(): void;\n error(err?: any): void;\n complete(): void;\n}\n\n/**\n * A basic interface for a Subscription to an Observable\n */\ninterface ISubscription {\n unsubscribe(): void;\n}\n\ntype SafeSubscriptionFunc = (sub: SafeSubscription) => ISubscription;\n\n/**\n * wraps a subscription, allowing unsubscribe calls even if\n * the first value comes synchronously\n */\nclass SafeSubscription {\n\n private _subscribed: boolean;\n private _subscription: ISubscription;\n\n constructor(subscriptionFunc: SafeSubscriptionFunc) {\n this._subscribed = true;\n this._subscription = subscriptionFunc(this);\n\n if (!this._subscribed) {\n this.unsubscribe();\n }\n }\n\n get subscribed(): boolean {\n return this._subscribed;\n }\n\n unsubscribe(): void {\n if (this._subscribed && this._subscription) {\n this._subscription.unsubscribe();\n }\n\n this._subscribed = false;\n }\n}\n\n/**\n * A function to process return value from `activate`/`canActivate` steps\n * Supports observable/promise\n *\n * For observable, resolve at first next() or on complete()\n */\nconst processPotential = (obj: any, resolve: (val?: any) => any, reject: (err?: any) => any): any => {\n // if promise like\n if (obj && typeof obj.then === 'function') {\n return Promise.resolve(obj).then(resolve).catch(reject);\n }\n\n // if observable\n if (obj && typeof obj.subscribe === 'function') {\n let obs: IObservable = obj;\n return new SafeSubscription(sub => obs.subscribe({\n next() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n },\n error(error) {\n if (sub.subscribed) {\n sub.unsubscribe();\n reject(error);\n }\n },\n complete() {\n if (sub.subscribed) {\n sub.unsubscribe();\n resolve(obj);\n }\n }\n }));\n }\n\n // else just resolve\n try {\n return resolve(obj);\n } catch (error) {\n return reject(error);\n }\n};\n","import { Next } from './interfaces';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { processDeactivatable, processActivatable } from './utilities-activation';\n\n/**\n * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route\n */\nexport class CanDeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'canDeactivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route\n */\nexport class CanActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'canActivate', next);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route\n */\nexport class DeactivatePreviousStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processDeactivatable(navigationInstruction, 'deactivate', next, true);\n }\n}\n\n/**\n * A pipeline step responsible for finding and activating method `activate` on a view model of a route\n */\nexport class ActivateNextStep {\n run(navigationInstruction: NavigationInstruction, next: Next): Promise {\n return processActivatable(navigationInstruction, 'activate', next, true);\n }\n}\n","import { Container } from 'aurelia-dependency-injection';\nimport { Pipeline } from './pipeline';\nimport { BuildNavigationPlanStep } from './step-build-navigation-plan';\nimport { LoadRouteStep } from './step-load-route';\nimport { CommitChangesStep } from './step-commit-changes';\nimport { CanDeactivatePreviousStep, CanActivateNextStep, DeactivatePreviousStep, ActivateNextStep } from './step-activation';\nimport { PipelineStep, StepRunnerFunction, IPipelineSlot } from './interfaces';\nimport { PipelineSlotName } from './pipeline-slot-name';\n\n/**\n * A multi-slots Pipeline Placeholder Step for hooking into a pipeline execution\n */\nclass PipelineSlot implements IPipelineSlot {\n\n /**@internal */\n container: Container;\n /**@internal */\n slotName: string;\n /**@internal */\n slotAlias?: string;\n\n steps: (Function | PipelineStep)[] = [];\n\n constructor(container: Container, name: string, alias?: string) {\n this.container = container;\n this.slotName = name;\n this.slotAlias = alias;\n }\n\n getSteps(): (StepRunnerFunction | IPipelineSlot | PipelineStep)[] {\n return this.steps.map(x => this.container.get(x));\n }\n}\n\n/**\n * Class responsible for creating the navigation pipeline.\n */\nexport class PipelineProvider {\n\n /**@internal */\n static inject() { return [Container]; }\n /**@internal */\n container: Container;\n /**@internal */\n steps: (Function | PipelineSlot)[];\n\n constructor(container: Container) {\n this.container = container;\n this.steps = [\n BuildNavigationPlanStep,\n CanDeactivatePreviousStep, // optional\n LoadRouteStep,\n createPipelineSlot(container, PipelineSlotName.Authorize),\n CanActivateNextStep, // optional\n createPipelineSlot(container, PipelineSlotName.PreActivate, 'modelbind'),\n // NOTE: app state changes start below - point of no return\n DeactivatePreviousStep, // optional\n ActivateNextStep, // optional\n createPipelineSlot(container, PipelineSlotName.PreRender, 'precommit'),\n CommitChangesStep,\n createPipelineSlot(container, PipelineSlotName.PostRender, 'postcomplete')\n ];\n }\n\n /**\n * Create the navigation pipeline.\n */\n createPipeline(useCanDeactivateStep: boolean = true): Pipeline {\n let pipeline = new Pipeline();\n this.steps.forEach(step => {\n if (useCanDeactivateStep || step !== CanDeactivatePreviousStep) {\n pipeline.addStep(this.container.get(step));\n }\n });\n return pipeline;\n }\n\n /**@internal */\n _findStep(name: string): PipelineSlot {\n // Steps that are not PipelineSlots are constructor functions, and they will automatically fail. Probably.\n return this.steps.find(x => (x as PipelineSlot).slotName === name || (x as PipelineSlot).slotAlias === name) as PipelineSlot;\n }\n\n /**\n * Adds a step into the pipeline at a known slot location.\n */\n addStep(name: string, step: PipelineStep | Function): void {\n let found = this._findStep(name);\n if (found) {\n let slotSteps = found.steps;\n // prevent duplicates\n if (!slotSteps.includes(step)) {\n slotSteps.push(step);\n }\n } else {\n throw new Error(`Invalid pipeline slot name: ${name}.`);\n }\n }\n\n /**\n * Removes a step from a slot in the pipeline\n */\n removeStep(name: string, step: PipelineStep): void {\n let slot = this._findStep(name);\n if (slot) {\n let slotSteps = slot.steps;\n slotSteps.splice(slotSteps.indexOf(step), 1);\n }\n }\n\n /**\n * Clears all steps from a slot in the pipeline\n * @internal\n */\n _clearSteps(name: string = ''): void {\n let slot = this._findStep(name);\n if (slot) {\n slot.steps = [];\n }\n }\n\n /**\n * Resets all pipeline slots\n */\n reset(): void {\n this._clearSteps(PipelineSlotName.Authorize);\n this._clearSteps(PipelineSlotName.PreActivate);\n this._clearSteps(PipelineSlotName.PreRender);\n this._clearSteps(PipelineSlotName.PostRender);\n }\n}\n\n/**@internal */\nconst createPipelineSlot = (container: Container, name: PipelineSlotName, alias?: string): PipelineSlot => {\n return new PipelineSlot(container, name, alias);\n};\n","import * as LogManager from 'aurelia-logging';\nimport { Container } from 'aurelia-dependency-injection';\nimport { History, NavigationOptions } from 'aurelia-history';\nimport { Router } from './router';\nimport { PipelineProvider } from './pipeline-provider';\nimport { isNavigationCommand } from './navigation-commands';\nimport { EventAggregator } from 'aurelia-event-aggregator';\nimport { NavigationInstruction } from './navigation-instruction';\nimport { ViewPort, ConfiguresRouter, PipelineResult } from './interfaces';\nimport { RouterEvent } from './router-event';\n\n/**@internal */\ndeclare module 'aurelia-dependency-injection' {\n interface Container {\n viewModel?: any;\n }\n}\n\nconst logger = LogManager.getLogger('app-router');\n\n/**\n * The main application router.\n */\nexport class AppRouter extends Router {\n\n /**@internal */\n static inject() { return [Container, History, PipelineProvider, EventAggregator]; }\n\n events: EventAggregator;\n /**@internal */\n maxInstructionCount: number;\n /**@internal */\n _queue: NavigationInstruction[];\n /**@internal */\n isActive: boolean;\n\n constructor(container: Container, history: History, pipelineProvider: PipelineProvider, events: EventAggregator) {\n super(container, history); // Note the super will call reset internally.\n this.pipelineProvider = pipelineProvider;\n this.events = events;\n }\n\n /**\n * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.\n * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.\n */\n reset(): void {\n super.reset();\n this.maxInstructionCount = 10;\n if (!this._queue) {\n this._queue = [];\n } else {\n this._queue.length = 0;\n }\n }\n\n /**\n * Loads the specified URL.\n *\n * @param url The URL fragment to load.\n */\n loadUrl(url: string): Promise {\n return this\n ._createNavigationInstruction(url)\n .then(instruction => this._queueInstruction(instruction))\n .catch(error => {\n logger.error(error);\n restorePreviousLocation(this);\n });\n }\n\n /**\n * Registers a viewPort to be used as a rendering target for activated routes.\n *\n * @param viewPort The viewPort. This is typically a element in Aurelia default impl\n * @param name The name of the viewPort. 'default' if unspecified.\n */\n registerViewPort(viewPort: /*ViewPort*/ any, name?: string): Promise {\n // having strong typing without changing public API\n const $viewPort: ViewPort = viewPort;\n super.registerViewPort($viewPort, name);\n\n // beside adding viewport to the registry of this instance\n // AppRouter also configure routing/history to start routing functionality\n // There are situation where there are more than 1 element at root view\n // in that case, still only activate once via the following guard\n if (!this.isActive) {\n const viewModel = this._findViewModel($viewPort);\n if ('configureRouter' in viewModel) {\n // If there are more than one element at root view\n // use this flag to guard against configure method being invoked multiple times\n // this flag is set inside method configure\n if (!this.isConfigured) {\n // replace the real resolve with a noop to guarantee that any action in base class Router\n // won't resolve the configurePromise prematurely\n const resolveConfiguredPromise = this._resolveConfiguredPromise;\n this._resolveConfiguredPromise = () => {/**/};\n return this\n .configure(config => {\n viewModel.configureRouter(config, this);\n return config;\n })\n .then(() => {\n this.activate();\n resolveConfiguredPromise();\n });\n }\n } else {\n this.activate();\n }\n }\n // when a viewport is added dynamically to a root view that is already activated\n // just process the navigation instruction\n else {\n this._dequeueInstruction();\n }\n\n return Promise.resolve();\n }\n\n /**\n * Activates the router. This instructs the router to begin listening for history changes and processing instructions.\n *\n * @params options The set of options to activate the router with.\n */\n activate(options?: NavigationOptions): void {\n if (this.isActive) {\n return;\n }\n\n this.isActive = true;\n // route handler property is responsible for handling url change\n // the interface of aurelia-history isn't clear on this perspective\n this.options = Object.assign({ routeHandler: this.loadUrl.bind(this) }, this.options, options);\n this.history.activate(this.options);\n this._dequeueInstruction();\n }\n\n /**\n * Deactivates the router.\n */\n deactivate(): void {\n this.isActive = false;\n this.history.deactivate();\n }\n\n /**@internal */\n _queueInstruction(instruction: NavigationInstruction): Promise {\n return new Promise((resolve) => {\n instruction.resolve = resolve;\n this._queue.unshift(instruction);\n this._dequeueInstruction();\n });\n }\n\n /**@internal */\n _dequeueInstruction(instructionCount: number = 0): Promise {\n return Promise.resolve().then(() => {\n if (this.isNavigating && !instructionCount) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n let instruction = this._queue.shift();\n this._queue.length = 0;\n\n if (!instruction) {\n // ts complains about inconsistent returns without void 0\n return void 0;\n }\n\n this.isNavigating = true;\n\n let navtracker: number = this.history.getState('NavigationTracker');\n let currentNavTracker = this.currentNavigationTracker;\n\n if (!navtracker && !currentNavTracker) {\n this.isNavigatingFirst = true;\n this.isNavigatingNew = true;\n } else if (!navtracker) {\n this.isNavigatingNew = true;\n } else if (!currentNavTracker) {\n this.isNavigatingRefresh = true;\n } else if (currentNavTracker < navtracker) {\n this.isNavigatingForward = true;\n } else if (currentNavTracker > navtracker) {\n this.isNavigatingBack = true;\n } if (!navtracker) {\n navtracker = Date.now();\n this.history.setState('NavigationTracker', navtracker);\n }\n this.currentNavigationTracker = navtracker;\n\n instruction.previousInstruction = this.currentInstruction;\n\n let maxInstructionCount = this.maxInstructionCount;\n\n if (!instructionCount) {\n this.events.publish(RouterEvent.Processing, { instruction });\n } else if (instructionCount === maxInstructionCount - 1) {\n logger.error(`${instructionCount + 1} navigation instructions have been attempted without success. Restoring last known good location.`);\n restorePreviousLocation(this);\n return this._dequeueInstruction(instructionCount + 1);\n } else if (instructionCount > maxInstructionCount) {\n throw new Error('Maximum navigation attempts exceeded. Giving up.');\n }\n\n let pipeline = this.pipelineProvider.createPipeline(!this.couldDeactivate);\n\n return pipeline\n .run(instruction)\n .then(result => processResult(instruction, result, instructionCount, this))\n .catch(error => {\n return { output: error instanceof Error ? error : new Error(error) } as PipelineResult;\n })\n .then(result => resolveInstruction(instruction, result, !!instructionCount, this));\n });\n }\n\n /**@internal */\n _findViewModel(viewPort: ViewPort): ConfiguresRouter | undefined {\n if (this.container.viewModel) {\n return this.container.viewModel;\n }\n\n if (viewPort.container) {\n let container = viewPort.container;\n\n while (container) {\n if (container.viewModel) {\n this.container.viewModel = container.viewModel;\n return container.viewModel;\n }\n\n container = container.parent;\n }\n }\n\n return undefined;\n }\n}\n\nconst processResult = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n instructionCount: number,\n router: AppRouter\n): Promise => {\n if (!(result && 'completed' in result && 'output' in result)) {\n result = result || {} as PipelineResult;\n result.output = new Error(`Expected router pipeline to return a navigation result, but got [${JSON.stringify(result)}] instead.`);\n }\n\n let finalResult: PipelineResult = null;\n let navigationCommandResult = null;\n if (isNavigationCommand(result.output)) {\n navigationCommandResult = result.output.navigate(router);\n } else {\n finalResult = result;\n\n if (!result.completed) {\n if (result.output instanceof Error) {\n logger.error(result.output.toString());\n }\n\n restorePreviousLocation(router);\n }\n }\n\n return Promise.resolve(navigationCommandResult)\n .then(_ => router._dequeueInstruction(instructionCount + 1))\n .then(innerResult => finalResult || innerResult || result);\n};\n\nconst resolveInstruction = (\n instruction: NavigationInstruction,\n result: PipelineResult,\n isInnerInstruction: boolean,\n router: AppRouter\n): PipelineResult => {\n instruction.resolve(result);\n\n let eventAggregator = router.events;\n let eventArgs = { instruction, result };\n if (!isInnerInstruction) {\n router.isNavigating = false;\n router.isExplicitNavigation = false;\n router.isExplicitNavigationBack = false;\n router.isNavigatingFirst = false;\n router.isNavigatingNew = false;\n router.isNavigatingRefresh = false;\n router.isNavigatingForward = false;\n router.isNavigatingBack = false;\n router.couldDeactivate = false;\n\n let eventName: string;\n\n if (result.output instanceof Error) {\n eventName = RouterEvent.Error;\n } else if (!result.completed) {\n eventName = RouterEvent.Canceled;\n } else {\n let queryString = instruction.queryString ? ('?' + instruction.queryString) : '';\n router.history.previousLocation = instruction.fragment + queryString;\n eventName = RouterEvent.Success;\n }\n\n eventAggregator.publish(eventName, eventArgs);\n eventAggregator.publish(RouterEvent.Complete, eventArgs);\n } else {\n eventAggregator.publish(RouterEvent.ChildComplete, eventArgs);\n }\n\n return result;\n};\n\nconst restorePreviousLocation = (router: AppRouter): void => {\n let previousLocation = router.history.previousLocation;\n if (previousLocation) {\n router.navigate(previousLocation, { trigger: false, replace: true });\n } else if (router.fallbackRoute) {\n router.navigate(router.fallbackRoute, { trigger: true, replace: true });\n } else {\n logger.error('Router navigation failed, and no previous location or fallbackRoute could be restored.');\n }\n};\n","/**\n* The status of a Pipeline.\n*/\nexport const enum PipelineStatus {\n Completed = 'completed',\n Canceled = 'canceled',\n Rejected = 'rejected',\n Running = 'running'\n}\n","/**\n * A list of known router events used by the Aurelia router\n * to signal the pipeline has come to a certain state\n */\n// const enum is preserved in tsconfig\nexport const enum RouterEvent {\n Processing = 'router:navigation:processing',\n Error = 'router:navigation:error',\n Canceled = 'router:navigation:canceled',\n Complete = 'router:navigation:complete',\n Success = 'router:navigation:success',\n ChildComplete = 'router:navigation:child:complete'\n}\n","/**\n * Available pipeline slot names to insert interceptor into router pipeline\n */\n// const enum is preserved in tsconfig\nexport const enum PipelineSlotName {\n /**\n * Authorization slot. Invoked early in the pipeline,\n * before `canActivate` hook of incoming route\n */\n Authorize = 'authorize',\n /**\n * Pre-activation slot. Invoked early in the pipeline,\n * Invoked timing:\n * - after Authorization slot\n * - after canActivate hook on new view model\n * - before deactivate hook on old view model\n * - before activate hook on new view model\n */\n PreActivate = 'preActivate',\n /**\n * Pre-render slot. Invoked later in the pipeline\n * Invokcation timing:\n * - after activate hook on new view model\n * - before commit step on new navigation instruction\n */\n PreRender = 'preRender',\n /**\n * Post-render slot. Invoked last in the pipeline\n */\n PostRender = 'postRender'\n}\n"],"names":["LogManager.getLogger","tslib_1.__extends"],"mappings":";;;;;;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