如果要更改標題中的所有路線,你可以重新打開Ember.Route
類:
Ember.Route.reopen({
activate: function() {
this._super.apply(this, arguments);
var title = this.get('title') || '';
document.title = title;
}
});
所以在您的路線定義title屬性,將使document.title
轉換到該路線時更改。
例如:
App.IndexRoute = Ember.Route.extend({
title: 'index' // changes the title to index
});
App.FooRoute = Ember.Route.extend({
title: 'foo' // changes the title to foo
});
App.BarRoute = Ember.Route.extend({
title: 'bar' // changes the title to bar
});
App.NotitleRoute = Ember.Route.extend({}); // don't change the title
觀察:這implemantation不具有約束力知道
請給看看。源代碼http://jsbin.com/ucanam/1918/edit。嵌入式演示http://jsbin.com/ucanam/1918
這應該讓事情變得簡單,但林不知道這是否可用。 https://github.com/emberjs/ember.js/pull/2757 – blessenm