1

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

可能出了什么问题?

(我会在知道相关位后立即发布一些代码。目前看来可能有很多东西。)

4

1 回答 1

1

当您单击链接时,与通过浏览器中的 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`.
于 2013-07-19T05:58:45.537 回答