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

Adding routes at runtime no longer works #10979

Closed
yosoyju opened this issue Apr 28, 2015 · 10 comments
Closed

Adding routes at runtime no longer works #10979

yosoyju opened this issue Apr 28, 2015 · 10 comments

Comments

@yosoyju
Copy link

yosoyju commented Apr 28, 2015

Issue #2892 allowed new routes to be added at runtime. This appears to no longer function in 1.11.3 or 1.12.0 beta 1.

@rwjblue
Copy link
Member

rwjblue commented Apr 28, 2015

Can you provide a reproduction? The tests added in that pull request are all passing, so I'm not sure how this is failing without a repro.

@yosoyju
Copy link
Author

yosoyju commented Apr 29, 2015

Here is a JSBin running in Ember 1.10.0. Wait two seconds, then click the Foo link. The Bar link is there.

http://emberjs.jsbin.com/cogofekuho/2/

Here is the same JSBin running 1.11.3. Clicking the link never shows the Bar link because the route is seemingly never registered.

http://emberjs.jsbin.com/kilevi/1/

@honbo
Copy link

honbo commented May 2, 2015

Seeing this as well after upgrading to Ember 1.11. Router.map can still be called multiple times, but the actual router instance isn't being remapped when that happens. The tests in the aforementioned commit aren't failing because the second call to Router.map is still happening before app initialization (which IMO doesn't reflect the spirit of the enhancement--in practice the second call to Router.map would happen after initialization).

As a temporary workaround I have resorted to mimicking some of the behavior of _initRouterJs after calling Router.map to at least have my new routes recognized:

r = App.registry.lookup('router:main')
cb = r.constructor.dslCallbacks
dsl = new Ember.RouterDSL null,
    enableLoadingSubstates: false
generateDSL = ->
    @resource 'application', { path: "/", overrideNameAssertion: true }, ->
        b.call @ for b in cb
generateDSL.call dsl
r.router.map dsl.generate()

@rwjblue
Copy link
Member

rwjblue commented May 2, 2015

To be honest, I was not aware that we supported lazily defining routes (after app initialization). I'll try to confirm with the rest of the core team, and see if it was intended as a public API.

@yosoyju
Copy link
Author

yosoyju commented May 21, 2015

Is there any update to this?

@rwjblue
Copy link
Member

rwjblue commented Apr 14, 2016

At this point, I would say that dynamically adding more routes after router initialization is not supported.

Sorry for keeping this issue open so long...

@rwjblue rwjblue closed this as completed Apr 14, 2016
@sdhull
Copy link

sdhull commented Sep 22, 2017

Hah I just posted in discuss.emberjs.com about this ... I guess (for now) I'll try @honbo's hack above and see if that works still (hopefully still works 2 yrs later 😬 )

@sdhull
Copy link

sdhull commented Sep 22, 2017

uhhh trying to reproduce your success @honbo ... in your snippet, it's adding the 'application' route right?

@sdhull
Copy link

sdhull commented Sep 22, 2017

Ohhhh you run that snippet after calling Router.map again at runtime, right?

@sdhull
Copy link

sdhull commented Sep 22, 2017

OK got some deprecation warnings but it works! 🎉
Thanks @honbo ❤️

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

4 participants