TransitionTo and the new Ember Router

The new ember router throws me in a loop. Does anyone know how to manually initiate a URL change when you (1) DO NOT use redirection in the router (2) NOT using the linkTo helper element?

It seems like this:

App.container.lookup('router:main').router 

no longer works, builds today.

+6
source share
2 answers

This seems hard to do in the new Ember router, because the coal works hard to prevent you from writing code in this style. Instead of accessing the router instance (or anything else) through the App , your ember application code should work with properties that were injected into the runtime. As @ sly7_7 mentioned above, your view will have access to the controller, and the controller can trigger a jump, for example:

 view.get('controller').transitionTo('state') 

Depending on how your third-party library works, you can do this by triggering an event in dom (handled by the view) or by registering a callback when the view is displayed from didInsertElement

The main thing to remember is that App.anything-in-lowercase is usually a bad practice. Whenever possible, try to ensure that the infrastructure takes care of creating and combining your application classes.

See the notes for this commit for more details: https://github.com/emberjs/ember.js/commit/5becdc4467573f80a5c5dbb51d97c6b9239714a8

+3
source

You can try the following:

 App.__container__.lookup('router:main').transitionTo('name_of_your_route'); 
0
source

All Articles