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'
}
});
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'
}
});
Share
Improve this question
edited Jun 30, 2012 at 9:14
dda
6,2132 gold badges27 silver badges35 bronze badges
asked Jun 30, 2012 at 8:24
Lorraine BernardLorraine Bernard
13.4k23 gold badges85 silver badges138 bronze badges
1 Answer
Reset to default 9You 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 :)