根据
Backbone.js页面:
Until recently,hash fragments (#page) were used to provide these
permalinks,but with the arrival of the History API,it’s now
possible to use standard URLs (/page).
我试图添加此路由器规则:
- routes: {
- 'test': function() {
- alert('ok'); }
- }
并称为Backbone.history.start({pushState:true,root:’/ myroot /’}).我的页面中有一个链接:
- <a href="test">test me</a>
我截获了链接的点击事件:
- $('a[href=test]').click(function(e) {
- router.navigate('test');
- e.preventDefault(); });
当我点击链接时,没有发出请求,我相信拦截成功了.但事件并未触发.
所以,请帮助我了解这个History API的工作原理.或指出我做错了什么.
解决方法
你需要打开pushState:
Backbone.history.start({pushState:true});
您的链接将强制从您的服务器完全刷新,您的服务器必须使用该URL的内容进行响应.
myRouter.navigate( “测试”);
有关HTML5历史记录api:http://diveintohtml5.info/history.html的更多信息
有关使用带有Backbone的pushState的一些介绍级别信息:
我给出的演示视频涵盖了所有这些:
希望有所帮助.