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);
}
}
});