Inject EmberJS Router into Components - 31 Jan 2016

If you find the need to change routes in a component action, then you’ll need access to the router. Here’s a quick example of an initializer that will inject the router into your components.


  export function initialize(application) {
    application.inject('component', 'router', 'router:main')

  export default {
    name: 'component-routes',

You can then access the router in your components like such:

  get(this, 'router').transitionTo('dashboard')