我来自或之前的路线 [英] The route i came from, or previous route

查看:76
本文介绍了我来自或之前的路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我访问一条路线然后去另一条路线时,是否知道我来自哪条路线?

我尝试过 document.referrer - 这不行。谷歌没有提出任何答案..

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..

推荐答案

没有使用API​​的直接解决方案。意思是说,这个信息不是公共API的一部分。
但是,您可以自行缓存此信息。

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'));
    }
});

使用setupController而不是enter,因为当您从/ users / 1转换到/ users / 2例如,enter / exit方法不执行,而setupController每次都被执行(并且是公共API的一部分)。
如果您有嵌套路由,您应该优化它,因为这样也会添加中间路由。但是对于你的例子,它的效果很好。

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.

这篇关于我来自或之前的路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆