vendredi 2 janvier 2015

Ember.js child route's beforeModel fires before parent's route hands its model to its controller

I’ve got an application route which fetches current user in its model hook (and also sets it as the model). I’ve also got child routes that should transition to a login page if application controller’s model is null (i.e. user is not logged in). In these child routes I check if this.controllerFor(‘application’).get(‘model’) is null. Now, if the user is actually logged in, I see the following behavior. First, application route model hook works and returns a user is exptected. Then, a child route reports the user as null. And then an observer in application controller notices a model changing to an actual user. My question is: why would a child route’s beforeModel hook work before actual parent routes model change is propogated to its controller.


Everything works fine if I put the checks in child route’s setupController, but that triggers its model hook event if the route redirected, which is not nice at all.


Accessing modelFor('application') also does not work reliably.


Thanks





Aucun commentaire:

Enregistrer un commentaire