简体   繁体   English

在ember引擎route.js中嵌套路由?

[英]Nested routes in ember engine routes.js?

How to define nested routes in ember routable engine? 如何在ember可路由引擎中定义嵌套路由? I can't navigate to beyond 2 trees. 我无法导航到超过2棵树。 Like, For example 像,例如

All posts
 Post
   Comments
     Comment

I can access 我可以访问

localhost:4200/posts/:postid/ 本地主机:4200 /职位/:帖子ID /

But when I access 但是当我访问

localhost:4200/posts/:postid/comments/:commentid 本地主机:4200 /职位/:帖子ID /评论/:commentid

Its not rendering the content for comments template. 它不呈现评论模板的内容。 But it doesn't show any error either. 但这也没有显示任何错误。

In your terminal 在您的终端

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

In your router.js, replace the contents by the following 在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'});
            });
        });
    });
});

This is a solution, But what I prefer is , define an index sub-route in every main routes, for example ember g route posts/index and add it into your router.js like 这是一个解决方案,但是我更喜欢在每个主要路由中定义一个索引子路由,例如ember g route posts/index并将其添加到您的router.js中,例如

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

add an index sub route every time 每次添加索引子路由

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM