backbone: router.navigate doesn't call router unless hash is changed
I’m trying to use URLs without hashbangs which is causing some grief.
As I test I did this.
<a href="#" onclick="router.navigate('/albums/<%= album.id %>', true); return false;">Show</a>
The URL is updated but my router isn’t called. At first I thought the route didn’t match but if I refresh the page the route is successfully matched.
Then I tried this:
<a href="#" onclick="router.navigate('/albums/<%= album.id %>', true);">Show</a>
And everything works just fine, seems like the router is only called if a hashchange is triggered.
About this issue
- Original URL
- State: closed
- Created 13 years ago
- Comments: 22 (5 by maintainers)
Ran into this issue today and would just like to add my 2 cents:
Seems like un-intuitive behavior that when explicitly setting
trigger: trueit won’t trigger the event unless the hash has changed.My vote is in favor of
trigger: truetriggering the route no matter the condition.One real world example is when you want to refresh the current page you are on, that would be impossible to do with the current behavior of
trigger: true.This is indeed an interesting behavior of
router.navigate()that I’ve run into before when trying to force a route to reload. Here’s what I ended up doing:That’s not explictly documented as part of the API, but it certainly gets the job done. Seems reasonable to me that
router.navigate( 'current/path', true )should trigger the route handler to be called again.Anyone else care to chime in on this?
Works if I remove the inital / Guess it must be an exact match to your routes
I have spent 3 hours trying to find why the
roter.navigate()method did not work on my application. I think, BB docs should include a notification about this issue.My ugly but quick solution was to call a
router.navigate()method before the actual one.For now, it worked. But if there was a
refresh:trueoption, I would definitely use it…