Sam
Sam

Reputation: 4339

Nested routes in Ember

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.

Upvotes: 1

Views: 51

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

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'});
        });
    });
});

Upvotes: 2

Related Questions