Search code examples
backbone.jsbackbone-routing

Hash and backbone router


How should I make this using Router?

var itemView = Marionette.ItemView.extend({

     events: {
         'click #loadPage': 'loadPage'
     },

     loadPage: function () {
         document.location.hash = '#tasks/' + this.model.get('id');
     }

});

Solution

  • As per documentation, router.navigate is simply proxying to Backbone.history, which is global so you should be able to use it without problems:

    Backbone.history.navigate("#tasks/", { trigger: true })
    

    the {trigger: true} options as expected will trigger the hash change so that your router can react if it has that route registered.