Trigger same location route

2019-02-04 09:32发布

Is there a way to trigger same location route in backbone.js, for example when location is /My/App/#/About and user clicks again on anchor with the same route in order to refresh the page content.

8条回答
Lonely孤独者°
2楼-- · 2019-02-04 10:34

Using Backbone 0.9.2 you pass in an options object and set 'trigger' to 'true'.

router.navigate('some/route', { trigger : true });

Reference: http://documentcloud.github.com/backbone/#Router-navigate

查看更多
你好瞎i
3楼-- · 2019-02-04 10:37
Backbone.history.loadUrl(Backbone.history.fragment);

The solution for your specific problem isn't really documented and it seems the suggested best practice is to just call the function that is declared in the route you want to fire :/

Ref: https://github.com/documentcloud/backbone/issues/1214

So far the other answers are correct, but they forgot to mention that if the hash navigated to is the same as the current hash, nothing will fire.

查看更多
登录 后发表回答