O'Reilly logo

Building Scalable Apps with Redis and Node.js by Joshua Johanan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Backbone router

Backbone has one more feature we will use. This is routing. A Backbone router will listen for hash changes in the URL and this will trigger events. The router can be configured to match certain patterns and even pull out parameters. Let's create the router, as shown in the following code:

var Router = Backbone.Router.extend({
  routes: {
    '': 'RoomSelection',
    'room/:room' : 'JoinRoom',
    '*default' : 'Default'
  }
});

Routers are built the same way as other Backbone objects; we extend the base router. The Router object really only needs a routes object that has patterns as the properties and the event name as the value. Routers allow the back button and deep linking to work in a single-page JavaScript application, just like the chat ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required