【问题标题】:Nested routes in ember engine routes.js?ember 引擎 routes.js 中的嵌套路由?
【发布时间】:2018-10-21 05:06:04
【问题描述】:

ember 可路由引擎中如何定义嵌套路由?我无法导航到超过 2 棵树。像, 例如

All posts
 Post
   Comments
     Comment

我可以访问

localhost:4200/posts/:postid/

但是当我访问时

localhost:4200/posts/:postid/cmets/:commentid

它没有呈现 cmets 模板的内容。但它也没有显示任何错误。

【问题讨论】:

  • 你能分享router.js文件吗?

标签: ember.js ember-engines


【解决方案1】:

在您的终端中

$ ember g route posts
$ ember g route posts/post
$ ember g route posts/post/comments
$ ember g route posts/post/comments/comment

在您的 router.js 中,将内容替换为以下内容

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

这是一个解决方案,但我更喜欢的是,在每个主要路由中定义一个索引子路由,例如 ember g route posts/index 并将其添加到您的 router.js 中,如

this.route('posts', function() {
    this.route('index', {path: '/'});
    this.route('post', {path: '/:post_id'}, function() {
        .....
        .....
    });
});

每次添加索引子路由

【讨论】:

    猜你喜欢
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-10
    • 1970-01-01
    • 2014-12-19
    • 1970-01-01
    相关资源
    最近更新 更多