1

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');
     }

});
Lorraine Bernard
  • 13,000
  • 23
  • 82
  • 134

2 Answers2

3

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.

Tallmaris
  • 7,605
  • 3
  • 28
  • 58
0

You must have "global" variable with a Router instance.

Then just call that variable in this way:

// yourRouter was defined in your main controller like this: 
// var YourRouterClass = Backbone.Router.extend({ 
// stuff of your own Router
// });
// var yourRouter = new YourRouterClass(); <- this is your global router instance
yourRouter.navigate('tasks/'+this.model.get('id'), {trigger : true});
Daniel Aranda
  • 6,426
  • 2
  • 21
  • 28