最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Backbone.history.start with a specific fragment - Stack Overflow

programmeradmin1浏览0评论

I want to start my Backbone router at a specific action sometimes, different than the one that was navigated to. How can I change it so that when I call Backbone.history.start it goes to a specific action/fragment other than the one in the URL?

Backbone.history.start
  pushState: true
  root: "/"

Maybe there's some option, or maybe there's a way for me to change the fragment before making that function call?

Thanks!

I want to start my Backbone router at a specific action sometimes, different than the one that was navigated to. How can I change it so that when I call Backbone.history.start it goes to a specific action/fragment other than the one in the URL?

Backbone.history.start
  pushState: true
  root: "/"

Maybe there's some option, or maybe there's a way for me to change the fragment before making that function call?

Thanks!

Share Improve this question asked Oct 18, 2013 at 21:06 GarrettGarrett 11.7k20 gold badges86 silver badges129 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Just pass "silent" option and than call "navigate":

Backbone.history.start({ silent: true });
router.navigate('test', { trigger: true });

In this case hash that was before you called Backbone.history.start will be ignored. Hash will be changed to 'test' and the same route function will be called.

The Backbone.history.navigate will navigate to the route in the first argument, if the second argument is true, it will also trigger the route function.

Backbone.history.navigate('users/sam', true);
发布评论

评论列表(0)

  1. 暂无评论