0

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

All posts
 Post
   Comments
     Comment

我可以访问

本地主机:4200/posts/:postid/

但是当我访问

本地主机:4200/posts/:postid/comments/:commentid

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

4

1 回答 1

0

在你的终端

$ 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() {
        .....
        .....
    });
});

每次添加一个索引子路由

于 2018-10-25T11:20:58.427 回答