2016-03-04 31 views
0

我正面臨着與Ember路由相關的嚴重問題。直接輸入網址時不會調用路由鉤子

當我嘗試通過link-to幫手顯示單個項目時,它工作正常,並且note.index正確調用的路由掛鉤。但是,當我直接在瀏覽器中輸入URL(localhost:4200/assessment/1/note/1)時,路由掛接不會被調用,或者是「model」掛鉤或「setupController」掛鉤或任何其他掛鉤。 基本上我想通過store.find將一些額外的參數傳遞給我的rails應用程序。

Router.js

@resource "assessment", path: 'assessments/:assessment_id', -> 
    @route 'edit' 
    @resource "notes", -> 
    @route "new" 
@resource "note", path: "note/:note_id", -> 
    @route 'edit' 

音符/ index.js

`import Ember from 'ember'` 

noteIndexRoute = Ember.Route.extend 
    model: (params)-> 
     console.log('********************Model Hook******************') 
     assessment = @modelFor('assessment') 
     @store.find('note',params.note_id,assessment_id: assessment.get('id')}); 

    setupController: (controller,model)-> 
     @_super controller, model 
     console.log('********************Setup Contr Hook********************') 
     assessment = @modelFor('assessment') 
     controller.set("model",@store.find('note',model.id,assessment_id: assessment.get('id')}); 

`export default noteIndexRoute` 

注:我想一些額外的參數傳遞給我的軌道API,這就是爲什麼我要打電話去鉤取上項目。

+0

你在哪個版本上?目前不推薦使用'this.resource'。 – locks

+0

我的應用中也沒有看到'/ assessment/1/note/1'路由,因爲'note'沒有嵌套在'assessment'下面。 – locks

+1

也許不是你所遇到的具體問題,但是'controller.set('model','將給'model'屬性分配一個承諾,這不是你可能想要的。你需要做set一個'then'子句,或者更可能的是,在一個'beforeModel'或'afterModel'鉤子中執行,Ember將負責解決您的承諾。另外,您不需要在'model'中使用'return'鉤? – 2016-03-04 13:51:20

回答

0

Ember版本是1.10.0。現在,當我在瀏覽器中輸入網址並且運行良好時,路由鉤子正在快速發展。實際上我的路由文件是index.js,它出現在note/index.js路徑中。我將index.js路徑從note目錄移動到"app/routes/"目錄,並將index.js文件的名稱更改爲note.js文件。所以我的路徑文件的新路徑是app/routes/note.js.它解決了我的問題,現在我的鉤子正常工作,並在我將直接url輸入到大型瀏覽器時調用。

同樣,我移動並更改控制器文件和模板文件的名稱和路徑。從note/index.jsnote/index.hbsapp/routes/note.js用於控制器和app/templates/note.hbs用於模板文件。

相關問題