Emberjs: Accessing dynamic segment in nested routes/controllers

97 views Asked by At

I have nested routes like this:

  this.resource('profile', { path: '/:user' }, function(){
    this.route('followers');
    this.route('following');
  });

I need an access to the value of 'user' dynamic segment in my followers/following routes/controllers. One way I have figured out is to use

  this.controllerFor('profile').get('user')

inside my followers/following routes.

What is the correct way to do this?

Thanks,

1

There are 1 answers

0
Sam Selikoff On BEST ANSWER

I think you're looking for route#modelFor.

Example:

App.Router.map(function() {
    this.resource('post', { path: '/post/:post_id' }, function() {
        this.resource('comments');
    });
});

App.CommentsRoute = Ember.Route.extend({
    afterModel: function() {
        this.set('post', this.modelFor('post'));
    }
});