documentcloud/backbone — pull request #760 by sebpiq (2011-11-24 16:05:03+00:00)
Title: Router that is hidden from History

For complex routing purposes, I have found it handy to use several routers. But in the current backbone version, multiple routers generally don't integrate well together, because they compete with each other.

This patch brings very small modifications to Backbone.Router. Router accepts an option `discreet`, which makes it unknown to History, and therefore deaf to hashchanges.

Now a disclaimer : I have started using backbone quite recently, so my suggestion might be complete stupidity and in that case please help me get back on the right track !

1 - This allows, if you have complicated routes, to nest routers in the following way :

```javascript
var MapRouter = Backbone.Router.extend({
discreet: true,
routes: {
"banana/:id": "showBanana",
"pear/:id": showPear,
// ...
}
//, ...
});
var mapRouter = new MapRouter();

var SearchRouter = Backbone.Router.extend({
discreet: true,
routes: {
"banana/:query",
"pear/:query"
// ...
}
//, ...
});
var searchRouter = new SearchRouter();

var MainRouter = Backbone.Router.extend({
routes: {
"map/*fragment": "delegateToMapRouter",
"search/*fragment": "delegateToSearchRouter"
// ...
},
delegateToMapRouter: function(fragment) {
mapRouter.navigate(fragment, true);
},
delegateToSearchRouter: function(fragment) {
searchRouter.navigate(fragment, true);
},
//...
});
```

2 - In my case, I need to store a complex state e.g. `search/banana/green//map/apple/1`, which I split in a main router, and dispatch to slave routers (which are "discreet" and not tied to history). That's a bit hackish, but it was to illustrate the flexibility having discreet router brings.

This guy had a similar need :

https://github.com/documentcloud/backbone/issues/455