Ember.js 中的嵌套路由

Nested routes in Ember.js

我有一个 ember 应用程序需要以下视图:


我正在为第三个而苦苦挣扎。

这是我的 router.js

this.route('reviews', function() {
  this.route('show', { path: "/:id" });
});

this.route('users', function(){
  this.route('show', {path: '/:id'}, function () {
    this.route("reviews", function(){});
  });
});

这条路线的模板在 templates/users/show/reviews/index.hbs

我的路线在routes/users/show/reviews/index.js

但是当我访问 localhost:4200/users/1/reviews 时,它显示了用户配置文件路径(users/:id - 第二个要点)。像完全一样一样

如何让这条路线使用正确的模板和 route.js 文件?

你的路线应该是这样的:

this.resource('reviews', function() {
  this.route('show', { path: '/:id'})
})

前面的意思是您可以使用以下路线:

/reviews <- 资源评论的默认路由 index

/reviews/:id <- 这是路线 show

并且应该有以下文件:

路线 -> app/routes/reviews/show.jsapp/routes/reviews/index.js

控制器 -> app/controllers/reviews/show.js, app/controllers/reviews/index.js

模板 -> app/templates/reviews/show.hbsapp/templates/reviews/index.hbs

请注意,如果您没有定义任何以前的文件,ember将默认生成一个。

用户应遵循与先前定义相同的逻辑。

this.resource('users', function() {
  this.resource('user', { path: '/:id' }, function () {
    this.route("reviews");
   });
});

翻译之前的用户定义,您将有以下路线。

/users <- 资源用户的默认索引

/users/:id <- 资源用户的默认索引

/users/:id/reviews <- reviewsusers

内的路线

希望能帮到你!