Search code examples
javascriptember.jsroutesbrowser-history

Ember: change route event from outside the app


Here is the context. I'm developing an Ember app, that will be embed in a Drupal page. Only problem: the menu of the app must be in the drupal page.

So I'm trying to find a way to update the url of the page (from outside the app) and to get the event of changing url inside Ember so I can then apply the route as usual.

I tried:

  • history.pushstate(). But it doesn't trigger "popstate" so I can't really get any callback.
  • use "hash" url type in ember config, and then get the hashchange event from inside Ember. It works but I'd like to use the "history" url type

I have to try:

  • in Ember app, get the click event on the outside menu, and apply my routes. (But it doesn't seem like a really clean solution, does it ?)

Any ideas I can get to do that ?

Thanks for your help !

Config:

  • Ember : 1.13.7
  • Ember Data : 1.13.8
  • jQuery : 1.11.3

Solution

  • I think most people will advise against doing something like this, Ember really isn't built to be smaller portions of your app controlled from the outside and doesn't provide any methods for doing so.

    Dispatching a custom event that Ember is listening for might be the least gross way to go about it if you absolutely have to do this. You could pass the route name via event.detail from the custom event and then use this.transitionTo(event.detail).