Returning to previous route with model reload



I’m currently having a problem that sounds like it should have a more or less easy solution but I haven’t found it yet.

In my Ember-App, you can create a new task from every route. I then go to the TaskCreateRoute, and when I save a task I want to go back to the route where I was before, or to the index route if I started at the TaskCreateRoute.

I solved this via updateCurrentPath in my ApplicationController, where I add an entry to an array like this:

  route: currentPath,
  id: pathId

And then I have a function gotoPrevious which sends me to the previous route (simplified):


(There are some other checks being made if no lastPage exists, but they work fine so far, so that’s not the problem).

However, if I start, for example, in a list view where all tasks are displayed, then create a new task and return there, the just created task is not in the list. Now I think the appropriate thing to do would be to call Route.refresh() - but I don’t know how to get the corresponding route object from the ApplicationController.

To clarify things, here is the basic structure:

App.ApplicationController = Ember.Controller.extend({
  updateCurrentPath: function() { ... },
  actions: { 
     gotoPrevious: function () { ... }

All other controllers have needs: [“application”], and I use it like for example in the TaskCreateController: {

I really don’t know how to handle this now - I think that this use case is quite common, and to be honest I think that Ember should provide some kind of built-in “back” mechanism. Hopefully, somebody can guide me in the right direction!


Yeah, this is most likely quite late already to reply. However, maybe creating a Mixin would help. Something like that:

… Ember.Mixin.create({ lastRoutes: [] });

Then, you can use/import that mixin in your routes that need to store its routeName. For example, inside the route’s setupController() hook push/save this.get(‘routeName’) into the Mixin’s lastRoutes accessible via this.get(‘lastRoutes’). After that, access lastRoutes inside your controller where the previous route needs to be known. Something like that