我在灰燼應用此路線:灰燼裝模板只能在頁面刷新
Router.map(function() {
// landing page (login/register)
this.route('home', {path: '/'});
// authenticated pages
this.route('webappFrame', {path: '/app'}, function() {
this.route('feed', {path: 'feed'});
this.route('photoDetail', {path: 'photo/detail/:id'});
});
});
其中兩個「飼料」和「photoDetail」有一個模型鉤子返回一個承諾(記錄來自服務器); 我在/ template文件夾中有一個loading.hbs模板;
在「feed」和「photoDetail」路由頁面刷新後,加載模板正確顯示; 但是當在路線之間導航時,它不再顯示(出口保持白色不可用,承諾解決);
我用ember-cli 2.3.0-beta.1(但也嘗試1.13.14穩定)與燼2.3.0; 在官方的ember文檔中寫道,它應該總是遍歷模板樹,直到找到加載模板; 有人可以告訴我這裏有什麼問題嗎?
UPDATE -------------------------------------------- --------
// feed model hook
model: function(params, transition) {
return this.store.query('photo', {type: 'feed'});
}
// photoDetail model hook
model: function(params, transition) {
var self = this;
return Ember.RSVP.hash({
photo: self.store.find('photo', params.id),
comments: self.store.query('comment', {id: params.id})
});
},
和在進料模板:
{{#each photo as |item|}}
{{photo-item item=item}}
{{/each}}
,然後將光項目組成:
{{#link-to "webappFrame.photoDetail" item.id}}
<img class="photoImage" src="{{imageurl item.hash type='photo'}}">
{{/link-to}}
其中{{IMAGEURL}}是隻是一個幫助創造th圖像的路徑; 在這裏,我通過「item.id」鏈接到(通過「項目」本身instad)強制輸入詳細信息時的照片重新加載(以獲得評論)
現在,已經添加了模板/ webapp-frame/loading.hbs,它可以工作; 的事情是,加載模板總是在整個應用程序相同;所以我希望只有一個,而不是在每個模板子文件夾中都有一個副本...
你可以添加你的路線,尤其是模型掛鉤,並鏈接到助手,在您的模板 –
作爲一個側面說明,如果你的路徑不必鍵入路徑名稱相匹配在'this.route('feed');'已經足夠了 –
是否還將loading.hbs添加爲/templates/webappFrame/loading.hbs? https://guides.emberjs.com/v2.3.0/routing/loading-and-error-substates/ –