0

Backbone.js 앱의 페이지 탐색에 이벤트가 발생하는 데 문제가 있습니다. 첫째, 관련 코드 :페이지에 액세스 할 때 백본/마리오네트 라우터 이벤트가 실행되지 않습니다.

* users_app.js.coffee *

@Demo.module "UsersApp", (UsersApp, App, Backbone, Marionette, $, _) -> 

    class UsersApp.Router extends Backbone.Marionette.AppRouter 
     appRoutes: 
      "users" : "listUsers" 

    UsersApp.API = 
     listUsers: -> 
      console.log "listUsers" 

    App.addInitializer -> 
     new UsersApp.Router 
      controller: UsersApp.API 

app.js.coffee

@Demo = do(Backbone, Marionette) -> 

    App = new Marionette.Application 

    App.on "initialize:before", (options) -> 
    @currentUser = App.request "set:current:user", options.currentUser 

    App.reqres.setHandler "get:current:user", -> 
    App.currentUser 

    App.addRegions 
    headerRegion: "#header-region" 
    mainRegion: "#main-region" 
    footerRegion: "#footer-region" 

    App.addInitializer -> 
    App.module("HeaderApp").start() 
    App.module("FooterApp").start() 

    App.on "initialize:after", -> 
    if Backbone.history 
     Backbone.history.start 

    App 

내가 콘솔에서 테스트 한 내가 호출 할 수 있습니다 기능이 listUsers 인 경우 수동으로 간단하게 Demo.UsersApp.API.listUsers()과 함께 사용합니다. 그러나 listUsers은 페이지로드시 실행되지 않습니다. 이 구현은 또한 다음과 일치하는 것으로 보입니다. Marionette documentation

의견이 있으십니까? 콘솔에서 appRoutes 이벤트를 테스트 할 수있는 쉬운 방법이 있나요?

+0

"발사하지"로 당신은 당신이 주소 /index.html#users의 listUsers에 가면 호출되지 않습니다 것을 의미? – Ingro

+0

"listUsers"(문자열)가 콘솔에 출력되지 않는다는 것을 의미합니다. – mattmattmatt

+0

네, 그렇지만 브라우저로 그 경로를 치고 있습니까? 코드에서 기본 경로가 설정되지 않았기 때문입니다. – Ingro

답변

0

당신은 appRouter에서 컨트롤러를 지정해야합니다 :

{ 
    controller: UsersApp.API 
}