Skip to content

Instantly share code, notes, and snippets.

@MiguelMadero
Created September 25, 2016 17:15
Show Gist options
  • Save MiguelMadero/3cd0cd4e8559335c73d412835e36c2e6 to your computer and use it in GitHub Desktop.
Save MiguelMadero/3cd0cd4e8559335c73d412835e36c2e6 to your computer and use it in GitHub Desktop.
// initializers/x-routing-service.js
export default {
name: 'x-routing-service',
initialize: function(container, application) {
application.inject('service:routing', 'router', 'router:main');
application.inject('service:routing', 'applicationController', 'controller:application');
}
};
// services/routing.js
import Ember from 'ember';
export default Ember.Service.extend(Ember.Evented, {
// NOTE: dependencies injected via initializer
// applicationController: Ember.inject.controller('application'),
// router: injected('router:main')
currentRouteName: Ember.computed.alias('applicationController.currentRouteName'),
currentPath: Ember.computed.alias('applicationController.currentPath'),
currentRouteSegments: function () {
return this.get('currentPath') ? this.get('currentPath').split('.') : [];
}.property('currentPath'),
transitionTo () {
var router = this.get('router');
router.transitionTo.apply(router, arguments);
},
replaceWith () {
var router = this.get('router');
router.replaceWith.apply(router, arguments);
},
_subscribeToRouterEvents: function () {
let router = this.get('router');
router.on('willTransition', () => this.trigger('routeWillChange'));
router.on('didTransition', () => this.trigger('routeDidChange'));
}.on('init')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment