Ember transitionToRoute cleanly in a component without sendAction

前端 未结 5 2071
悲&欢浪女
悲&欢浪女 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:44

    If you want to use the router only in a specific component or service or controller, you may try this:

    Initialize an attribute with the private service -routing. The - because it's not a public API yet.

    router: service('-routing'),
    

    And then inside any action method or other function inside the service or component:

    this.get('router').transitionTo(routeName, optionalParams);
    

    Note: It'll be transitionToRoute in a controller.

提交回复
热议问题