[英]Route hooks are not called when the url is directly entered
I'm facing a serious issue related to Ember routes. 我面临着与Ember航线相关的严重问题。
When I try to show a single item through a link-to
helper, it works fine and hooks in route for note.index
get called properly. 当我尝试通过
link-to
帮助器显示单个项目时,它可以正常工作,并且在note.index
路由钩子中调用正确。 But when I enter the URL ( localhost:4200/assessment/1/note/1
) directly in the browser, then route hooks are not called, either it is "model" hook or "setupController" hook or any other hook. 但是,当我直接在浏览器中输入URL(
localhost:4200/assessment/1/note/1
)时,不会调用路由钩子,它是“模型”钩子或“ setupController”钩子或任何其他钩子。 Basically I want to pass some extra parameters to my rails application with store.find
. 基本上,我想使用
store.find
将一些额外的参数传递给我的rails应用程序。
Router.js Router.js
@resource "assessment", path: 'assessments/:assessment_id', ->
@route 'edit'
@resource "notes", ->
@route "new"
@resource "note", path: "note/:note_id", ->
@route 'edit'
note/index.js note / 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`
Note: I want to pass some extra parameters to my rails API, that's why I need to call hook on fetching item. 注意:我想将一些额外的参数传递给我的Rails API,这就是为什么我需要在获取项目时调用钩子。
Ember version is 1.10.0. 灰烬版本为1.10.0。 Now route hooks are wroking when i enter url in browser and working well.
现在,当我在浏览器中输入url并运行良好时,路由钩子就会混乱。 actually my route file was index.js, which was present in
note/index.js
path. 实际上,我的路由文件是index.js,该文件存在于
note/index.js
路径中。 i move index.js route from note directory to "app/routes/"
directory and change the name from index.js file to note.js file. 我将index.js路由从注释目录移至
"app/routes/"
目录,并将名称从index.js文件更改为note.js文件。 so my new path for route file is app/routes/note.js.
所以我的路由文件新路径是
app/routes/note.js.
it resolved my issue and now my hooks are working properly and called when i enter direct url into broswer. 它解决了我的问题,现在当我在浏览器中输入直接网址时,我的钩子可以正常工作并被调用。
similarly i move and change the name and path of controller file and template file. 同样,我移动并更改控制器文件和模板文件的名称和路径。 from
note/index.js
and note/index.hbs
to app/routes/note.js
for controller and app/templates/note.hbs for template file. 从
note/index.js
和note/index.hbs
到控制器的app/routes/note.js
和模板文件的app / templates / note.hbs。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.