2014-01-27 123 views
0

我有一個嵌套的路由是設置爲:模型鉤否則瀏覽器重裝

this.resource('actions', { path: '/actions' }, function() { 
    this.route("action", {path: ':id'}); 
}); 

當我去/actions URL狀態時,它調用的ActionsIndexController模型(),併成功地檢索所有的記錄「行動」。如果我在這一點上重新加載它工作正常,重新加載所有記錄。問題在於轉換到子路線時。當在索引頁上並轉換到/actions/[action-id]時,頁面按預期方式加載,但如果在頁面上重新加載該頁面時(當然這意味着Actions的本地狀態已消失),該頁面將會失敗。

這裏是在ActionsActionRoute模型鉤:

model: function(params) { 
    console.log(params); 
    return this.store.find('Action',params.id); 
} 
在這兩個用例

有趣的是 - 當你開始導航到這個URL 當你按下重裝瀏覽器 - 它運行的模型掛鉤和控制檯聲明給出的結果是:

Object {id: "action-id", queryParams: Object} 

屬性似乎是完全相同但在重載情況下我給出了錯誤:

Error while loading route: TypeError: Cannot read property 'id' of undefined at DS.Store.Ember.Object.extend.push (http://my.server.com/myApp/javascripts/vendor.js:71617:77)

任何人都可以幫我找到這個問題嗎?

回答

1

在您的Router中,您將嵌套路徑指定爲route而不是resource

從灰燼指南:

NOTE: You should use this.resource for URLs that represent a noun, and this.route for URLs that represent adjectives or verbs modifying those nouns. For example, in the code sample above, when specifying URLs for posts (a noun), the route was defined with this.resource('posts'). However, when defining the new action (a verb), the route was defined with this.route('new').

在你的情況,/action/:id表示資源,不是路線從父資源。我建議你改變你的代碼,如下所示:

this.resource('actions', { path: '/actions' }, function() { 
    this.resource("action", {path: ':id'}); 
}); 
+0

謝謝Steve,它對它進行了排序。我需要回到文檔,並確保這對我來說是黑白的......特別是像「加載」,「錯誤」,甚至是「索引」等路線有時每次都是太多的實驗,我是確定管理的規則是清楚的。無論如何,感謝上帝爲督察和像你這樣有幫助的人。 :) – ken

+0

當然 - 你可能也對這篇文章感興趣:http://darthdeus.github.io/blog/2013/02/01/ember-dot-js-router-and-template-naming-convention/ –