Routing.navigate vs document.location.hash

I created a web application using backbone.marionette . When from Marionette.ItemView I fire the document.location.hash event:

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

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

If I call 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 call appRoutes.

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

Thanks.

 var Router = Marionette.AppRouter.extend({ appRoutes: { 'tasks': 'tasks', 'tasks/:id': 'taskDetail', '*defaults': 'tasks' } }); 
+4
source share
1 answer

You need to add {trigger: true}

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

As a rule, I expand the router and then add my own transition, which automatically adds this {trigger: true} . I understand why the developers did it this way, but it is not the way I ever used it :)

+9
source

All Articles