2016-08-31 47 views
0

我必须在“/ b”路线上提供我的骨干应用程序,并且无法连接到路由器。它工作正常,如果我只showView视图,但我的路由控制器功能没有发射时,我挂在我的路由器,任何想法?非索引根路径与Marionette路由器

路由器:

define('appRouter', ['marionette', 'rootView', 'changePasswordView'], function(Marionette, rootView, changePasswordView) { 
    return Marionette.AppRouter.extend({ 
    routes: { 
     '/b/change-password': 'showChangePassword', 
     '/b': 'showAccountSettings' 
    }, 
    showChangePassword: function() { 
     this.showView(new changePasswordView()); 
    }, 
    showAccountSettings: function() { 
     this.showView(new rootView()); 
    } 
    }); 
}); 

应用在onStart(这是确定射击):

var Application = Marionette.Application.extend({ 

... 

    onStart: function(options) { 
     console.log('on start'); 
     var router = new appRouter(options); 
     /** Starts the URL handling framework */ 
     if(! Backbone.History.started) Backbone.history.start(); 
     router.initialize(); 
    }, 

... 

}); 

当我访问http://localhost:8080/b(这是所有密集的目的,我的指数),它呈现一个空白页。

+0

你在哪里登记在Marionette.Application的路线?你可以发布代码吗? –

+0

这可能是我错过了,onStart显示在应用程序= Marionette.Application.extend({...})'''class extension – goofiw

回答

1

Backbone中的默认路由是hash-based。链接到您的/b路线应该看起来像http://localhost:8080/#/b

如果您不需要基于散列的链接,请以pushState: true开始记录。

Backbone.history.start({pushState: true}); 

编辑:

如果你提供的/b路径上的应用程序,那么你就错了定义的路由。路线必须相对于/b定义:

routes: { 
    'change-password': 'showChangePassword', 
    '': 'showAccountSettings' 
}, 

,并获得:

  • http://localhost:8080/b' - showAccountSettings`
  • http://localhost:8080/b#change-password' - showChangePassword`
+0

该应用程序被关闭'/ b'路径,而不是'/'路径。它不会(也不应该)在'/ b' – goofiw

+0

之前访问任何东西,谢谢你们 – goofiw