Skip to content

Commit

Permalink
corrected bug in subrouter references
Browse files Browse the repository at this point in the history
  • Loading branch information
kbjr committed May 20, 2014
1 parent 21d08b5 commit 6b830b8
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions lib/cloak/router.js
Expand Up @@ -271,8 +271,12 @@ var Router = module.exports = AppObject.extend({
};

// If the currently tracked url is the one we're already on, emit an event and move on
if (state.hash === this._currentUrl) {
this.emit('reload', this._currentRoute.params, this._currentRoute.href, data);
if (state.hash === this.topLevel._currentUrl) {
if (this._currentRoute) {
var params = this._currentRoute.params;
var href = this._currentRoute.href;
}
this.emit('reload', params, href, data);
return true;
}

Expand All @@ -286,8 +290,11 @@ var Router = module.exports = AppObject.extend({

// Handle unrecognized routes
if (! this._currentRoute) {
this.emit('notfound', state);
return this._deferToSubRouters();
if (! this._deferToSubRouters()) {
this.emit('notfound', state);
return false;
}
return true;
}


Expand All @@ -301,9 +308,20 @@ var Router = module.exports = AppObject.extend({
// @return void
//
_deferToSubRouters: function() {
return !! _.find(this._subRouters, function(subRouter) {
var temp = this._currentUrl;
this._currentUrl = null;

var sub = _.find(this._subRouters, function(subRouter) {
return subRouter._onstatechange();
});

this._currentUrl = temp;

if (sub) {
this._currentRoute = sub._currentRoute;
}

return !! sub;
}

});
Expand Down

0 comments on commit 6b830b8

Please sign in to comment.