Ember.js linkTo帮助程序链接不正确



我有一个Ember.js应用程序,顶部有一个导航栏。其中一个按钮转到/home,而另一个转到/book/:id/overview。如果我在/home页面上,则该按钮显示良好。如果我把鼠标悬停在按钮上,我可以看到链接会把我带到/book/2/overview。如果我复制链接位置并将其粘贴到地址栏中,它将带我进入/book/2/overview。但是,如果我只是点击链接,我就会进入/book/undefined/overview。链接显然指向了正确的位置,但Ember.js却把我带到了错误的位置。(或者更具体地说,它似乎没有找到模型,尽管如果我手动输入ID,它会发现它很好。)

可能出了什么问题?

(一旦我知道相关的部分,我就会发布一些代码。在这一点上,似乎可能有很多东西。)

单击链接时,与通过浏览器中的URL加载链接不同,不会调用路由的模型函数,而是将链接中提供的模型直接传递给setupController。也许你在里面做了什么奇怪的事。

以下是Ember代码中对model()的注释:

Note that for routes with dynamic segments, this hook is only
executed when entered via the URL. If the route is entered
through a transition (e.g. when using the `linkTo` Handlebars
helper), then a model context is already provided and this hook
is not called. Routes without dynamic segments will always
execute the model hook.
This hook follows the asynchronous/promise semantics
described in the documentation for `beforeModel`. In particular,
if a promise returned from `model` fails, the error will be 
handled by the `error` hook on `Ember.Route`.

最新更新