Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TransitionTo and the new Ember Router

The new ember router has been throwing me for a loop. Does anyone know how to manually triggering a url change when you are (1) NOT using a redirect in the router (2) NOT using the linkTo helper?

It seems that this:

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

no longer works, as of today's build.

like image 476
Han Avatar asked Jan 07 '13 20:01

Han


People also ask

Can you transition in Ember?

A Transition is a thennable (a promise-like object) that represents an attempt to transition to another route. It can be aborted, either explicitly via abort or by attempting another transition while a previous one is still underway. An aborted transition can also be retry() d later.

What is route in Ember?

This is the core feature of the Ember. js. The router used for to translate URL into the series of templates and also it represents the state of an application. The Ember. js uses the HashChange event that helps to know change of route; this can be done by implementing HashLocation object.


1 Answers

This seems hard to do in new ember router because ember is working hard to prevent you writing code in this style. Rather than access an instance of the router (or anything else) via App your ember application code should be working with properties that have been injected at runtime by the framework. As @sly7_7 mentioned above, your view will have access to the controller and controller can trigger a transition like:

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

Depending on how your third party library is working, you might do this by triggering an event in the dom (handled by the view) or by registering a callback when the view is rendered from within didInsertElement

The main thing to remember is that App.anything-in-lowercase is generally bad practice. Whenever possible try to let the framework take care of instantiating and wiring together your application classes.

For more detail, see the notes on this commit: https://github.com/emberjs/ember.js/commit/5becdc4467573f80a5c5dbb51d97c6b9239714a8

like image 106
Mike Grassotti Avatar answered Sep 21 '22 23:09

Mike Grassotti