Inject Route actions from within Ember Addon


#1

Is there any better way for handling this instead of dirty workaround using ApplicationRoute._actions


#2

You can use reopen.

Add this initializer to your ember-cli addon project:

app/initializers/add-action-to-application-route.js

import Ember from 'ember';
export default {
    name: 'add-action-to-application-route',
    initialize: function(container, app){
        Ember.run.next(function(){
            var applicationRoute = container.lookup('route:application');
            if (applicationRoute && typeof applicationRoute.reopen === 'function'){
                applicationRoute.reopen({
                    actions: {
                        doMore: function(){
                            //doing More
                        }
                    }
                });
            }
        });
    }
};

Existing actions won’t be overridden.

JS Bin Demo


#3

Holly smokes! This indeed did the trick.

Thank you so much @ramybenaroya

Is there any particular reason you need to Ember.run.next()


#4

Without the run.next The lookup method returned undefined.