如何在AngularJS中检索以前的URL [英] How can I retrieve the previous URL in AngularJS
本文介绍了如何在AngularJS中检索以前的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以使用$location.search()
和$location.path()
获取当前URL,但是我需要一种获取前一个URL的方法.我可以使用全局变量或类似的东西吗?
I know I can get the current URL using $location.search()
and $location.path()
but I need a way to get previous one. Can I use a global variable or something like that?
推荐答案
Angular $rootScope
将包含所有应用程序组件中的所有信息.
Angular $rootScope
will have the all information across your all app components.
在$rootscope
上插入$location
服务的下面将为您提供路线信息.
Here below $location
service injected on $rootscope
will give you the route information.
$rootScope.$on('$locationChangeStart', function (event, current, previous) {
console.log("Previous URL" +previous);
});
这篇关于如何在AngularJS中检索以前的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文