角 - UI的路由器获取previous状态 [英] Angular - ui-router get previous state
问题描述
有没有办法来获得当前状态的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屋!