Frage

Code is here: http://jsfiddle.net/cTpPx/, but view the live example here http://fiddle.jshell.net/cTpPx/show/, because I want you to observe the url changes.

Please disable Chrome cache when visit this page (Tick the relevant box in the built in Chrome debugger tool, and do not chose the debugger during the test)

When you open the page, you see the hastag changes to #!latest as expected, but when can.route.ready(true) gets executed, it changed back to #! empty route. Why there is such a strange behaviour?

But when you have cache for this page, it will work.

War es hilfreich?

Lösung

I'm pretty sure this is a timing issue. You are initializing the control and set the route right away in a route change event. If you defer setting the hash, it works: http://jsfiddle.net/cTpPx/2/

var AppController = can.Control({

    'route': function(){
        log('route empty');
        setTimeout(function() {
            window.location.hash = '#!latest';
        }, 10);
    },

    'latest route': function() {
        log('route: /latest');
    }

});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top