I know that I can use nested routes which don’t render the parent routes, if I don’t use
templates/myRoute.hbs , but
templates/myRoute/index.hbs. However, this leads to another issue:
routes/index.hbs I use the setupController method, to set a value on the controller, I end up with the controller for
controllers/myRoute.js instead of
controllers/myRoute/index.js (which I would actually need). So, I could work around that by manually retrieving the right controller, or using a different way to set up the controller, but both seem rather cumbersome.
I tried to setup all the routes, controllers and templates to use the
*/myRoute/index.js|hbs pattern, however this just leads to the params in the route:model(params) function being undefined…
Is there a clean way to render a template without rendering the parent nested templates and still being able to access that controller from setupController() in the route?
I know that I can use nested routes which don’t render the parent routes,
This is incorrect, if a nested route is rendered, then the parent route must also be rendered too.
Those routes are different things - the index route is a completely different route to the parent route.
You should implement the setupController hook on the route that you want to use it on, not on a different route.
Agreed. I should have been writing that the parent templates are not rendered instead of the route.
I wish I could be just using the correct route, however I came across the implications mentioned above. If I don’t use the index routes+templates, parent templates are required to be rendered (unless I am missing something). If I use index routes and templates, ember does not provide the Params in the route, hence I lose the information about the id of the current resource (and fail to get the model). If I mix both non-index route and index controller/template, I have access to all the data and behavior I need, but setup gets quite messy. It feels like I am trying to fight the ember conventions, but can’t find a way to avoid that.
Edit: I have noticed that in most cases I am able to get the corresponding model in the index route by calling
this.modelFor('myModel'). Still this feels rather cumbersome…