Just in case someone stumbles about this again after I stumbled about this after 7 years:
Usually you solve it by using $location:
$location.url('<url>');
$location.replace();
But... default html5Mode this will not replace window.location.search query parameters like
http://localhost/path?auth=xxx&andso=on
Without html5Mode (enabled:false by default) you need to care about pushState yourself before the AngularJs application runs:
Solution is to use...
window.history.replaceState(null, window.name, window.location.origin + window.location.path + window.location.hash)
(an example replacing the currently shown location url without parameters)
.. in an angular.provider() or angular.config():
In a provider when offering a reusable service:
angular.module('app').provider('AuthService', [
'someConfig',
function(someConfig){
if (someConfigObject.doItBeforeStartup) {
// ... check for parameter in window.location.search or whatever
window.history.replaceState(null, window.name, window.origin + window.path + window.hash)
}
this.readQuery = function(cfg){./* you can do it also here and call it in config*/..}
this.$get = ...
}]);
and/or in an config when using providers:
angular.module('app').config([
'AuthServiceProvider',
'someConfig',
function (AuthServiceProvider, someConfig) {
window.history.replaceState(.....)
// or in
// AuthServiceProvider.readQuery(...)
}]);