Router
에 "hashbang"URL (#!
)을 사용하도록 설정하려고합니다. Hashbang Ember.js를 사용하는 URL
App.Router.map(function() {
this.route("index", { path: "!/" });
this.route("otherState", { path: "!/otherState" });
});
은 엠버에서 할이 수 있습니까?
Router
에 "hashbang"URL (#!
)을 사용하도록 설정하려고합니다. Hashbang Ember.js를 사용하는 URL
App.Router.map(function() {
this.route("index", { path: "!/" });
this.route("otherState", { path: "!/otherState" });
});
은 엠버에서 할이 수 있습니까?
연장 Ember.HashLocation
가야 할 길입니다.
깨끗한 구현을 위해 다음을 수행 할 수 있습니다.
App.Router.reopen({
location: 'hashbang'
})
테디 Zeenny의 대답은 대부분 정확하고 registerImplementation
이를 구현하는 깨끗한 방법이 될 것 같다 :
Ember.Location.registerImplementation('hashbang', Ember.HashLocation.extend({
// overwrite what you need, for example:
formatURL: function(url) {
return '#!' + url;
}
// you'll also need to overwrite setURL, getURL, onUpdateURL...
})
은 다음 앱 라우터 위치 관리를위한 사용자 정의 구현을 사용하도록 지시합니다. 나는 그 질문에 완전히 답할 수 있도록 그의 대답을 편집하려고 노력했지만 편집은 거부되었다.
App.Router.reopen({
location: 'hashbang'
})
: 당신이 "hashbang"위치 구현을 활용할 수있는 라우터를 변경해야 귀하의 응용 프로그램을 작성하면 다음
(function() {
var get = Ember.get, set = Ember.set;
Ember.Location.registerImplementation('hashbang', Ember.HashLocation.extend({
getURL: function() {
return get(this, 'location').hash.substr(2);
},
setURL: function(path) {
get(this, 'location').hash = "!"+path;
set(this, 'lastSetURL', "!"+path);
},
onUpdateURL: function(callback) {
var self = this;
var guid = Ember.guidFor(this);
Ember.$(window).bind('hashchange.ember-location-'+guid, function() {
Ember.run(function() {
var path = location.hash.substr(2);
if (get(self, 'lastSetURL') === path) { return; }
set(self, 'lastSetURL', null);
callback(location.hash.substr(2));
});
});
},
formatURL: function(url) {
return '#!'+url;
}
}));
})();
: 어쨌든 여기
은 엠버 사용 hashbang URL을 만들 수있는 전체 코드입니다
몇가지 덧글 : - Ember.Router' 대신에'App.Router'를 다시 열어 보는 것이 더 낫습니다. (특히 여러분이 테스트 중이라면, Ember.Router'를 깨끗하게 유지하는 것이 좋습니다.) -'Ember.Router' 대신' init'과'willDestroy'는 HashLocation을 확장하기 때문에이 함수들은 상속 될 것이고 코드는 더 간단해질 것입니다. –
감사. 네가 한 말을 바꿨다. – twiz
이 메서드는 완벽하게 작동하지만 마지막 ember에서는 deprecation 메시지를 throw합니다. 비추천 코드를 사용하지 않고 이것을 사용하려면 어떻게해야합니까? –
나는 'Ember.HashLocation' 속성을 덮어 씀으로써 여러개의 문자열에'! '를 추가 할 수있게되었습니다. 이것이 무엇인가를 깨뜨리는 지 확실하지 않습니다. 더 합법적 인 방법을 게시하는 사람이 아무도 없다면 내 코드를 답으로 추가하겠습니다. – twiz