AngularJS:在重定向之前获取网址

我为所有错误的Urls定义了状态

.state('404',{ 
    url: '/404',data: { title: 'Page not found' },templateUrl: errorHandlerTemplate,parent: 'authenticated' 
})

我已设置重定向以使其正常运行

$urlRouterProvider.otherwise('/404');

我想获取用户在重定向发生之前尝试输入的原始网址。

$transitions.onBefore({ entering: '404' },function(trans) {
    console.log(trans.from().name);
    console.log(trans.to().name);
});

' trans.to()。name '似乎总是保留值'404',这是重定向后的最终网址。有没有办法获取被丢弃的原始网址?

wjw850329 回答:AngularJS:在重定向之前获取网址

$rootScope.$on('$stateChangeStart',function (event,toState,toParams,fromState,fromParams,options) {
    console.log(fromState,fromParams);
}
转换开始时会触发

$stateChangeStart

fromStatefromParams足以在重定向之前获取网址。

For more info on $stateChangeStart

本文链接:https://www.f2er.com/3140936.html

大家都在问