简体   繁体   English

骨干非默认根URL

[英]Backbone non-default root url

I'm trying to integrate Backbone inside a PHP CMS . 我正在尝试将Backbone集成到PHP CMS

The root url for my Backbone app is: 我的Backbone应用程序的根URL是:

http://localhost/administrator/index.php?option=com_test&controller=product.list

I have setup my router like this: 我已经这样设置了路由器:

var AppRouter = Backbone.Router.extend({
    routes: {
        '': 'test',
    }
});

var initialize = function () {
    var router = new AppRouter;

    router.on('test', function () {
        console.log('match');
    });

    Backbone.history.start({
        pushState: true,
        root: '/administrator/index.php?option=com_test&controller=product.list'
    });

    router.navigate('/', {trigger: true});
};

The navigate function is correctly called but the route never matches. 正确调用了navigate功能,但路由从未匹配。 I tried to add a trailing backslash in the root , but it doesn't not change anything. 我试图在root添加尾随反斜杠,但是它没有任何改变。

The problem is that you should either add test method to Router like that: 问题是您应该像这样向Router添加test方法:

var AppRouter = Backbone.Router.extend({
  routes: {
    '': 'test',
  },
  test: function(){
    console.log('test route');
  }
});

or listen to route:test event: 或收听route:test事件:

router.on('route:test', function () {
    console.log('match');
});

because Backbone.Router triggers routes names when matched with prefix route: 因为Backbone.Router与前缀route:匹配时会触发路由名称route:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM