diff --git a/lib/cloak/router.js b/lib/cloak/router.js index 201d70b..acbd2d8 100644 --- a/lib/cloak/router.js +++ b/lib/cloak/router.js @@ -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; } @@ -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; } @@ -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; } });