Skip to content

Commit

Permalink
chore(all): prepare release 1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Jul 17, 2018
1 parent a59f13e commit 1187b6c
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 129 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurelia-router",
"version": "1.6.1",
"version": "1.6.2",
"description": "A powerful client-side router.",
"keywords": [
"aurelia",
Expand Down
64 changes: 42 additions & 22 deletions dist/amd/aurelia-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ define(['exports', 'aurelia-logging', 'aurelia-route-recognizer', 'aurelia-depen

this.config.navModel.isActive = true;

router._refreshBaseUrl();
router.refreshNavigation();

var loads = [];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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, {
Expand All @@ -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);

Expand All @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down
69 changes: 45 additions & 24 deletions dist/aurelia-router.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -267,7 +267,6 @@ export class NavigationInstruction {

this.config.navModel.isActive = true;

router._refreshBaseUrl();
router.refreshNavigation();

let loads = [];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -1663,6 +1674,8 @@ export class Router {
}
};

let result;

if (results && results.length) {
let first = results[0];
let instruction = new NavigationInstruction(Object.assign({}, instructionInit, {
Expand All @@ -1672,20 +1685,20 @@ 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 },
queryParams: results ? results.queryParams : {},
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);

Expand All @@ -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 {
Expand Down Expand Up @@ -1752,6 +1769,10 @@ export class Router {
}
}

function generateBaseUrl(router: Router, instruction: NavigationInstruction) {
return `${router.baseUrl || ''}${instruction.getBaseUrl() || ''}`;
}

function validateRouteConfig(config: RouteConfig, routes: Array<Object>): void {
if (typeof config !== 'object') {
throw new Error('Invalid Route Config');
Expand Down
Loading

0 comments on commit 1187b6c

Please sign in to comment.