Showing posts with label router. Show all posts
Showing posts with label router. Show all posts

Thursday, June 19, 2014

Cleanup Events With Backbone Routers

Backbone routers allow you to listen to route events. These are triggered when one of the defined paths in the router matches the URL. For example, the paths of your application can be statically defined and named in the routes object. The route events triggered by the router use the route name — route:home, or route:help. What's nice about this is that different components can subscribe to router events. This means I don't have to define all my route handling code in one place — each component of my application is able to encapsulate it's own routing logic. One piece of the puzzle that's missing is cleaning up my views once the route that created them is no longer active.

Tuesday, January 21, 2014

Scalable Routing With Backbone

The typical Backbone application, at least the demo applications you'll find, use a single router instance to manage URLs. That's fine because where there are only a handful of possible URLs the application understands, creating more than one router instance is overkill. What I find strange, however, are the lack of examples that use multiple routers. Backbone exposes the router as a component to be extended and instantiated. It's by no means a singleton.