documentcloud/backbone — Issue #810: pushState and multiple roots
Author: joelhegg
Created: 2011-12-23 20:13:15+00:00
State: open

I have an existing Backbone app with multiple routers. I want to turn on pushState, but this only allows for a single, global root. I really need independent roots for each router.

For example, let's say we have SearchRouter with a route ":query" that without pushState you would access like: "/search/#foo". We also have CategoriesRouter with a route ":categoryId" that you would access like "/categories/#1234". With pushState enabled these would become "/search/foo" and "/categories/1234".

I initially tried setting the root to "/search/" and SearchRouter worked fine, but CategoriesRouter obviously did not.

It looks like the only other knob I can turn is to make "search/" and "categories/" part of their respective routes. This is fairly drastic though because it changes the semantics of our fragments and will break existing bookmarks.

What's the best solution for this? Would it make sense to add an optional prefix to router? This would be concatenated between root and frag in Backbone.history.navigate().