Good day. Help please, there is a huge SPA using the old version angular 1.4.8
Throughout the project, to navigate between the "pages", the ToUrl function is used with the following code:
var ToUrl = function (relativeUrl) { var mainContainerElement = window.angular.element("#MainContainer") var rootScope = mainContainerElement.injector().get("$rootScope"); var ngLocation = rootScope.ngLocation; if (rootScope && ngLocation) { rootScope.historyPushCount = 1; rootScope.$evalAsync(ngLocation.url(relativeUrl)); } } }; In all places where this function (ToUrl) is called everything is fine. In addition to one service. For some reason, angular sends another request to the server with the same url to which the transition is performed by the ToUrl function. It turns out 2 requests in a row.
Using the debugger, I found the function fireUrlChange, in which there is a lastHistoryState === cachedState check and this check returns false. Because of this, angular creates another query. In the belt, cachedState is always null, but for the time the function is triggered, the number 2 for some reason appears there.
Here is the code for the fireUrlChange function:
function fireUrlChange() { if (lastBrowserUrl === self.url() && lastHistoryState === cachedState) { return; } lastBrowserUrl = self.url(); lastHistoryState = cachedState; forEach(urlChangeListeners, function(listener) { listener(self.url(), cachedState); }); } Help please, how to find the reason for changing the parameter cachedState (or lastHistoryState)?