TommyLike
TommyLike

Reputation: 1018

ember route pass dynamic url to child route

if I have defined routes below:

App.Router.map(function () {
    this.resource('user', {path: "/:user"}, function () {
        this.route('work', {path: "/work"});
    })
});

I can get the :user value in user controller,but How can I get this value in my work controller or work route?

Upvotes: 0

Views: 91

Answers (2)

Patsy Issa
Patsy Issa

Reputation: 11293

You can set it on the controller from the work route in the setupController hook:

setupController(controller) {
  controller.set('userId', this.modelFor('user').get('id'));
  return this._super(...arguments);
}
// ES < 6 syntax
setupController: function(controller) {
  controller.set('userId', this.modelFor('user').get('id'));
  return this._super.apply(this, arguments);
}

Upvotes: 0

artych
artych

Reputation: 3669

You could use modelFor in route and set user controller property in model (or beforeModel, afterModel) hook: http://emberjs.com/api/classes/Ember.Route.html#method_modelFor

//work route
model: function() {
  return Ember.RSVP.hash({
    user: this.modelFor('user'), // here user is routeName
    work: // your logic here
  });
},

setupController: function(controller, models) {
  controller.setProperties(models);
}

Upvotes: 2

Related Questions