骨干路由器听者不打散列标签 [英] Backbone router listener not hitting hash tag
问题描述
我的问题是,当我在一个链接中使用一个散列标签,它只是附加的哈希的URL,而不是去的路线。例如 /ToDo/public/offline2.html#test
。如果我离开了标签=
它进入路由器的某些原因。
我已经关闭了jQuery移动路由器具有以下code
<脚本类型=文/ JavaScript的>
(文档)$ .bind(mobileinit功能(){
$ .mobile.ajaxEnabled = FALSE;
$ .mobile.linkBindingEnabled = FALSE;
$ .mobile.hashListeningEnabled = FALSE;
$ .mobile.pushStateEnabled = FALSE;
$ .mobile.changePage.defaults.changeHash = FALSE;
});< / SCRIPT>< SCRIPT SRC =../ JS / jquery.mobile.js>< / SCRIPT>
< SCRIPT SRC =../的js / jquery.js和>< / SCRIPT>
如何我的html code是非常基本的。
< P>去到< A HREF =#测试ID =#测试>测试页< / A>< / P>
所以我有一个包含在JavaScript code单独的js文件说,文件test.js.这是主要的code
$(app.init)app.init =功能(){
的console.log('开始初始化) 路由器=新TestRouter();
的console.log('端INIT')
}
VAR TestRouter = Backbone.Router.extend({
路线:{
:家,
测试:测试
}, 初始化:功能(){风险自=这
_.bindAll(个体经营)},
家庭:功能(){
警报(名);
// $ .mobile.changePage($('#家页'){changeHash:假});
}, 测试:函数(名称){
警报(名);
// $ .mobile.changePage($('#测试页面'){changeHash:假});
}
})
正如我所说的code适用于家庭,当我设置这样的标签
< A HREF =数据图标=家>家庭和LT; / A>
您需要调用Backbone.history.start()之前骨干将开始监测hashchange事件。
app.init =功能(){
的console.log('开始初始化) 路由器=新TestRouter();
Backbone.history.start();
的console.log('端INIT')
}
My problem is that when I use a hash tag in a link, it just attaches the hash to the url rather than going to the route. For example /ToDo/public/offline2.html#test
. If I leave the tag = ""
it does go to the router for some reason.
I have turned off the jquery mobile router with following code
<script type="text/javascript">
$(document).bind("mobileinit", function () {
$.mobile.ajaxEnabled = false;
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
$.mobile.changePage.defaults.changeHash = false;
});
</script>
<script src="../js/jquery.mobile.js"></script>
<script src="../js/jquery.js"></script>
How my html code is very basic
<p>go to <a href="#test" id="#test">test page</a></p>
So I have a separate js file containing the javascript code in say file test.js. this is the main code
$(app.init)
app.init = function() {
console.log('start init')
router = new TestRouter();
console.log('end init')
}
var TestRouter = Backbone.Router.extend({
routes:{
"":"home",
"test":"test"
},
initialize: function(){ var self = this
_.bindAll(self) },
home: function(){
alert(name);
// $.mobile.changePage($('#home-page'), {changeHash:false});
},
test: function (name) {
alert(name);
// $.mobile.changePage($('#test-page'), {changeHash:false});
}
})
As I said the code works for the home, when I set the tag like this
<a href="" data-icon="home">Home</a>
You need to invoke Backbone.history.start() before Backbone will start monitoring for hashchange events.
app.init = function() {
console.log('start init')
router = new TestRouter();
Backbone.history.start();
console.log('end init')
}
这篇关于骨干路由器听者不打散列标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!