在Ember中定义资源路由的正确方法?

Rob*_*bin 4 routes ember.js

在指南中,我可以看到两种方法来定义资源的路径,我想知道我应该使用的是什么,为什么?


在这里找到:http://emberjs.com/guides/routing/defining-your-routes/

App.Router.map(function() {
  this.resource('posts');
  this.resource('post', { path: '/posts/:post_id' });
});
Run Code Online (Sandbox Code Playgroud)

在此处找到:http://emberjs.com/guides/templates/links/

App.Router.map(function() {
  this.resource("posts", function(){
    this.route("post", { path: "/:post_id" });
  });
});
Run Code Online (Sandbox Code Playgroud)

我发现很奇怪有定义2个资源,posts并且post,当它实际上只是一个Post资源.

Dev*_*man 5

我相信当你这样做的时候

App.Router.map(function() {
  this.resource("posts", function(){
    this.route("post", { path: "/:post_id" });
  });
});
Run Code Online (Sandbox Code Playgroud)

它在帖子模板的{{outlet}}内呈现帖子模板.

当你这样做的时候

App.Router.map(function() {
  this.resource('posts');
  this.resource('post', { path: '/posts/:post_id' });
});
Run Code Online (Sandbox Code Playgroud)

访问/ posts /:post_id时,帖子模板不会呈现

  • 来自http://emberjs.com/guides/routing/defining-your-routes/:您应该将this.resource用于表示名词的URL,将this.route用于表示修饰这些名词的形容词或动词的URL. (2认同)