0
votes

I was wondering what the best practices around transition to another route in Ember. Currently in my controller, I call the ember data store then transition to another route using transitionToRoute function but with the new focus components these days I saw you an inject the router as a service inside your component. Is this where I should be moving this logic or controller is still right place for this?

2

2 Answers

5
votes

The best practice is to use Route for loading and mutating data as well as for transitions. Remember: data down, actions up.

https://guides.emberjs.com/v2.14.0/routing/

1
votes

Always best practice would be to use route. In case if you are forced to use transition in any other places may be in your smart component then you can use ember-router-service-polyfill addon.

ember install ember-router-service-polyfill

Then you can do inject router service and use transitionTo method.

import Ember from 'ember';

export default Ember.Component.extend({
  router: Ember.inject.service(),

  actions: {
    next() {
      this.get('router').transitionTo('other.route');
    }
  }
});