transitionToRoute('route') From Inside Component

后端 未结 6 1178
逝去的感伤
逝去的感伤 2021-01-04 02:18

How do I transition to a route pragmatically from inside a component action?

I tried to use @get(\'controller\').transitionToRoute(\'images\'

6条回答
  •  盖世英雄少女心
    2021-01-04 02:41

    Create action on parent controller.

    export default Ember.Controller.extend({
      actions: {
        transInController() {
           this.transitionToRoute('home')
        }
      }
    });
    

    Specify this action on component call.

    {{some-component transInComponent=(action "transInController")}}
    

    AFTER v3.4.0 (August 27, 2018)

    some-component.js

    export default Component.extend({
      actions: {
          componentAction1() {
              this.transInComponent();
          }
      }
    });
    

    OR simpler in some-component.hbs

    
    

    BEFORE v3.4.0

    Ember.component.sendAction

    "Send Action" from component up to controller

    export default Ember.Component.extend({
      actions: {
          componentAction1() {
              this.sendAction('transInComponent');
          }
      }
    });
    

提交回复
热议问题