AngularJS:如何清除URL查询参数? [英] AngularJS: How to clear query parameters in the URL?

查看:1233
本文介绍了AngularJS:如何清除URL查询参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的AngularJS应用程序需要访问用户的LinkedIn的个人资料。为了做到这一点,我需要将用户重定向到包含一个回调REDIRECT_URI参数它会告诉LinkedIn将用户重定向回到我的web应用程序,并在URL中包括一个code查询参数一个LinkedIn URL。这是一个传统的OAuth 2.0用户流量。

My AngularJS application needs to have access to the user's LinkedIn profile. In order to do that I need to redirect the user to a LinkedIn URL which contains a callback redirect_uri parameter which will tell LinkedIn to redirect the user back to my webapp and include a "code" query param in the URL. It's a traditional Oauth 2.0 flow.

除了LinkedIn用户重定向到以下网址一切都很正常:

Everything works great except that LinkedIn redirects the user back to the following URL:

http://localhost:8080/?code=XXX&state=YYY#/users/123/providers/LinkedIn/social-sites

我想删除 code = XXX&放大器;从URL状态= YYY 为了使干净?用户不需要看我从LinkedIn收到的查询参数重定向。

I would like to remove ?code=XXX&state=YYY from the URL in order to make it clean. The user does not need to see the query parameters I received from LinkedIn redirect.

我试过 $ location.absUrl($ location.path()+ $的location.hash())。REPLACE(),但保留在该查询参数网址。

I tried $location.absUrl($location.path() + $location.hash()).replace(), but it keep the query params in the URL.

我也无法提取查询参数,例如code,使用($ location.search())。code
好像有? #在URL之前上面淋水角。

I am also unable to extract the query parameters, e.g. "code", using ($location.search()).code. It seems like having ? before # in the URL above is tricking Angular.

推荐答案

我最终得到来自AngularJS论坛答案。请参见详情此线程

I ended up getting the answer from AngularJS forum. See this thread for details

该链接到谷歌论坛线程,这是难以阅读,不提供一个明确的答案。要删除URL参数,用

The link is to a Google Groups thread, which is difficult to read and doesn't provide a clear answer. To remove URL parameters use

$location.url($location.path());

这篇关于AngularJS:如何清除URL查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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