Skip to content

Commit

Permalink
Merge pull request #2843 from camptocamp/replaceState_errors
Browse files Browse the repository at this point in the history
Ignore history.replaceState errors
  • Loading branch information
fredj committed Aug 29, 2017
2 parents 8811c8c + e32a118 commit b7f2ace
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/services/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ ngeo.Location = function(location, history) {
};


/**
* @param {History} history History.
* @param {string} state State.
*/
ngeo.Location.replaceState = function(history, state) {
try {
history.replaceState(null, '', state);
} catch (error) {
// replaceState fails on some browser if the domain in the state
// is not the same as location.origin
}
};


/**
* Get the location's current path.
* @return {string|undefined} The path.
Expand Down Expand Up @@ -328,7 +342,7 @@ ngeo.Location.prototype.deleteFragmentParam = function(key) {
* @export
*/
ngeo.Location.prototype.refresh = function() {
this.history_.replaceState(null, '', this.getUriString());
ngeo.Location.replaceState(this.history_, this.getUriString());
};


Expand Down Expand Up @@ -361,7 +375,7 @@ ngeo.LocationFactory = function($rootScope, $window) {
$rootScope.$evalAsync(() => {
lastUri = newUri;
if (history !== undefined && history.replaceState !== undefined) {
history.replaceState(null, '', newUri);
ngeo.Location.replaceState(history, newUri);
}
$rootScope.$broadcast('ngeoLocationChange');
});
Expand Down

0 comments on commit b7f2ace

Please sign in to comment.