0
votes

How do I get access to the params field from my index route that I created.

Here is my router.

export default Router.map(function() {
  this.resource('posts', function() {
    this.resource('posts.post', {path: ':id'}, function(){
      ...
      ...
      ...
    });
  });
});

When I go to /posts/1 and look at the ember inspector's view tree, I see for routes posts.post and posts.post.index both have {id: '1'} for their model.

In the posts.post route, I can do the following:

export default Ember.Route.extend({
  model: function(params){
    console.log('params.id = ' + params.id);
  },
});

This prints to the console params.id = 1.

However, when I run that same code in the posts.post.index route; params.id is undefined. As a matter of fact if I run JSON.stringify(params) it is empty.

How do I get access to the params form posts.post.index route. Ideally, I would like not to have to access the params from the posts.post route.

Any help would be greatly appreciated.

1

1 Answers

1
votes

You can get the model of another route with this.modelFor('posts.post').

Note that dynamic segments are only available to the route where they were defined. Wanting to access those from different routes is a bad smell.