From 1187b6ce8f2e07acc2b221044f5dade1ad4cd3c7 Mon Sep 17 00:00:00 2001 From: EisenbergEffect Date: Mon, 16 Jul 2018 22:11:56 -0700 Subject: [PATCH] chore(all): prepare release 1.6.2 --- bower.json | 2 +- dist/amd/aurelia-router.js | 64 ++++++++++++++++--------- dist/aurelia-router.js | 69 +++++++++++++++++---------- dist/commonjs/aurelia-router.js | 64 ++++++++++++++++--------- dist/es2015/aurelia-router.js | 46 +++++++++++++----- dist/native-modules/aurelia-router.js | 66 ++++++++++++++++--------- dist/system/aurelia-router.js | 67 +++++++++++++++++--------- doc/CHANGELOG.md | 12 +++++ package.json | 2 +- 9 files changed, 263 insertions(+), 129 deletions(-) diff --git a/bower.json b/bower.json index a8ec7c0e..7845e567 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-router", - "version": "1.6.1", + "version": "1.6.2", "description": "A powerful client-side router.", "keywords": [ "aurelia", diff --git a/dist/amd/aurelia-router.js b/dist/amd/aurelia-router.js index cc67a13e..ccf11205 100644 --- a/dist/amd/aurelia-router.js +++ b/dist/amd/aurelia-router.js @@ -279,7 +279,6 @@ define(['exports', 'aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depen this.config.navModel.isActive = true; - router._refreshBaseUrl(); router.refreshNavigation(); var loads = []; @@ -677,7 +676,19 @@ define(['exports', 'aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depen if ('redirect' in config) { var _router = instruction.router; return _router._createNavigationInstruction(config.redirect).then(function (newInstruction) { - var params = Object.keys(newInstruction.params).length ? instruction.params : {}; + var params = {}; + for (var _key2 in newInstruction.params) { + var val = newInstruction.params[_key2]; + if (typeof val === 'string' && val[0] === ':') { + val = val.slice(1); + + if (val in instruction.params) { + params[_key2] = instruction.params[val]; + } + } else { + params[_key2] = newInstruction.params[_key2]; + } + } var redirectLocation = _router.generate(newInstruction.config.name, params, instruction.options); if (instruction.queryString) { @@ -770,22 +781,22 @@ define(['exports', 'aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depen var nextParams = next.params; var nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; - for (var _key2 in nextParams) { - if (_key2 === nextWildCardName) { + for (var _key3 in nextParams) { + if (_key3 === nextWildCardName) { continue; } - if (prevParams[_key2] !== nextParams[_key2]) { + if (prevParams[_key3] !== nextParams[_key3]) { return true; } } - for (var _key3 in prevParams) { - if (_key3 === nextWildCardName) { + for (var _key4 in prevParams) { + if (_key4 === nextWildCardName) { continue; } - if (prevParams[_key3] !== nextParams[_key3]) { + if (prevParams[_key4] !== nextParams[_key4]) { return true; } } @@ -796,14 +807,14 @@ define(['exports', 'aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depen var prevQueryParams = prev.queryParams; var nextQueryParams = next.queryParams; - for (var _key4 in nextQueryParams) { - if (prevQueryParams[_key4] !== nextQueryParams[_key4]) { + for (var _key5 in nextQueryParams) { + if (prevQueryParams[_key5] !== nextQueryParams[_key5]) { return true; } } - for (var _key5 in prevQueryParams) { - if (prevQueryParams[_key5] !== nextQueryParams[_key5]) { + for (var _key6 in prevQueryParams) { + if (prevQueryParams[_key6] !== nextQueryParams[_key6]) { return true; } } @@ -921,7 +932,7 @@ define(['exports', 'aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depen var hasRoute = this._recognizer.hasRoute(name); if ((!this.isConfigured || !hasRoute) && this.parent) { - return this.parent.generate(name, params); + return this.parent.generate(name, params, options); } if (!hasRoute) { @@ -1069,8 +1080,7 @@ define(['exports', 'aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depen Router.prototype._refreshBaseUrl = function _refreshBaseUrl() { if (this.parent) { - var baseUrl = this.parent.currentInstruction.getBaseUrl(); - this.baseUrl = this.parent.baseUrl + baseUrl; + this.baseUrl = generateBaseUrl(this.parent, this.parent.currentInstruction); } }; @@ -1104,6 +1114,8 @@ define(['exports', 'aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depen } }; + var result = void 0; + if (results && results.length) { var first = results[0]; var _instruction = new NavigationInstruction(Object.assign({}, instructionInit, { @@ -1113,19 +1125,19 @@ define(['exports', 'aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depen })); if (typeof first.handler === 'function') { - return evaluateNavigationStrategy(_instruction, first.handler, first); + result = evaluateNavigationStrategy(_instruction, first.handler, first); } else if (first.handler && typeof first.handler.navigationStrategy === 'function') { - return evaluateNavigationStrategy(_instruction, first.handler.navigationStrategy, first.handler); + result = evaluateNavigationStrategy(_instruction, first.handler.navigationStrategy, first.handler); + } else { + result = Promise.resolve(_instruction); } - - return Promise.resolve(_instruction); } else if (this.catchAllHandler) { var _instruction2 = new NavigationInstruction(Object.assign({}, instructionInit, { params: { path: fragment }, queryParams: results ? results.queryParams : {}, config: null })); - return evaluateNavigationStrategy(_instruction2, this.catchAllHandler); + result = evaluateNavigationStrategy(_instruction2, this.catchAllHandler); } else if (this.parent) { var _router2 = this._parentCatchAllHandler(this.parent); @@ -1140,11 +1152,15 @@ define(['exports', 'aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depen parentCatchHandler: true, config: null })); - return evaluateNavigationStrategy(_instruction3, _router2.catchAllHandler); + result = evaluateNavigationStrategy(_instruction3, _router2.catchAllHandler); } } - return Promise.reject(new Error('Route not found: ' + url)); + if (result && parentInstruction) { + this.baseUrl = generateBaseUrl(this.parent, parentInstruction); + } + + return result || Promise.reject(new Error('Route not found: ' + url)); }; Router.prototype._findParentInstructionFromRouter = function _findParentInstructionFromRouter(router, instruction) { @@ -1201,6 +1217,10 @@ define(['exports', 'aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depen return Router; }(); + function generateBaseUrl(router, instruction) { + return '' + (router.baseUrl || '') + (instruction.getBaseUrl() || ''); + } + function validateRouteConfig(config, routes) { if ((typeof config === 'undefined' ? 'undefined' : _typeof(config)) !== 'object') { throw new Error('Invalid Route Config'); diff --git a/dist/aurelia-router.js b/dist/aurelia-router.js index 0804c3f4..4c62870e 100644 --- a/dist/aurelia-router.js +++ b/dist/aurelia-router.js @@ -1,7 +1,7 @@ import * as LogManager from 'aurelia-logging'; import {RouteRecognizer} from 'aurelia-route-recognizer'; import {Container} from 'aurelia-dependency-injection'; -import {History} from 'aurelia-history'; +import {History,NavigationOptions} from 'aurelia-history'; import {EventAggregator} from 'aurelia-event-aggregator'; export function _normalizeAbsolutePath(path, hasPushState, absolute = false) { @@ -267,7 +267,6 @@ export class NavigationInstruction { this.config.navModel.isActive = true; - router._refreshBaseUrl(); router.refreshNavigation(); let loads = []; @@ -1057,16 +1056,29 @@ export function _buildNavigationPlan(instruction: NavigationInstruction, forceLi if ('redirect' in config) { let router = instruction.router; return router._createNavigationInstruction(config.redirect) - .then(newInstruction => { - let params = Object.keys(newInstruction.params).length ? instruction.params : {}; - let redirectLocation = router.generate(newInstruction.config.name, params, instruction.options); + .then(newInstruction => { + let 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]; + } + } else { + params[key] = newInstruction.params[key]; + } + } + let redirectLocation = router.generate(newInstruction.config.name, params, instruction.options); - if (instruction.queryString) { - redirectLocation += '?' + instruction.queryString; - } + if (instruction.queryString) { + redirectLocation += '?' + instruction.queryString; + } - return Promise.resolve(new Redirect(redirectLocation)); - }); + return Promise.resolve(new Redirect(redirectLocation)); + }); } let prev = instruction.previousInstruction; @@ -1393,9 +1405,9 @@ export class Router { * Navigates to a new location. * * @param fragment The URL fragment to use as the navigation destination. - * @param options The navigation options. See [[History.NavigationOptions]] for all available options. + * @param options The navigation options. */ - navigate(fragment: string, options?: any): NavigationResult { + navigate(fragment: string, options?: NavigationOptions): NavigationResult { if (!this.isConfigured && this.parent) { return this.parent.navigate(fragment, options); } @@ -1410,9 +1422,9 @@ export class Router { * * @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. See [[History.NavigationOptions]] for all available options. + * @param options The navigation options. */ - navigateToRoute(route: string, params?: any, options?: any): NavigationResult { + navigateToRoute(route: string, params?: any, options?: NavigationOptions): NavigationResult { let path = this.generate(route, params); return this.navigate(path, options); } @@ -1448,7 +1460,7 @@ export class Router { generate(name: string, params?: any, options?: any = {}): string { let hasRoute = this._recognizer.hasRoute(name); if ((!this.isConfigured || !hasRoute) && this.parent) { - return this.parent.generate(name, params); + return this.parent.generate(name, params, options); } if (!hasRoute) { @@ -1631,8 +1643,7 @@ export class Router { _refreshBaseUrl(): void { if (this.parent) { - let baseUrl = this.parent.currentInstruction.getBaseUrl(); - this.baseUrl = this.parent.baseUrl + baseUrl; + this.baseUrl = generateBaseUrl(this.parent, this.parent.currentInstruction); } } @@ -1663,6 +1674,8 @@ export class Router { } }; + let result; + if (results && results.length) { let first = results[0]; let instruction = new NavigationInstruction(Object.assign({}, instructionInit, { @@ -1672,12 +1685,12 @@ export class Router { })); if (typeof first.handler === 'function') { - return evaluateNavigationStrategy(instruction, first.handler, first); + result = evaluateNavigationStrategy(instruction, first.handler, first); } else if (first.handler && typeof first.handler.navigationStrategy === 'function') { - return evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); + result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); + } else { + result = Promise.resolve(instruction); } - - return Promise.resolve(instruction); } else if (this.catchAllHandler) { let instruction = new NavigationInstruction(Object.assign({}, instructionInit, { params: { path: fragment }, @@ -1685,7 +1698,7 @@ export class Router { config: null // config will be created by the catchAllHandler })); - return evaluateNavigationStrategy(instruction, this.catchAllHandler); + result = evaluateNavigationStrategy(instruction, this.catchAllHandler); } else if (this.parent) { let router = this._parentCatchAllHandler(this.parent); @@ -1701,11 +1714,15 @@ export class Router { config: null // config will be created by the chained parent catchAllHandler })); - return evaluateNavigationStrategy(instruction, router.catchAllHandler); + result = evaluateNavigationStrategy(instruction, router.catchAllHandler); } } - return Promise.reject(new Error(`Route not found: ${url}`)); + if (result && parentInstruction) { + this.baseUrl = generateBaseUrl(this.parent, parentInstruction); + } + + return result || Promise.reject(new Error(`Route not found: ${url}`)); } _findParentInstructionFromRouter(router: Router, instruction: NavigationInstruction): NavigationInstruction { @@ -1752,6 +1769,10 @@ export class Router { } } +function generateBaseUrl(router: Router, instruction: NavigationInstruction) { + return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`; +} + function validateRouteConfig(config: RouteConfig, routes: Array): void { if (typeof config !== 'object') { throw new Error('Invalid Route Config'); diff --git a/dist/commonjs/aurelia-router.js b/dist/commonjs/aurelia-router.js index 1a9f4c50..4c74e0b6 100644 --- a/dist/commonjs/aurelia-router.js +++ b/dist/commonjs/aurelia-router.js @@ -234,7 +234,6 @@ var NavigationInstruction = exports.NavigationInstruction = function () { this.config.navModel.isActive = true; - router._refreshBaseUrl(); router.refreshNavigation(); var loads = []; @@ -632,7 +631,19 @@ function _buildNavigationPlan(instruction, forceLifecycleMinimum) { if ('redirect' in config) { var _router = instruction.router; return _router._createNavigationInstruction(config.redirect).then(function (newInstruction) { - var params = Object.keys(newInstruction.params).length ? instruction.params : {}; + var params = {}; + for (var _key2 in newInstruction.params) { + var val = newInstruction.params[_key2]; + if (typeof val === 'string' && val[0] === ':') { + val = val.slice(1); + + if (val in instruction.params) { + params[_key2] = instruction.params[val]; + } + } else { + params[_key2] = newInstruction.params[_key2]; + } + } var redirectLocation = _router.generate(newInstruction.config.name, params, instruction.options); if (instruction.queryString) { @@ -725,22 +736,22 @@ function hasDifferentParameterValues(prev, next) { var nextParams = next.params; var nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; - for (var _key2 in nextParams) { - if (_key2 === nextWildCardName) { + for (var _key3 in nextParams) { + if (_key3 === nextWildCardName) { continue; } - if (prevParams[_key2] !== nextParams[_key2]) { + if (prevParams[_key3] !== nextParams[_key3]) { return true; } } - for (var _key3 in prevParams) { - if (_key3 === nextWildCardName) { + for (var _key4 in prevParams) { + if (_key4 === nextWildCardName) { continue; } - if (prevParams[_key3] !== nextParams[_key3]) { + if (prevParams[_key4] !== nextParams[_key4]) { return true; } } @@ -751,14 +762,14 @@ function hasDifferentParameterValues(prev, next) { var prevQueryParams = prev.queryParams; var nextQueryParams = next.queryParams; - for (var _key4 in nextQueryParams) { - if (prevQueryParams[_key4] !== nextQueryParams[_key4]) { + for (var _key5 in nextQueryParams) { + if (prevQueryParams[_key5] !== nextQueryParams[_key5]) { return true; } } - for (var _key5 in prevQueryParams) { - if (prevQueryParams[_key5] !== nextQueryParams[_key5]) { + for (var _key6 in prevQueryParams) { + if (prevQueryParams[_key6] !== nextQueryParams[_key6]) { return true; } } @@ -876,7 +887,7 @@ var Router = exports.Router = function () { var hasRoute = this._recognizer.hasRoute(name); if ((!this.isConfigured || !hasRoute) && this.parent) { - return this.parent.generate(name, params); + return this.parent.generate(name, params, options); } if (!hasRoute) { @@ -1024,8 +1035,7 @@ var Router = exports.Router = function () { Router.prototype._refreshBaseUrl = function _refreshBaseUrl() { if (this.parent) { - var baseUrl = this.parent.currentInstruction.getBaseUrl(); - this.baseUrl = this.parent.baseUrl + baseUrl; + this.baseUrl = generateBaseUrl(this.parent, this.parent.currentInstruction); } }; @@ -1059,6 +1069,8 @@ var Router = exports.Router = function () { } }; + var result = void 0; + if (results && results.length) { var first = results[0]; var _instruction = new NavigationInstruction(Object.assign({}, instructionInit, { @@ -1068,19 +1080,19 @@ var Router = exports.Router = function () { })); if (typeof first.handler === 'function') { - return evaluateNavigationStrategy(_instruction, first.handler, first); + result = evaluateNavigationStrategy(_instruction, first.handler, first); } else if (first.handler && typeof first.handler.navigationStrategy === 'function') { - return evaluateNavigationStrategy(_instruction, first.handler.navigationStrategy, first.handler); + result = evaluateNavigationStrategy(_instruction, first.handler.navigationStrategy, first.handler); + } else { + result = Promise.resolve(_instruction); } - - return Promise.resolve(_instruction); } else if (this.catchAllHandler) { var _instruction2 = new NavigationInstruction(Object.assign({}, instructionInit, { params: { path: fragment }, queryParams: results ? results.queryParams : {}, config: null })); - return evaluateNavigationStrategy(_instruction2, this.catchAllHandler); + result = evaluateNavigationStrategy(_instruction2, this.catchAllHandler); } else if (this.parent) { var _router2 = this._parentCatchAllHandler(this.parent); @@ -1095,11 +1107,15 @@ var Router = exports.Router = function () { parentCatchHandler: true, config: null })); - return evaluateNavigationStrategy(_instruction3, _router2.catchAllHandler); + result = evaluateNavigationStrategy(_instruction3, _router2.catchAllHandler); } } - return Promise.reject(new Error('Route not found: ' + url)); + if (result && parentInstruction) { + this.baseUrl = generateBaseUrl(this.parent, parentInstruction); + } + + return result || Promise.reject(new Error('Route not found: ' + url)); }; Router.prototype._findParentInstructionFromRouter = function _findParentInstructionFromRouter(router, instruction) { @@ -1156,6 +1172,10 @@ var Router = exports.Router = function () { return Router; }(); +function generateBaseUrl(router, instruction) { + return '' + (router.baseUrl || '') + (instruction.getBaseUrl() || ''); +} + function validateRouteConfig(config, routes) { if ((typeof config === 'undefined' ? 'undefined' : _typeof(config)) !== 'object') { throw new Error('Invalid Route Config'); diff --git a/dist/es2015/aurelia-router.js b/dist/es2015/aurelia-router.js index 10aed4d6..f4039af5 100644 --- a/dist/es2015/aurelia-router.js +++ b/dist/es2015/aurelia-router.js @@ -1,7 +1,7 @@ import * as LogManager from 'aurelia-logging'; import { RouteRecognizer } from 'aurelia-route-recognizer'; import { Container } from 'aurelia-dependency-injection'; -import { History } from 'aurelia-history'; +import { History, NavigationOptions } from 'aurelia-history'; import { EventAggregator } from 'aurelia-event-aggregator'; export function _normalizeAbsolutePath(path, hasPushState, absolute = false) { @@ -185,7 +185,6 @@ export let NavigationInstruction = class NavigationInstruction { this.config.navModel.isActive = true; - router._refreshBaseUrl(); router.refreshNavigation(); let loads = []; @@ -538,7 +537,19 @@ export function _buildNavigationPlan(instruction, forceLifecycleMinimum) { if ('redirect' in config) { let router = instruction.router; return router._createNavigationInstruction(config.redirect).then(newInstruction => { - let params = Object.keys(newInstruction.params).length ? instruction.params : {}; + let params = {}; + for (let key in newInstruction.params) { + let val = newInstruction.params[key]; + if (typeof val === 'string' && val[0] === ':') { + val = val.slice(1); + + if (val in instruction.params) { + params[key] = instruction.params[val]; + } + } else { + params[key] = newInstruction.params[key]; + } + } let redirectLocation = router.generate(newInstruction.config.name, params, instruction.options); if (instruction.queryString) { @@ -768,7 +779,7 @@ export let Router = class Router { generate(name, params, options = {}) { let hasRoute = this._recognizer.hasRoute(name); if ((!this.isConfigured || !hasRoute) && this.parent) { - return this.parent.generate(name, params); + return this.parent.generate(name, params, options); } if (!hasRoute) { @@ -912,8 +923,7 @@ export let Router = class Router { _refreshBaseUrl() { if (this.parent) { - let baseUrl = this.parent.currentInstruction.getBaseUrl(); - this.baseUrl = this.parent.baseUrl + baseUrl; + this.baseUrl = generateBaseUrl(this.parent, this.parent.currentInstruction); } } @@ -944,6 +954,8 @@ export let Router = class Router { } }; + let result; + if (results && results.length) { let first = results[0]; let instruction = new NavigationInstruction(Object.assign({}, instructionInit, { @@ -953,19 +965,19 @@ export let Router = class Router { })); if (typeof first.handler === 'function') { - return evaluateNavigationStrategy(instruction, first.handler, first); + result = evaluateNavigationStrategy(instruction, first.handler, first); } else if (first.handler && typeof first.handler.navigationStrategy === 'function') { - return evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); + result = evaluateNavigationStrategy(instruction, first.handler.navigationStrategy, first.handler); + } else { + result = Promise.resolve(instruction); } - - return Promise.resolve(instruction); } else if (this.catchAllHandler) { let instruction = new NavigationInstruction(Object.assign({}, instructionInit, { params: { path: fragment }, queryParams: results ? results.queryParams : {}, config: null })); - return evaluateNavigationStrategy(instruction, this.catchAllHandler); + result = evaluateNavigationStrategy(instruction, this.catchAllHandler); } else if (this.parent) { let router = this._parentCatchAllHandler(this.parent); @@ -980,11 +992,15 @@ export let Router = class Router { parentCatchHandler: true, config: null })); - return evaluateNavigationStrategy(instruction, router.catchAllHandler); + result = evaluateNavigationStrategy(instruction, router.catchAllHandler); } } - return Promise.reject(new Error(`Route not found: ${url}`)); + if (result && parentInstruction) { + this.baseUrl = generateBaseUrl(this.parent, parentInstruction); + } + + return result || Promise.reject(new Error(`Route not found: ${url}`)); } _findParentInstructionFromRouter(router, instruction) { @@ -1028,6 +1044,10 @@ export let Router = class Router { } }; +function generateBaseUrl(router, instruction) { + return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`; +} + function validateRouteConfig(config, routes) { if (typeof config !== 'object') { throw new Error('Invalid Route Config'); diff --git a/dist/native-modules/aurelia-router.js b/dist/native-modules/aurelia-router.js index a3a74039..9899a053 100644 --- a/dist/native-modules/aurelia-router.js +++ b/dist/native-modules/aurelia-router.js @@ -11,7 +11,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" import * as LogManager from 'aurelia-logging'; import { RouteRecognizer } from 'aurelia-route-recognizer'; import { Container } from 'aurelia-dependency-injection'; -import { History } from 'aurelia-history'; +import { History, NavigationOptions } from 'aurelia-history'; import { EventAggregator } from 'aurelia-event-aggregator'; export function _normalizeAbsolutePath(path, hasPushState) { @@ -212,7 +212,6 @@ export var NavigationInstruction = function () { this.config.navModel.isActive = true; - router._refreshBaseUrl(); router.refreshNavigation(); var loads = []; @@ -610,7 +609,19 @@ export function _buildNavigationPlan(instruction, forceLifecycleMinimum) { if ('redirect' in config) { var _router = instruction.router; return _router._createNavigationInstruction(config.redirect).then(function (newInstruction) { - var params = Object.keys(newInstruction.params).length ? instruction.params : {}; + var params = {}; + for (var _key2 in newInstruction.params) { + var val = newInstruction.params[_key2]; + if (typeof val === 'string' && val[0] === ':') { + val = val.slice(1); + + if (val in instruction.params) { + params[_key2] = instruction.params[val]; + } + } else { + params[_key2] = newInstruction.params[_key2]; + } + } var redirectLocation = _router.generate(newInstruction.config.name, params, instruction.options); if (instruction.queryString) { @@ -703,22 +714,22 @@ function hasDifferentParameterValues(prev, next) { var nextParams = next.params; var nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; - for (var _key2 in nextParams) { - if (_key2 === nextWildCardName) { + for (var _key3 in nextParams) { + if (_key3 === nextWildCardName) { continue; } - if (prevParams[_key2] !== nextParams[_key2]) { + if (prevParams[_key3] !== nextParams[_key3]) { return true; } } - for (var _key3 in prevParams) { - if (_key3 === nextWildCardName) { + for (var _key4 in prevParams) { + if (_key4 === nextWildCardName) { continue; } - if (prevParams[_key3] !== nextParams[_key3]) { + if (prevParams[_key4] !== nextParams[_key4]) { return true; } } @@ -729,14 +740,14 @@ function hasDifferentParameterValues(prev, next) { var prevQueryParams = prev.queryParams; var nextQueryParams = next.queryParams; - for (var _key4 in nextQueryParams) { - if (prevQueryParams[_key4] !== nextQueryParams[_key4]) { + for (var _key5 in nextQueryParams) { + if (prevQueryParams[_key5] !== nextQueryParams[_key5]) { return true; } } - for (var _key5 in prevQueryParams) { - if (prevQueryParams[_key5] !== nextQueryParams[_key5]) { + for (var _key6 in prevQueryParams) { + if (prevQueryParams[_key6] !== nextQueryParams[_key6]) { return true; } } @@ -854,7 +865,7 @@ export var Router = function () { var hasRoute = this._recognizer.hasRoute(name); if ((!this.isConfigured || !hasRoute) && this.parent) { - return this.parent.generate(name, params); + return this.parent.generate(name, params, options); } if (!hasRoute) { @@ -1002,8 +1013,7 @@ export var Router = function () { Router.prototype._refreshBaseUrl = function _refreshBaseUrl() { if (this.parent) { - var baseUrl = this.parent.currentInstruction.getBaseUrl(); - this.baseUrl = this.parent.baseUrl + baseUrl; + this.baseUrl = generateBaseUrl(this.parent, this.parent.currentInstruction); } }; @@ -1037,6 +1047,8 @@ export var Router = function () { } }; + var result = void 0; + if (results && results.length) { var first = results[0]; var _instruction = new NavigationInstruction(Object.assign({}, instructionInit, { @@ -1046,19 +1058,19 @@ export var Router = function () { })); if (typeof first.handler === 'function') { - return evaluateNavigationStrategy(_instruction, first.handler, first); + result = evaluateNavigationStrategy(_instruction, first.handler, first); } else if (first.handler && typeof first.handler.navigationStrategy === 'function') { - return evaluateNavigationStrategy(_instruction, first.handler.navigationStrategy, first.handler); + result = evaluateNavigationStrategy(_instruction, first.handler.navigationStrategy, first.handler); + } else { + result = Promise.resolve(_instruction); } - - return Promise.resolve(_instruction); } else if (this.catchAllHandler) { var _instruction2 = new NavigationInstruction(Object.assign({}, instructionInit, { params: { path: fragment }, queryParams: results ? results.queryParams : {}, config: null })); - return evaluateNavigationStrategy(_instruction2, this.catchAllHandler); + result = evaluateNavigationStrategy(_instruction2, this.catchAllHandler); } else if (this.parent) { var _router2 = this._parentCatchAllHandler(this.parent); @@ -1073,11 +1085,15 @@ export var Router = function () { parentCatchHandler: true, config: null })); - return evaluateNavigationStrategy(_instruction3, _router2.catchAllHandler); + result = evaluateNavigationStrategy(_instruction3, _router2.catchAllHandler); } } - return Promise.reject(new Error('Route not found: ' + url)); + if (result && parentInstruction) { + this.baseUrl = generateBaseUrl(this.parent, parentInstruction); + } + + return result || Promise.reject(new Error('Route not found: ' + url)); }; Router.prototype._findParentInstructionFromRouter = function _findParentInstructionFromRouter(router, instruction) { @@ -1134,6 +1150,10 @@ export var Router = function () { return Router; }(); +function generateBaseUrl(router, instruction) { + return '' + (router.baseUrl || '') + (instruction.getBaseUrl() || ''); +} + function validateRouteConfig(config, routes) { if ((typeof config === 'undefined' ? 'undefined' : _typeof(config)) !== 'object') { throw new Error('Invalid Route Config'); diff --git a/dist/system/aurelia-router.js b/dist/system/aurelia-router.js index 54b8c38d..f7c7176a 100644 --- a/dist/system/aurelia-router.js +++ b/dist/system/aurelia-router.js @@ -3,7 +3,7 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-dependency-injection', 'aurelia-history', 'aurelia-event-aggregator'], function (_export, _context) { "use strict"; - var LogManager, RouteRecognizer, Container, History, EventAggregator, _typeof, _createClass, isRootedPath, isAbsoluteUrl, CommitChangesStep, NavigationInstruction, NavModel, Redirect, RedirectToRoute, pipelineStatus, Pipeline, RouterConfiguration, activationStrategy, BuildNavigationPlanStep, Router, CanDeactivatePreviousStep, CanActivateNextStep, DeactivatePreviousStep, ActivateNextStep, SafeSubscription, RouteLoader, LoadRouteStep, PipelineSlot, PipelineProvider, logger, AppRouter; + var LogManager, RouteRecognizer, Container, History, NavigationOptions, EventAggregator, _typeof, _createClass, isRootedPath, isAbsoluteUrl, CommitChangesStep, NavigationInstruction, NavModel, Redirect, RedirectToRoute, pipelineStatus, Pipeline, RouterConfiguration, activationStrategy, BuildNavigationPlanStep, Router, CanDeactivatePreviousStep, CanActivateNextStep, DeactivatePreviousStep, ActivateNextStep, SafeSubscription, RouteLoader, LoadRouteStep, PipelineSlot, PipelineProvider, logger, AppRouter; function _possibleConstructorReturn(self, call) { if (!self) { @@ -124,7 +124,19 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depende if ('redirect' in config) { var _router = instruction.router; return _router._createNavigationInstruction(config.redirect).then(function (newInstruction) { - var params = Object.keys(newInstruction.params).length ? instruction.params : {}; + var params = {}; + for (var _key2 in newInstruction.params) { + var val = newInstruction.params[_key2]; + if (typeof val === 'string' && val[0] === ':') { + val = val.slice(1); + + if (val in instruction.params) { + params[_key2] = instruction.params[val]; + } + } else { + params[_key2] = newInstruction.params[_key2]; + } + } var redirectLocation = _router.generate(newInstruction.config.name, params, instruction.options); if (instruction.queryString) { @@ -219,22 +231,22 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depende var nextParams = next.params; var nextWildCardName = next.config.hasChildRouter ? next.getWildCardName() : null; - for (var _key2 in nextParams) { - if (_key2 === nextWildCardName) { + for (var _key3 in nextParams) { + if (_key3 === nextWildCardName) { continue; } - if (prevParams[_key2] !== nextParams[_key2]) { + if (prevParams[_key3] !== nextParams[_key3]) { return true; } } - for (var _key3 in prevParams) { - if (_key3 === nextWildCardName) { + for (var _key4 in prevParams) { + if (_key4 === nextWildCardName) { continue; } - if (prevParams[_key3] !== nextParams[_key3]) { + if (prevParams[_key4] !== nextParams[_key4]) { return true; } } @@ -245,14 +257,14 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depende var prevQueryParams = prev.queryParams; var nextQueryParams = next.queryParams; - for (var _key4 in nextQueryParams) { - if (prevQueryParams[_key4] !== nextQueryParams[_key4]) { + for (var _key5 in nextQueryParams) { + if (prevQueryParams[_key5] !== nextQueryParams[_key5]) { return true; } } - for (var _key5 in prevQueryParams) { - if (prevQueryParams[_key5] !== nextQueryParams[_key5]) { + for (var _key6 in prevQueryParams) { + if (prevQueryParams[_key6] !== nextQueryParams[_key6]) { return true; } } @@ -260,6 +272,10 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depende return false; } + function generateBaseUrl(router, instruction) { + return '' + (router.baseUrl || '') + (instruction.getBaseUrl() || ''); + } + function validateRouteConfig(config, routes) { if ((typeof config === 'undefined' ? 'undefined' : _typeof(config)) !== 'object') { throw new Error('Invalid Route Config'); @@ -659,6 +675,7 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depende Container = _aureliaDependencyInjection.Container; }, function (_aureliaHistory) { History = _aureliaHistory.History; + NavigationOptions = _aureliaHistory.NavigationOptions; }, function (_aureliaEventAggregator) { EventAggregator = _aureliaEventAggregator.EventAggregator; }], @@ -825,7 +842,6 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depende this.config.navModel.isActive = true; - router._refreshBaseUrl(); router.refreshNavigation(); var loads = []; @@ -1330,7 +1346,7 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depende var hasRoute = this._recognizer.hasRoute(name); if ((!this.isConfigured || !hasRoute) && this.parent) { - return this.parent.generate(name, params); + return this.parent.generate(name, params, options); } if (!hasRoute) { @@ -1478,8 +1494,7 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depende Router.prototype._refreshBaseUrl = function _refreshBaseUrl() { if (this.parent) { - var baseUrl = this.parent.currentInstruction.getBaseUrl(); - this.baseUrl = this.parent.baseUrl + baseUrl; + this.baseUrl = generateBaseUrl(this.parent, this.parent.currentInstruction); } }; @@ -1513,6 +1528,8 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depende } }; + var result = void 0; + if (results && results.length) { var first = results[0]; var _instruction = new NavigationInstruction(Object.assign({}, instructionInit, { @@ -1522,19 +1539,19 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depende })); if (typeof first.handler === 'function') { - return evaluateNavigationStrategy(_instruction, first.handler, first); + result = evaluateNavigationStrategy(_instruction, first.handler, first); } else if (first.handler && typeof first.handler.navigationStrategy === 'function') { - return evaluateNavigationStrategy(_instruction, first.handler.navigationStrategy, first.handler); + result = evaluateNavigationStrategy(_instruction, first.handler.navigationStrategy, first.handler); + } else { + result = Promise.resolve(_instruction); } - - return Promise.resolve(_instruction); } else if (this.catchAllHandler) { var _instruction2 = new NavigationInstruction(Object.assign({}, instructionInit, { params: { path: fragment }, queryParams: results ? results.queryParams : {}, config: null })); - return evaluateNavigationStrategy(_instruction2, this.catchAllHandler); + result = evaluateNavigationStrategy(_instruction2, this.catchAllHandler); } else if (this.parent) { var _router2 = this._parentCatchAllHandler(this.parent); @@ -1549,11 +1566,15 @@ System.register(['aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depende parentCatchHandler: true, config: null })); - return evaluateNavigationStrategy(_instruction3, _router2.catchAllHandler); + result = evaluateNavigationStrategy(_instruction3, _router2.catchAllHandler); } } - return Promise.reject(new Error('Route not found: ' + url)); + if (result && parentInstruction) { + this.baseUrl = generateBaseUrl(this.parent, parentInstruction); + } + + return result || Promise.reject(new Error('Route not found: ' + url)); }; Router.prototype._findParentInstructionFromRouter = function _findParentInstructionFromRouter(router, instruction) { diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 806cd9d7..a8fc2fb5 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,15 @@ + +## [1.6.2](https://github.com/aurelia/router/compare/1.6.1...1.6.2) (2018-07-17) + + +### Bug Fixes + +* **navigation-plan:** Accept parameters in a redirect config ([7172ed2](https://github.com/aurelia/router/commit/7172ed2)), closes [#607](https://github.com/aurelia/router/issues/607) +* Forward options argument to parent router.generate ([78aad40](https://github.com/aurelia/router/commit/78aad40)), closes [#606](https://github.com/aurelia/router/issues/606) +* Update baseUrl when creating a navigation instruction ([e801550](https://github.com/aurelia/router/commit/e801550)), closes [#378](https://github.com/aurelia/router/issues/378) [#605](https://github.com/aurelia/router/issues/605) + + + ## [1.6.1](https://github.com/aurelia/router/compare/1.6.0...1.6.1) (2018-06-19) diff --git a/package.json b/package.json index e9712b43..eac1e997 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-router", - "version": "1.6.1", + "version": "1.6.2", "description": "A powerful client-side router.", "keywords": [ "aurelia",