4

I have built a web app using backbone.marionette. When, from a Marionette.ItemView, I trigger the event document.location.hash:

 document.location.hash = '#tasks/' + this.model.get('id');

1.a) it changes the URL 1.b) it triggers the appRoutes

If I trigger the Routing.navigate from the same place:

router.navigate('#tasks/' + this.model.get('id'))

2.a) it changes the URL as expected 2.b) it does not trigger the appRoutes.

Any idea why 2.b happens? Where could the issue be?

Thanks.

var Router = Marionette.AppRouter.extend({
    appRoutes: {
        'tasks': 'tasks',
        'tasks/:id': 'taskDetail',
        '*defaults': 'tasks'
    }
});
dda
  • 6,030
  • 2
  • 25
  • 34
Lorraine Bernard
  • 13,000
  • 23
  • 82
  • 134

1 Answers1

9

You need to add {trigger: true}

router.navigate('#tasks/' + this.model.get('id'), {trigger: true})

Generally I extend the router and then add my own navigate that automatically adds that {trigger: true}. I understand why the developers did it like that, but it isn't the way I've ever used it :)

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Stephen
  • 5,362
  • 1
  • 22
  • 33
  • Thanks, actually this question is related to this one: [Circular Dependencies for a web app using backbone.marionette and requireJs](http://stackoverflow.com/questions/11265332/circular-dependencies-for-a-web-app-using-backbone-marionette-and-requirejs). And I would like to know how can I reach the same goal raising events. – Lorraine Bernard Jun 30 '12 at 08:31