Ember transitionToRoute cleanly in a component without sendAction

前端 未结 5 2090
悲&欢浪女
悲&欢浪女 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条回答
  •  猫巷女王i
    2020-12-28 16:08

    Use router: service()

    instead of router: service('-routing')

    import Component from '@ember/component';
    import {inject as service} from '@ember/service';
    
    export default Component.extend({
      router: service(),
    
      actions: {
        onClick(params) {
          let route = this.getMyRoute(params);
          this.get('router').transitionTo(route);
        }
      }
    });
    

提交回复
热议问题