【问题标题】:Naming of Routes for nested resources in Ember.JSEmber.JS 中嵌套资源的路由命名
【发布时间】:2014-06-02 13:33:29
【问题描述】:

以下路由设置来自 Ember.JS 文档 (http://emberjs.com/guides/routing/defining-your-routes/),我必须处理一个等效问题:

App.Router.map(function() {
    this.resource('post', { path: '/post/:post_id' }, function() {
        this.route('edit');
        this.resource('comments', function() {
            this.route('new');
        });
    });
});

根据文档和我自己的经验,这会导致以下路径:

/post/:post_id/comments -> App.CommentsIndexRoute

但是,由于我想要一个特定于帖子的评论路线,我本来希望

/post/:post_id/comments -> App.PostsCommentsRoute

我的谬误到底是什么,我必须改变什么才能实现我的目标。

【问题讨论】:

    标签: javascript ember.js routes


    【解决方案1】:

    只有route 与他们的父母resource 分享他们的名字。如果您希望它显示为PostsCommentsRoute,它会更像这样(注意我将它复数以匹配您的示例,尽管 url 没有被复数)

    App.Router.map(function() {
        this.resource('posts', { path: '/post/:post_id' }, function() {
            this.route('comments');
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-04
      • 2019-10-18
      • 2013-01-16
      • 2013-01-31
      • 2015-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多