'transitionToExternal' from Component : Ember Engines

Hi, I’m using Ember Engines. How to make a transition to external route from inside the component? Currently router instance 'Ember.getOwner(this).lookup(‘router:main’) ’ seems it doesn’t have transitionToExternal function.

Looked into the discussion ‘https://github.com/ember-engines/ember-engines/issues/260’ but not helpful.

Edit: the workaround, as suggested in above link like getting external route using ‘_getExternalRoute’ function of router service and then using the ‘transitionTo’ function of router service, is working fine. kindly post if any other solutions are available.

You can use the router service (maybe via polyfill if you run an older version of Ember) and pass it down from the parent app to the engine, via a service dependency. You can then inject this router service into your component and transition wherever you want. Better yet, do this transition in an action in a route and pass this action down into the component.

2 Likes

to build on @martinmalinda, here is the documentation for the routing service.

(not sure what version you’re using but it hasn’t changed much if you’re using a version that supports it)

1 Like

Another way to do this is to use the bind helper https://github.com/Serabe/ember-bind-helper to use transitionTo directly from the router service. Or create a dedicated service that uses the router service and defines actions that handle transitions specific to your app, e.g. onclick={{action 'go' target=navigationService}}.