根据
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的一些介绍级别信息:
我给出的演示视频涵盖了所有这些:
希望有所帮助.
原文地址:https://www.jb51.cc/js/159804.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。