I have an existing traditional application with server-side rendering. I’d like to eventually replace the front-end completely with an application written in Ember.JS. However such a rewrite won’t happen overnight and in the interim there will be a situation where we have to combine both applications.
I’m currently working out the following setup;
+-----------------_Layout.cshtml----------------+
|+----------------_TopMenu.cshtml--------------+|
||Link 1 | Link 2 | Ember Link 1 | Ember Link 2||
|+---------------------------------------------+|
|+------------------Ember.cshtml---------------+|
|| <script src="assets/my-app.js" /> ||
|| <script src="assets/vender.js" /> ||
||+---------------application.hbs-------------+||
||| |||
||| |||
||| |||
||+-------------------------------------------+||
|+---------------------------------------------+|
+-----------------------------------------------+
Thus, inside the existing application there will be a page embedding the Ember application. My question has to do with integrating both applications: how to deeplink between them?
In the top menu navigation there are two navigation items, when clicked they will open a different URL and ember will start loading the appropriate view, according to the router definition. However instead of re-loading Ember when going from “Ember Link 1” to “Ember Link 2”, I’d like to “stay within Ember” and not have the browser actual reboot the Ember application.
My first attempt at doing this is hooking into the router:
$("a:not(.ember-view)").on('click', function (event) {
event.preventDefault();
var url = this.pathname + this.search + this.hash;
window.MyApp.__container__.lookup("router:main").router.transitionTo(url).then(
function (transition) { /* succes */ },
function (transition) { /* no such view in Ember, redirecting browser */ location.href = url; }
);
});
While this does work for debug builds, it feels hacky and doesn’t work in production (see my other topic for details). Also the “active” state of {{#link-to}}
helpers is not correctly reflected when a navigation is triggered by the code above. From the documentation, I can’t seem to find some guide on how to integrate ember into an existing application, so would really like to know how to achieve this.