2016-08-31 7 views
0

"/ b"ルートでバックボーンアプリケーションを提供する必要があり、ルータに問題があります。私はちょうどビューを表示する場合は正常に動作しますが、私のルーターにフックをかけたときに私のルートコントローラ機能は起動しません。マリネットのルータを使用した非インデックスルートパス

ルータ:(発火が確認された)

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は '' 'Application = Marionette.Application.extend({...})' ''クラス拡張子にあります – goofiw

答えて

1

バックボーンのデフォルトルートはhash-basedです。 /bへのリンクはhttp://localhost:8080/#/bのようになります。

ハッシュベースのリンクが必要な場合は、開始履歴をpushState: trueとしてください。

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

EDIT:あなたは/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

関連する問題