Question

right now im diving into canjs, it looks like a great mvc framework. I'm having troubles with the router. I'm using wamp for making my tests in localhost. So the problem is the following: when I enter localhost the initial url in the browser is "localhost" which matches my first case in the router which handles the empty urls. Problem is that I'm doing a window.location.hast to redirect the user, but after I do this it doesn't gets routed so this is the part i need help with. My router code is as follows:

$(function() {
'use strict';
var Routing = can.Control({
    defaults: {}
}, {
    'init': function() {
        console.log('router init');
    },
    //default router
    'route' : function(){
        console.log('default route');
        window.location.hash= "#!dashboard/london/";//doesnt works like this
        //can.route.attr('location','london');//like this it works!!!
    },
    //route i cant match!
    'dashboard/:location/ route' : function(data){
        console.log(data.location);
    }
});

can.route.ready(false);
new Routing($('body'));
can.route.ready(true);

});

Was it helpful?

Solution

I created a Fiddle with the latest version (which only needs to call can.route.ready() to start routing) running your code and I get

router init
default route
london

Which should be what you're expecting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top