获取当前正在转换到的状态的名称

Get the name of the state that is currently being transitioned to

在我的某些状态解析中,我正在检查以确保用户已登录,如果他们没有登录,我会将他们重定向到登录状态。登录后,我想重定向回他们打算访问的原始状态。

我的问题是:如何从解析函数中获取当前正在转换到的状态的名称(以便我可以存储它并在登录后转换到它)?

我查看了 $state 的文档,我所能找到的只是 $state.transition,但这不包含任何有用的信息。

您是否需要在 resolve 函数中处理它?

通常这种 activity 会在 stateChangeStart 事件中处理...

$rootScope.$on('$stateChangeStart', 
function(event, toState, toParams, fromState, fromParams){ 
    event.preventDefault(); 
    // transitionTo() promise will be rejected with 
    // a 'transition prevented' error
})

(来自 github wiki:https://github.com/angular-ui/ui-router/wiki and the API docs: http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state)

您可以将 toState 存储在服务中,直到成功登录后更改为请求的状态。