Skip to content

Commit

Permalink
Swap historyState for params in exec. also error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwasner committed Apr 14, 2016
1 parent 8372241 commit d0c7dfd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/mvc/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var Router = Disposable.extend(function(viewManager){
* @method exec
*
* @param {String} url The URL
* @param {Object} state A history record object
* @param {Object} params Additional parameters to pass to the route
* @return {Promise} A promise
*/
/**
Expand All @@ -140,6 +140,9 @@ var Router = Disposable.extend(function(viewManager){
* @return {Promise} A promise
*/
exec(url, state, params) {
if(state && !params){
state = params;
}
if (this.locked) {
return Promise.reject('locked');
} else {
Expand Down Expand Up @@ -179,11 +182,11 @@ var Router = Disposable.extend(function(viewManager){
}
if(checkAuth && failUrl !== url && !ignoreAuth){
return func().then(
() => _executeIfRouteExists.call(this, url, state, params),
() => _executeIfRouteExists.call(this, failUrl, state, params));
() => _executeIfRouteExists.call(this, url, state, params),
() => _executeIfRouteExists.call(this, failUrl, state, params)).catch(url=>_rejectionMessage(url));
}
else{
return _executeIfRouteExists.call(this, url, state, params);
return _executeIfRouteExists.call(this, url, state, params).catch(url=>_rejectionMessage(url));;
}

},
Expand Down Expand Up @@ -270,7 +273,7 @@ let _executeIfRouteExists = function(url, state, params) {
}

if (!route) {
return Promise.reject([url, state]);
return Promise.reject(url);
}
return Promise.resolve()
.then(() => route.exec(url, this, this.viewManager, state, params))
Expand All @@ -281,6 +284,7 @@ let _executeIfRouteExists = function(url, state, params) {
throw err;
});
}
let _rejectionMessage = (url)=>console.error('Unable to find a route for ' + url);

let singletonRouter = new Router();
export default singletonRouter;

0 comments on commit d0c7dfd

Please sign in to comment.