loading...

Ember route's actions during Transitions

sarath profile image sarathkumar ・2 min read

When i was working with the EmberJS webApp, i got struck with case where i was hit by the error Nothing handled the action 'alerthello'. πŸ˜”

Consider,

I have a alerthello action in the route named test.js and a controller named test.js with function triggerprinthello.

The controller part looks like:

test-controller

The route part looks like:

test-route

Is this the entire code ?, nope it’s just a sample (you may steal the code if i showed them πŸ˜‚)

You may think who the hell in the world would write such a script, well i am that guy.

Ok, let’s come to the point.

I tried to execute the above code, instead of showing the alert it throwed the error.

Then i dig into this thing, then i found something interesting (maybe πŸ€” to me).

You know what i found ? 😲

The thing is that the ember maintains a active route list (Based on which the bubbling happens). πŸ€”

When I transitioned from some Xroute to testroute ember won’t add the testroute in the active Route List until transition is completed.

In my case, setupcontroller will call the function triggerprinthello which in turn will search for the action alerthello in the active route list, since the testroute(still in transitioning state) is not yet listed in the Active route List, so it will bubble till the application route looking for the action (Ember: did you forget to add the action thinking about your girlfriend) and then boom πŸ’₯ it throws the error.

So, how did i solved this:

In two ways,

1) I handled the action in the controller itself.
2) I handled the action in the didTransition hook of the route. 😌

You may ask why did this crap is posted here, i thought this post might be somewhat helpful to others.

Also, please share your thoughts if i am wrong at something, so that i could correct myself 😊.

Discussion

pic
Editor guide
Collapse
rakchamp profile image
Ajith kannan

Tough to realise. But thanks for the approach ..Cheers