Canjs:触发当前页面的路由事件



我有一个罐子。看起来像这样的控件:

can.Control({
    "route": function(){
        ...
    },
    "a.test click": function(){
        can.route.attr({
            page: "home",
            type: "test"
        });
    }
});

如果当前页面为{page:"home",类型:"test"},则不会调用"route"回调。

无论我当前所在的页面如何,我都如何触发路由事件?

我的想法
我可以直接调用this.route(),但我必须处理更改URL的问题,这使得它不是一个好的解决方案。

"{can.route} change": function(ev, attr, how, newVal, oldVal) {
    if(how=='your-page') {
        // your change
    }
}

关于canjs中的路由:http://canjs.com/docs/can.route.html

最新更新