Routing as a service?


#1

I am implementing some relatively complicated modal components. One of the things I’d like to do is depending on the state of the modal, have the url transition (and hence the background UI transition). Currently I am putting all my “transition needs” into an “Evented” service, and have application route monitor the service. Whenever application route observes a “transition” event fired from the service, it will do the transition. The user level api looks like the following

export default Ember.Component.extend({
  routing: Ember.inject.service(),

  someFunc(model) {
    this.get('routing').transitionTo('blog', model);
  }
});

It would be awesome if this is built into Ember, especially considering we are about to remove controllers. Once controller is removed, the only thing that can transition is Route, which is not very accessible from components or services.

What do you guys think?


#2

Btw, I made this into an addon. You can try it out:

https://www.npmjs.com/package/ember-cli-routing-service


#3

also there is a private routing service in ember

routing: Ember.inject.service('-routing')

#4

Super awesome! Wonder how much more of Ember’s awesomeness is buried in the RFC.