Re-routing in a server-side rendered application


I posted this question on Stack Overflow already but maybe I wrote too much text or something. If this topic does not fit into this forum I apologize.

So I have this legacy web application built with the Yii PHP framework and I want to use Ember to improve functionality, reduce spaghetti JS and to replace multiple server-side rendered CRUD templates by stateful Ember templates and components.

My main concern is that I want to use Ember models and templates while keeping the routing logic in the JS loaded after the Ember application. We have an existing API for a few models that we want Ember to fetch. The pages the user loads have an unusable URL, though, so we have to somehow instruct the Ember app to load the cars/index controller on a given page using JS.

Let’s assume we are dealing with a index.php?r=cars/index JSON API that will get us all cars. And we can fetch index.php?r=cars/index_html that will output the list of cars as HTML, and load some assets including our Ember app.

Now, when I visit that page the Ember Inspector shows that I’m on IndexRoute but I cannot get IndexRoute to redirect to cars or cars/index so that the cars are actually fetched and the corresponding template is displayed.

What I need is some JS that will allow me to redirect to that controller or maybe you have an alternative way to integrate Ember into this legacy application, keeping all the EmberData functionality and that will not restrict me to using components like ember-islands does. (I could not get that to fetch the models either, and I want to keep templates for each REST action as well.)


well, I dont know how to do that, since i dont know your code. But what you need to do is just call transitionTo from the current route (in your case is IndexRoute). Maybe define an action on `IndexRoutethat calltransitionTo```, anywhere on your code should send an action to fire it, maybe on component.

Basically i dont like the concept of server-side rendered app like that, it’s too complex. My reccommandation is just tell the server side to render preloadData.