AngularJS如何获取URL引荐来源网址

AngularJS如何获取URL引荐来源网址

本文介绍了AngularJS如何获取URL引荐来源网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AngularJS中,我有一个登录控制器,如果用户到达该页面且未登录,则该应用程序中的每个页面都将其重定向到该控制器.登录顺序之后,我想将用户重定向至他们来自的页面.最好的方法是什么?

In AngularJS, I have a login controller that is redirected to by every single page in the app if the user arrives at the page and is not logged in. After the login sequence, I would like to redirect the user back to the page that they came from. What's the best way to do this?

推荐答案

您可以使用history.back()来使用户导航到他之前的页面.在每种情况下都可以使用,除非用户直接导航到登录页面:)

You can use history.back() to let the user navigate to the page he was previously. This works in every case, except when the user navigates directly to the login page :)

另一种解决方案是,当您从另一个页面导航时,将搜索参数传递给登录页面.然后,可以从登录页面选择导航到搜索参数的页面(如果存在),否则选择导航到主页".

Another solution is to pass a search parameter to the login page when you navigate from another page. From the login page you can then choose to navigate to the page of the search parameter if its present, and otherwise navigate to the "home page".

这篇关于AngularJS如何获取URL引荐来源网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 07:19