Angular - ui-router 获取之前的状态 [英] Angular - ui-router get previous state

查看:33
本文介绍了Angular - ui-router 获取之前的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获取当前状态的前一个状态?

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

例如,我想知道当前状态 B 之前的前一个状态是什么(前一个状态是状态 A).

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-router github 文档页面中找到它.

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

推荐答案

ui-router 一旦转换就不会跟踪之前的状态,但是 $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.

您应该能够从该事件中捕获先前的状态(from 是您要离开的状态):

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

这篇关于Angular - ui-router 获取之前的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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