The route i came from, or previous route
Asked Answered
N

1

3

When i visit one route and then go to another, is where a way to know which route i came from?
I tried document.referrer - this doesn't work. Googling hadn't brought any answers either..

I set up this fiddle for example and testing..

Neurath answered 12/2, 2013 at 11:38 Comment(0)
S
4

There is no direct solution using the API. Meaning, this information is not part of the public API. However, you can cache this information yourself.

App.set('lastRoutes', []);

App.BaseRoute = Ember.Route.extend({
    setupController: function() {
        this._super.apply(this, arguments);
        App.get('lastRoutes').pushObject(this.get('routeName'));
    }
});

Use "setupController", rather than "enter", because when you transition from /users/1 to /users/2 for instance, the enter/exit methods are not executed, whereas the setupController gets executed every time (and is part of the public API). You should refine it if you have nested routes, because this will add the intermediate routes as well. But for your example, it works well.

Studdard answered 12/2, 2013 at 11:55 Comment(1)
I was hoping that there is something in Ember API, but seems that you are right.. Thanks a lot!Neurath

© 2022 - 2024 — McMap. All rights reserved.