I have made a demo of can.route,It can run when I open the page by this way :“file:///D:/work/bowerDemo/routeDemo.html#!findStudent/2/8” but when i open the page like this “http://test.bower-canjs.com/route_demo01.html#!student/3/5”,it does not work.How can I resolve this problem .
Can you create a JSBin or provide a sample of your code?
window.location.hash="#!student/1/5";
can.route("#!student/:pageNo/:pageCount",{pageNo:1,pageCount:5});
can.route.attr({
"action":"student"
});
var student=can.Control.extend({
init:function(){
},
"student/:pageNo/:pageCount route":function(data){
console.log("pageCount="+data.pageCount);
console.log("pageNo="+data.pageNo);
},
"action route":function(data){
console.log(data);
},
"{can.route} change":function(ev,attr,how,newAttr,oldAttr){
console.log(ev,attr,how,newAttr,oldAttr);
}
});
new student("body");
/*can.route.bind("change",function(ev,attr,how,newAttr,oldAttr){
console.log(ev,attr,how,newAttr,oldAttr);
})*/
can.route.ready();
In general, this code is outdated. It’s best to avoid Controls (except when making pure-DOM widgets), and it’s even better to avoid can/control/routes like "student/:pageNo/:pageCount route"
.
I made a JSbin that shows what you have working: http://justinbmeyer.jsbin.com/zobawa/edit?js,console,output
I hade to change:
new student("body");
to new student(document.body);
Are you new to CanJS? If yes, I’d encourage you to use Components instead of Controls. Checkout DoneJS’s getting started guide for an intro that shows CanJS’s routing.
Excuse me.May I get some help from you that about ‘canjs’ more information?Or can you give me some simple demo of it?Thank you
@marvengong DoneJs helps you start with canjs just follow the getting started guide