2

so this bug is killing me as I have no clue what's going on, I updated my canjs version to the latest which is currently 2.0.4 with jquery, and the router stopped working. Is not routing anything, I try with window.location.hash and can.route.attr and is not routing. The thing that bugs me is that with the old version I had was working perfectly. Here is the code

var Router = can.Control({
    'init': function() {
    },
    'route' : function(){
        window.location.hash = '#!dashboard';
    },
    'dashboard route': function() {
        console.log('dashboard')
    }
});

$(document).ready(function() {
    can.route.ready(false);
    new Router($('body'));
    can.route.ready(true);
});
ramblinjan
  • 6,578
  • 3
  • 30
  • 38
rdk1992
  • 406
  • 1
  • 5
  • 20
  • To add to @air_hadoken's correct answer, this should be the only major breaking change when upgrading form 1.1.x to 2.0.x: http://canjs.com/guides/migrating.html – Daff Feb 06 '14 at 02:56

1 Answers1

3

FYI, the latest CanJS is 2.0.5, released yesterday.

can.route.ready() doesn't work like it used to. can.route.ready(true) in fact does nothing, in order to prevent multiple route setups in legacy code. This explains somewhat why your code isn't initializing that first jump to #!dashboard, since you would need to init the Router controller before the call to ready.

Better to remove the first call to ready and take out the argument from the second. I have a demo of this at http://jsfiddle.net/air_hadoken/5maLu/1/ -- click Run and you will see evidence of each route listener in your controller firing.

air_hadoken
  • 611
  • 4
  • 5
  • thanks it worked. Now what I did was to download the latest version from their website and it still didnt worked, I download the one in your fiddle and it worked!. Thanks a lot, I needed to upgrade since the two way binding is a feature I must use now :D. – rdk1992 Feb 06 '14 at 23:23