Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add newest route to the start of the handlers array rather than the end #189

Closed
pieterv opened this issue Jan 15, 2011 · 2 comments
Closed

Comments

@pieterv
Copy link

pieterv commented Jan 15, 2011

It would be nice if Backbone.History.route() added new routes to the start of the handlers array (unshift) rather than the end (push). This would allow you to override previously set routes and allow the following application logic to work.

pdv.Controllers.App = Backbone.Controller.extend({

initialize: function(options) {
    // create App model, collection, view
    this.route('*path', 'all', this.checkPath);

},

createPath: function(stub) {
    this.getData(stub, function(data) {
            // Create model and add to collection

            // Add callback directly to model
            this.route(data.stub, data.stub, function() {
                // execute logic to show page
                model.set({showPage: true})
            });
    });
},

getData: function(stub, callback) {
      // Get data from server
    if (data) {
        callback.call(this, data);
    } else {
        // show 404 page
    }
}

});
@jashkenas
Copy link
Owner

Thanks for the idea -- calling route() should definitely allow you to override previously-defined routes. I've patched Backbone at ac8c3dd, give it a spin and let me know what you think.

@pieterv
Copy link
Author

pieterv commented Feb 7, 2011

The update looks perfect, i have had my local version of backbone patched like this for some time and have not encountered any issues with it.

jasonwebster pushed a commit to jasonwebster/backbone that referenced this issue May 13, 2011
… maps are the same, procedural route() calls can now override previously-defined routes.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants