A note about routing conflicts

Whichever method you use to create your routes, you should be careful to avoid defining the same route twice or defining two routes that overlap each other, such as foo and splatThatCouldBeFoo. While Backbone will allow you to define such routes and will continue working fine in spite of them, it will silently ignore any routes after the first that match. Take an example of the following code snippet:

new Backbone.Router({
    routes: {
        'foo': function() {alert('bar')},
        ':splatThatCouldBeFoo': function() {alert('baz')},
    }
}) 
Backbone.history.start();
// navigating to #foo alerts('bar')

One could take advantage of this behavior by deliberately defining specific routes, and then less specific overlapping routes, but this is not generally recommended. While a few simple overlapping routes are unlikely to cause problems, if you have too many they can make your Router difficult to work with. When you have such overlapping routes you have to first stop and understand every route involved before you can make changes to any of them, and then if you make a mistake it's all to easy to create a difficult to find bug.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.153.224