transitionToRoute('route') From Inside Component

后端 未结 6 1179
逝去的感伤
逝去的感伤 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:30

    I've written this answer for another similar question.

    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.

    Link to question: Ember transitionToRoute cleanly in a component without sendAction

    Link to answer: https://stackoverflow.com/a/41972854/2968465

提交回复
热议问题