角 - UI的路由器获取previous状态 [英] Angular - ui-router get previous state

查看:124
本文介绍了角 - UI的路由器获取previous状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法来获得当前状态的previous状态?

Is there a way to get the previous state of the current state?

例如我想知道previous状态是当前状态B(其中previous状态本来状态的)之前。

For example I would like to know what the previous state was before current state B (where previous state would have been state A).

我无法找到它的UI路由器GitHub的文档页面。

I am not able to find it in ui-router github doc pages.

推荐答案

UI的路由器不跟踪previous状态一旦转换,但该事件 $ stateChangeSuccess 上广播 $ rootScope 时的状态变化。

ui-router doesn't track the previous state once it transitions, but the event $stateChangeSuccess is broadcast on the $rootScope when the state changes.

您应该能够从该事件赶上前状态(是你要离开状态):

You should be able to catch the prior state from that event (from is the state you're leaving):

$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
   //assign the "from" parameter to something
});

这篇关于角 - UI的路由器获取previous状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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