Why is it not possible to trigger the `model` hook via `link-to` helper?

If you transition to a route and all the context objects -the objects which will serve as models to templates- are passed in, the beforeModel and model hooks will not be called. I think it makes a lot of sense, if the model is already known why should the framework fetch it again? (potentially firing an XHR request). There are several ways to pass in the context objects, the link-to helper and route.transitionTo come to mind.

All the other hooks (afterModel, setupController, renderTemplate, did I miss something?) will always be fired, no matter how you transitioned to the route.

I don’t think there is a way, the setupController always gets called, with the controller and the resolved model as parameters. That said, I don’t think you need that. Transitioning between routes via link-tos does change the url and so going back and forth between them (and bookmarking) just works.

BTW, there is a much simpler way to define your routes:

App.Router.map(function () {
 this.resource('calendar', function () {
    this.route('day', {path: '/day/:user_id/:date'});
    this.route('week', {path:'/week/:user_id/:date'});
  }
});

None that I know of, and it would be good to have it. Routing is hard to grasp in Ember but is one of the key points and the more you understand it, the more you love it, at least that’s what’s happening to me :slight_smile: So don’t be discouraged, there is a lot more way to go, but the journey is worthwhile!

1 Like