Ember transitionToRoute cleanly in a component without sendAction

前端 未结 5 2078
悲&欢浪女
悲&欢浪女 2020-12-28 15:09

How can transitionToRoute be called cleanly from within an Ember component?

It works with injecting a controller into the component and calling the cont

5条回答
  •  暖寄归人
    2020-12-28 15:59

    Jan 22, 2018 update
    As of Ember 2.15, phase 1 of the public router service is implemented.
    Transition to a route from inside a component:

    import { inject as service } from '@ember/service';
    
    export default Ember.Component.extend({
      router: service(),
    
      actions: {
        someAction() {
            this.get('router').transitionTo('index');
        }
      }
    
    });
    

提交回复
热议问题