gpt4 book ai didi

AngularJS ui-router 登录后重定向

转载 作者:行者123 更新时间:2023-12-02 11:29:26 26 4
gpt4 key购买 nike

我有一个使用 AngularJS 和 ui-router 的项目。除了第一次加载时从登录屏幕重定向到预览状态之外,一切正常。

默认状态是家 - http://test/#/

例如,如果用户未登录 - http://test/#/test/1000/details进入登录页面(这是应该做的)

用户登录后,系统进入默认状态“home - http://test/#/”,但我想转到http://test/#/requests/1000/details

如何保存“http://test/#/requests/1000/details或stateName”以在登录后重定向?

我尝试使用 $stateChangeSuccess$rootscope 中保存状态日志,但第一个状态日志 ( http://test/#/requests/1000/details ) 永远不会被保存。

有什么想法如何处理这个问题吗?

谢谢。

最佳答案

您可以在主应用程序的运行方法中向 $state 添加“前一个”属性。

这就是我解决问题的方法:

// add ui-router variables to $rootScope. Comes handy in many cases, for example setting page title
angular.module('app').run(['$rootScope', '$state', '$stateParams', addUIRouterVars]);

function addUIRouterVars($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;

// add previous state property
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState) {
$state.previous = fromState;
});
}

关于AngularJS ui-router 登录后重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27405101/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com