如何在AngularJS中检索以前的URL [英] How can I retrieve the previous URL in AngularJS

查看:75
本文介绍了如何在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屋!

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