Ember 路由器上的资源重用
Ember resource reuse on router
我想在多个路由下重复使用一个资源。出于示例目的,这是我的路由器的简化版本:
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
之类的东西,但没有可用的东西。
我应该做些不同的事情吗?
谢谢!
尝试将您的评论资源重命名为唯一的名称并将路径映射到评论:
this.resource("commentsfoo", { path: '/comments'}, ...
...
this.resource("commentsbar", { path: '/comments'}, ...
我想在多个路由下重复使用一个资源。出于示例目的,这是我的路由器的简化版本:
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
之类的东西,但没有可用的东西。
我应该做些不同的事情吗?
谢谢!
尝试将您的评论资源重命名为唯一的名称并将路径映射到评论:
this.resource("commentsfoo", { path: '/comments'}, ...
...
this.resource("commentsbar", { path: '/comments'}, ...