Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal engine routing problems on Ember 5.x #856

Open
LucasHillDex opened this issue Jan 31, 2024 · 5 comments
Open

Internal engine routing problems on Ember 5.x #856

LucasHillDex opened this issue Jan 31, 2024 · 5 comments

Comments

@LucasHillDex
Copy link

I'm having an issue due to the removal of route+controller transition methods in Ember > 5 (this.transitionTo etc). With those methods now unavailable, when we transition between engine routes inside of the engine, I'm not sure what API is available. The "engine router service" appears to have stalled out? Is there another way? #779
If you inject the host router via https://ember-engines.com/docs/deprecations#-use-alias-for-inject-router-service-from-host-application it is routing in the context of the host app not the engine and won't work for transitioning purely within the engine routes.

@SergeAstapov
Copy link
Contributor

@LucasHillDex shouldn't this.router.transitionTo() just work? this.hostRouter.transitionTo() per https://ember-engines.com/docs/deprecations#-use-alias-for-inject-router-service-from-host-application yes would do transition in the context of the host app.

@LucasHillDex
Copy link
Author

LucasHillDex commented Feb 7, 2024

@LucasHillDex shouldn't this.router.transitionTo() just work? this.hostRouter.transitionTo() per https://ember-engines.com/docs/deprecations#-use-alias-for-inject-router-service-from-host-application yes would do transition in the context of the host app.

@SergeAstapov Being that this is the host router you would need to provide the entire qualified route, including any part of the host app's parent route to the mounted engine. This breaks the encapsulation of the engine, and wouldn't work in one app where the engine is mounted in a different path than in another.

Imagine I have two engine routes called 'posts' and 'comments'. In ember 4.x and below, we could be in the 'posts' engine route and call this.transitionTo('comments'). Post 5.0 given those APIs are gone, if we use the host's router, we'd have to call something like this.router.transitionTo('home.engine.comments'), but what if in another app the engine is mounted under a completely different parent route or mount name?

@LucasHillDex
Copy link
Author

@SergeAstapov I came up with a minimal example to demonstrate the issue we're having: https://github.com/LucasHillDex/engine-routing

This is a simple routable engine addon. It has two routes, "first" and "second". In the beforeModel hook of "first" we want to transition to "second". I have illustrated the way would would use the old APIs to transition from one engine route into another. This does not seem possible now without knowing the structure of the host/parent app of the engine if you are using the inject host's router service. See: https://github.com/LucasHillDex/engine-routing/blob/main/addon/routes/first.js

I don't think this is an unusual use case or is it? Is there another supported way to do internal engine routing?

@LucasHillDex
Copy link
Author

@SergeAstapov I don't think I addressed your response properly, ember-engines does not allow you to inject the plain 'router' service anymore, as I believe that was still just the host's router (is that wrong?). Which is why it was made that you had to explicitly do it like: https://ember-engines.com/docs/deprecations#-use-alias-for-inject-router-service-from-host-application

See the example here for what happens when you try to just use the plain router service in an engine route. https://github.com/LucasHillDex/engine-routing/blob/main/addon/routes/first.js#L5

@brettburley
Copy link
Contributor

@LucasHillDex have you seen https://github.com/villander/ember-engines-router-service? This addon preserves the encapsulation you're looking for when routing via service within an engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants