mercredi 22 juin 2016

Actions sent from child route aftermodel hook aren't catched in parent route

Let me show you my configuration before explaning my problem. So here is an extract of my router :

Router.map(function() {
    [...]
    this.route('parent', {path: '/:parent_slug'}, function () {
        this.route('child', {path: '/:child_slug'});
    });
});

The parent route displays a component which need the parent_slug and optionally the child_slug. So in the child route afterModel() hook, I send an action to the parent route to update the child_slug it gives to the component.

In the child route :

afterModel(model) {
    [...]
    this.send('myAction', model.childSlug);
    [...]
}

In the parent route :

actions: {
    myAction(slug) {
        this.set('childSlug', slug);
    }
}

If I load the parent route first and then do a transition to the child route, the action will be sent and correctly catched by the parent but if I load the child route directly, the action is not catched. I tried to catch the action in the application route and it works.

So I guess that during the afterModel() hook of the childroute, the parents route actions aren't loaded yet.

Do you guys know if it's a bug or it's a normal behaviour ? I mean to start loading the child route before the parent one is completely loaded ?

Thank you !




Aucun commentaire:

Enregistrer un commentaire