May 19, 2015 Patch
As in ui-router 0.2.15, the problem of state reloading when changing request parameters was solved. However, the new update violated the capabilities of the API back and forth of the API with request parameters. I could not find a workaround for this.
Original
The answer to the answer did not help me, and there werenβt a ton of other answers. Trying to listen to $locationChangeStart caused problems when trying to go back and forth in the browser history, as this will cause me to run the code twice: once when the new state has changed, and another because $loationChangeStart fired.
I tried using reloadOnSearch=false , but prevented state changes even when the URL path was changed. So I finally got it to work by doing the following:
When changing $location.search() to update the request parameters, use "hack" to temporarily disable reloading during the search, set the request parameters, then re-enable reloading.
$state.current.reloadOnSearch = false; $location.search('query', [1,2]); $timeout(function () { $state.current.reloadOnSearch = undefined; });
This ensures that changes to the request parameters do not reload the state and that changes to the URL path will reload the state properly.
However, this did not cause the browser history to change state (necessary to find out when the request parameter changes to re-read the URL) when the request parameter was part of the URL. Therefore, I also had to add each request parameter name to the state url property.
$locationProvider.html5Mode(true); $stateProvider .state('home', { url: '/?param1¶m2¶m3', templateUrl: 'home.html', controller: 'homeCtrl as home', });
Any parameter names on the url are optional when specifying this method, but any changes to these parameter names reload the state when you click the back and forward buttons in the browser.
We hope that others find this useful, and they donβt need many days to figure out how to do this (like me).