backbone.marionette.subrouter
backbone.marionette.subrouter copied to clipboard
route cleanup on subrouter destruct
I have multiple modules in a project where every module has its own subrouter. I want to be able to load/unload modules with their subrouter. At the moment routes only get added but not removed. Even worse: If I instantiate a subrouter, delete it and instantiate it again I end up with the same route-handler multiple times in Backbone.history.routes
.
We should add a cleanup function or something to remove routes from the history if a subrouter gets destroyed! I'll look into it.
I just added this function to the SubRouter:
cleanUp: function() {
_.each(this.appRoutes, function(key, route) {
Backbone.history.handlers = _.reject(Backbone.history.handlers, function(handler) {
return String(handler.route).localeCompare(Backbone.Router.prototype._routeToRegExp(route)) === 0;
});
}, this);
}
This feels realy dirty! Maybe somebody got a better idea how to solve this?