我想在多个路由下重用资源。以下是我的路由器的简化版本,例如:
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.show
或foo.index
。似乎无法指定要使用的嵌套(foo或bar),它只是默认为定义的最后一个嵌套。我真的需要像foo.comments.show
这样的东西,但没有什么可用。
我应该采用不同的方式吗?
谢谢!
答案 0 :(得分:0)
尝试将您的评论资源重命名为独特的内容并将路径映射到评论:
this.resource("commentsfoo", { path: '/comments'}, ...
...
this.resource("commentsbar", { path: '/comments'}, ...