alecswan alecswan - 6 months ago 21
AngularJS Question

AngularJS: How to clear query parameters in the URL?

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.

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


I would like to remove
from the URL in order to make it clean. The user does not need to see the query parameters I received from LinkedIn redirect.

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

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


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

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