使用#标签在页面加载时不调用特定的canjs路由

时间:2014-06-07 18:09:52

标签: routes canjs canjs-routing

代码有什么问题?预期结果:当页面加载如url / case#!open-cases或url / cases#!new时,目标路由列表器(' new route'或者#39;:filter-cases route' ;)应该被调用,但它不会发生

PageControl = can.Control({
        init : function(el, options) {
            debugger;
        },
        'new route': function() {debugger;},
        ':filter-cases route': function() {debugger;
            new CaseList('#content');
        },
        'route': function(data) {debugger;
            new CaseList('#content');
        }
    });

    $(document).ready(function() {
        //initDialog();
        can.route(':filter-cases');
        can.route('case/:id');
        can.route('new');
        //can.route('', {filter: 'open' })
        can.route.ready();

        new PageControl(window);
    });

1 个答案:

答案 0 :(得分:1)

如果您在初始化页面控件后调用can.route.ready() ,它应该有效:

$(document).ready(function() {
    //initDialog();
    can.route(':filter-cases');
    can.route('case/:id');
    can.route('new');
    //can.route('', {filter: 'open' })

    new PageControl(window);
    can.route.ready();
});