Nested routes in Ember

泄露秘密 提交于 2020-01-05 09:35:19

问题


I want my settings area to look like this:

..
/settings/:accountId/users
/settings/:accountId/users/:userId

I have my router defined as follows:

Router.map(function() {
    this.route('login');
    this.resource('settings', { path: 'settings/:settings_id' }, function() {
        this.route('overview');
        this.route('users');
    });
});

This works for displaying the users listing page. I'm not sure how to take it to the next step though and have both a route and a resource for /users and /users/1.

Thanks.


回答1:


In the latest versions of Ember, route's can have sub routes (for namespace sake).

Router.map(function() {
    this.route('login');
    this.resource('settings', { path: 'settings/:settings_id' }, function() {
        this.route('overview');
        this.route('users', function(){
          this.route('user', {path:':user_id'});
        });
    });
});

http://emberjs.jsbin.com/cutayuniga/1/edit?html,js,output

If you're in an older version, you will have to make users a resource.

Router.map(function() {
    this.route('login');
    this.resource('settings', { path: 'settings/:settings_id' }, function() {
        this.route('overview');
        this.resource('users', function(){
          this.route('user', {path:':user_id'});
        });
    });
});


来源:https://stackoverflow.com/questions/27737960/nested-routes-in-ember

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!