要添加以前的答案,使用直接更改URL的方法来更改URL时,在当前的Ember版本中,可以选择将查询参数链接到控制器属性。
一个简单的例子从Ember guide page编译:
App.MapController = Ember.ObjectController.extend({
queryParams: ['zoom', {latitude: 'lat'}, {longitude: 'lon'}],
zoom: 10,
latitude: null,
longitude: null,
mapWindowChanged: function {
MapApi.reposition(this.zoom, this.latitude, this.longitude);
}.observes('zoom','latitude','longitude')
});
当使用查询参数这种方式,控制器/视图代码可以只是改变结合的控制器属性和查询参数将自动更新。
使用Ember.Route queryParams property方式的转变,查询参数的影响路径事件如下:
App.MapRoute = Ember.Route.extend({
queryParams: {
lat: {
refreshModel: true,
replace: true,
},
long: {
refreshModel: true,
replace: true,
},
zoom: {
replace: true
}
}
});
这将告诉灰烬倾斜地图时从服务器重新加载所需的部件,但不改变变焦时。此外,更改参数不会将状态项推送到浏览器历史记录。
你不应该用位置对象或类似的东西手动更新URL。影响Ember外观的方法是使用路线并为其添加动态片段。 – mavilein
看看下面的链接:http:// stackoverflow。com/questions/15165072/is-resource-nesting-the-only-way-to-enable-multiple-dynamic-segments/15174766#15174766 http://mavilein.github.io/javascript/2013/09/28/三步到烬 - js-seo-friendly-urls/ – mavilein
而这一个 - > http://stackoverflow.com/questions/18164461/how-do-you-maintain-the-page-state-so- that-you-can-provide-permalinks-using-emb/18249404#18249404 这些链接包含所有你需要的成分。如果您遇到问题,请创建一个JSFiddle或JSBin,我可以帮助您制定一个基本示例。 – mavilein