路由器上的Ember资源重用

时间:2015-01-23 20:58:57

标签: ember.js

我想在多个路由下重用资源。以下是我的路由器的简化版本,例如:

Router.map(function() {
  this.resource("foo", function() {
    this.resource("comments", function() {
      this.route("show", {
        path: ":comment_id"
      });
    });
  });
  this.route("bar", function() {
    this.resource("comments", function() {
      this.route("show", {
        path: ":comment_id"
      });
    });
  });
});

正如所料,我现在可以访问以下网址。

/foo/comments/2

/bar/comments/2

但是当我想在路线中使用transitionTo时,我只能访问comments.showfoo.index。似乎无法指定要使用的嵌套(foo或bar),它只是默认为定义的最后一个嵌套。我真的需要像foo.comments.show这样的东西,但没有什么可用。

我应该采用不同的方式吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试将您的评论资源重命名为独特的内容并将路径映射到评论:

this.resource("commentsfoo", { path: '/comments'}, ...
...
this.resource("commentsbar", { path: '/comments'}, ...