2013-09-07 1 views
3

Ember가 일부 이전 버전의 IE에서 잘 테스트되었다는 인상을 받았습니다. 그러나, 마침내 내 가까운 완전한 애플 리케이션 (폼 마법사)를 발사. IE가 replaceState 및 pushState에 대해 불만을 제기하고 있음을 알고 있습니다. http://caniuse.com/#search=pushStateEmber 1.0 최종 Internet Explorer 8 및 9 (History API - pushState 및 replaceState)

이 문제를 해결할 수있는 방법이 있습니까?

SCRIPT438: Object doesn't support property or method 'replaceState'

get(this, 'history').replaceState(state, null, path);

답변

10

UPDATE : 엠버 기준으로 1.5.0+ 나는 그들이 아래의 예에 대한 필요성을 제거한다 '자동'을 추가 한 것을 확인할 수 있습니다.

App.Router.reopen({ 
    location: 'auto' 
}); 

원래 답변 :

은 분명히 당신이 역사의 API를 감지 기능을 할 필요가 :

if (window.history && window.history.pushState) { 
    App.Router.reopen({ 
    location: 'history' 
    }); 
} 
0

주위에 작업이 없습니다. 해시 URL (/ #/사용자) 대신 실제 URL (/ 사용자)을 사용해야하는 경우 지원되는 브라우저 목록에서 IE 8 & 9를 제외하거나 Ember를 "점진적 향상"으로 사용해야합니다. 방식으로 방문한 각 실제 URL에 대해 서버의 유효한 콘텐츠를 계속 제공하고 기능 감지를 사용하여 Ember 앱을 선택적으로 활성화 할 수 있습니다.

0

pushSate 및 non-pushState 브라우저를 모두 올바르게 지원하려면 두 가지 다른 상태 메커니즘 사이에 변환기가 있어야합니다. IE8/9의

/관리자/사용자/123

, 당신은을 리디렉션 할 수 있습니다 : 예를 들어

,의 당신의 rootURL가 '/ 관리 /'당신이 URL로 시작 가정 해 봅시다 사용자를 '/ admin/#/users/123'으로 변경하십시오. 이 URL로 시작하는 경우 마찬가지로 :

/관리/#/사용자/123

... 다음 pushState를 지원하는 브라우저, 당신은 상태를 교체 할 수 있습니다에 대한에 '/ 관리/사용자/Ember의 라우팅 메커니즘이 인계 받기 전에 123 '.

이것은 Backbone 라우터의 기본 동작이며 매우 잘 작동합니다. Ember에서이 결과를 얻으려면 Backbone의 소스 코드에서 영감을 받아 다음과 같이 할 수 있습니다.

App.Router.reopen({ 
    rootURL: '/admin/', 

    init: function() { 
     this.translateRoute(); 
     this._super(); 
    }, 

    translateRoute: function() { 

     var hasPushState = window.history && window.history.pushState; 
     var atRoot = window.location.pathname === this.rootURL; 
     var fragment = decodeURIComponent(window.location.pathname); 
     if (!fragment.indexOf(this.rootURL)) 
      fragment = fragment.substr(this.rootURL.length); 

     if (hasPushState) 
      this.location = 'history'; 

     // If we started with a route from a pushState-enabled browser, 
     // but we're currently in a browser that doesn't support it... 
     if (!hasPushState && !atRoot) { 
      window.location.replace(this.rootURL + '#/' + fragment); 
      return; 
     } 

     // If we started with a hash-based route, 
     // but we're currently in a browser that supports pushState... 
     if (hasPushState && atRoot && window.location.hash) { 
      fragment = window.location.hash.replace(/^(#\/|[#\/])/, ''); 
      window.history.replaceState({}, document.title, window.location.protocol + '//' + window.location.host + this.rootURL + fragment); 
     } 
    } 
});