Git Product home page Git Product logo

Comments (7)

SergeAstapov avatar SergeAstapov commented on September 26, 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.

from ember-engines.

LucasHillDex avatar LucasHillDex commented on September 26, 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?

from ember-engines.

LucasHillDex avatar LucasHillDex commented on September 26, 2024

@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?

from ember-engines.

LucasHillDex avatar LucasHillDex commented on September 26, 2024

@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

from ember-engines.

brettburley avatar brettburley commented on September 26, 2024

@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.

from ember-engines.

LucasHillDex avatar LucasHillDex commented on September 26, 2024

@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.

I ended up finding my own workaround but that addon looks useful (hate to add another addon though that might not get updates in the future). I think it would be good for the engines team to really look into the routing issues and either document it better if solutions exist or explore improving the API.

from ember-engines.

void-mAlex avatar void-mAlex commented on September 26, 2024

Hello @LucasHillDex
we're working tightly with the ember routing work to make sure engines are better supported going forward out of the box

would love to know what workaround you found for the issue you were having
for now the recommendation is to use the addon routing service for engines until a transition path is built towards new routing

from ember-engines.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.