如何禁用骨干的历史,但仍然允许基于散列的路由? [英] How do I disable backbone history but still allow hash-based routing?
问题描述
说我做到以下几点:
- 点击主页上的(/)的链接,然后转到/职位/ 1
- 触发一个事件,并转到骨干路由/职位/ 1 /#/ 1 /修改
- 我单击后退
我需要让用户在主页(/)最终回,使其不回/职位/ 1
I need to make it so that the user ends up back on the homepage (/) not back at /posts/1
所以,我需要允许骨干哈希路线工作,但不能修改的历史。
我个人preFER保持的历史,但它是一个项目的要求。
So I need to allow for backbone hash routes to work but not modify the history. I'd personally prefer to keep the history, but it's a requirement of a project.
推荐答案
骨干网(0.9.x版本)的最新版本已触发的路线,而不是将其添加到历史的能力。
The latest version of Backbone (0.9.x) has the ability to trigger a route, but not add it to the history.
请参阅 Backbone.Router#导航以替换:true选项
See Backbone.Router#navigate for the replace:true option.
基本上,只要拨打.navigate你的路由器上触发:真(火的路线),并替代:真(以prevent它会历史)
Basically, just call .navigate on your router with trigger:true (to fire the route) and replace:true (to prevent it going to history)
app.navigate('posts/1/edit',{trigger:true, replace: true});
下面是显示在行动它的jsfiddle: http://jsfiddle.net/7Z6ju/1/
Here's a jsfiddle showing it in action: http://jsfiddle.net/7Z6ju/1/
- 单击发布1转到帖子第1页。
- 然后,单击编辑去
编辑页面。 - 然后,点击后退按钮 - 你应该结束了回
家中。
这篇关于如何禁用骨干的历史,但仍然允许基于散列的路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!