Based on the Mudasi Ali guide and analyzing the source of Ember v1.5, I use the following:
Coffeescript (use coffeescript.org for forwarding if you want JS / ES):
Ember.Route.reopen parentRoute: Em.computed -> r = @router.router if r.currentTransition handlerInfos = r.currentTransition.state.handlerInfos else handlerInfos = r.state.handlerInfos handlerInfos = this.router.router.state.handlerInfos return unless handlerInfos parent = @ for info in handlerInfos break if info.handler == @ parent = info.handler parent parentRouteName: Em.computed.alias('parentRoute.routeName') parentController: -> @controllerFor @get('parentRouteName') parentModel: -> @modelFor @get('parentRouteName')
The above parentRoute and parentRouteName on all your routes and two convenient functions parentController() and parentModel() , which return the parent controller and model, respectively, which can be useful in many situations, especially if you represent editing the resource as a nested route .
You can also define some actions to use in your views / controllers, etc. to cancel / reverse control as follows:
Ember.Route.reopen actions: goBack: -> @transitionTo @get('parentRouteName')
If you have a deep routing hierarchy and want to say skip the intermediate route, you just need to override goBack as follows:
App.SomeIntermediateRouteToSkipOnBack = Em.Route.extend actions: goBack: ->
source share