即使一切都在标题中,要清楚,我想我的emberjs 动态路由的样子:emberjs与哈希动态路由只(没有斜杠)
http://mywebsite.com/#dynamic_route/subroute
与哈希只,而不是一个以“/”默认:
http://mywebsite.com/#/dynamic_route/subroute
不知道是否有可能(我试过几个黑客没有成功),但如果是让我知道:)
个感谢, 汤姆
即使一切都在标题中,要清楚,我想我的emberjs 动态路由的样子:emberjs与哈希动态路由只(没有斜杠)
http://mywebsite.com/#dynamic_route/subroute
与哈希只,而不是一个以“/”默认:
http://mywebsite.com/#/dynamic_route/subroute
不知道是否有可能(我试过几个黑客没有成功),但如果是让我知道:)
个感谢, 汤姆
最高版本为1.0.0,pre.4这似乎是默认行为。在最终版本1.0.0中,它仅表现为没有路径的路由。一种方法我都遵循,似乎罚款通过提供位置API(http://emberjs.com/guides/routing/specifying-the-location-api/)的实施工作,它是基于默认实现讨论, https://github.com/emberjs/ember.js/issues/2053answers 和 Hashbang URLs using Ember.js
(function() {
var get = Ember.get, set = Ember.set;
Ember.Location.registerImplementation('no-slashes', Ember.HashLocation.extend({
getURL: function() {
var path = get(this, 'location').hash;
if(path.indexOf("/")!=1){
return "/"+path.substr(1);
}else{
return path.substr(1);
}
},
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(1);
if(path.indexOf("/")!=0){
path = "/"+path;
}
if (get(self, 'lastSetURL') === path) { return; }
set(self, 'lastSetURL', null);
callback(path);
});
});
}
}));
})();
App.Router.reopen({
location: 'no-slashes'
});
@melc感谢指着我正确的方向。我即兴编写了代码。注 - 我使用的是ember 1.5.1。
我最终只覆盖了getURL方法。 registerImplementation在1.5.1中已弃用,因此使用容器来注册HashLocation的新实现。希望这可以帮助某人。
(function() {
var get = Ember.get, set = Ember.set;
var noSlashLocation = Ember.HashLocation.extend({
getURL: function() {
var hash = this.getHash().substr(1);
return (hash.indexOf('/') != 0) ? '/'+hash : hash;
}
});
var container = new Ember.Container();
container.register('location:no-slash', noSlashLocation);
Ember.Router.reopen({
location: container.lookup('location:no-slash')
});
})();