The route i came from, or previous route

跟風遠走 提交于 2019-12-06 04:25:04

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!