2012-05-30 8 views
3

ember.js에서 다음과 같이 구현했습니다. 코드는 특정 지점까지 작동합니다.Ember 라우터가 Chrome 및 Safari에서 URL을 업데이트하지 않습니다.

루트 URL (예 : '/')에서 애플리케이션을 입력하면 tasks.index로 이동해야하며 변경 사항을 #/tasks를 표시하여 반영합니다.

하지만 '#/tasks'로 이동하면 'hello from index view'메시지가 표시됩니다.

Google 크롬 버전 19 및 ember.js edge를 사용하고 있습니다.

모든 도움을 주시면 대단히 감사하겠습니다.

App = Em.Application.create({}); 

App.IndexView = Em.View.extend({ 
    template: Em.Handlebars.compile(
     'hello world from index' 
    ) 
}); 

App.ShowView = Em.View.extend({ 
    template: Em.Handlebars.compile(
     'hello world from show' 
    ) 
}); 

App.Router = Ember.Router.extend({ 
    location: 'hash', 
    rootElement: "#my-app", 
    enableLogging: true, 

    root: Ember.State.extend({ 
     index: Ember.State.extend({ 
      route: '/', 
      redirectsTo: 'tasks.index' 
     }), 

     tasks: Ember.State.extend({ 
      route: '/tasks', 

      index: Ember.ViewState.extend({ 
       route: '/', 
       view: App.IndexView 
      }), 

      show: Ember.ViewState.extend({ 
       route: '/show', 
       view: App.ShowView 
      }) 
     }) 
    }) 
}); 

App.initialize(); 

답변

1

이 jsFiddle를 참조하십시오

코드 - 당신이 할 필요가 모든 변화 redirectsTo: 'tasks.index'redirectsTo: 'tasks'http://jsfiddle.net/ud3323/WLcRQ/

Debug->http://jsfiddle.net/ud3323/WLcRQ/show/

>이었다.

redirectsTo을 사용할 때 대상 상태에 시작 경로가 정의되어있을 때 대상 상태의 시작 경로를 지정할 필요가 없습니다.

+0

좋은 소식 !!! 고맙습니다! – codehugger

+0

내가 혼란스러워하는 것이 더 있습니다. 'tasks.show'로 리다이렉트하면 URL을 '#/tasks/show'로 업데이트하면 안됩니까? 'tasks.index'와 똑같이 동작합니다. 즉 URL이 전혀 업데이트되지 않습니다. – codehugger

+0

레일 라우터에서 루트를 정의하는 것처럼 동작하기 때문에 그럴 것 같아요. 이제 응용 프로그램 루트는 tasks.index이고 url에 "/"을 지정하여 도달 할 수 있으므로 변경되지 않습니다. task.index 상태로 transitionTo하면 url이 바뀌기 때문에 이것이 작동하는 것을 볼 수 있습니다. –

관련 문제