我想使用this tuto,但不适合我
$(function() { Router = can.Control({ "completed route" : function(){ console.log("the hash is #!completed") }, "active route" : function(){ console.log("the hash is #!active") }, "project/create" : function(){ console.log("the hash is #!project/create") }, "route" : function(){ console.log("empty hash") } }); // make sure to initialize the Control new Router(document); });
我使用window.location.hash = "!#completed"
或<a href="#!active">Show Active</a>
控制台中不显示任何消息。
我使用canjs 2.0.4和JQuery
感谢您的帮助
答案 0 :(得分:2)
您必须致电can.route.ready()初始化路由:
Router = can.Control({
"completed route" : function(){
console.log("the hash is #!completed")
},
"active route" : function(){
console.log("the hash is #!active")
},
"route" : function(){
console.log("empty hash")
}
});
// make sure to initialize the Control
new Router(document);
can.route.ready();