2016-08-31 52 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