Hope this helps others, As none of the suggestions I saw on SO worked. I managed to create kind of a hack to get this working using the following code in app.run function.
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
//not coming from any other page + coming to ads page + contains query string
if (fromState.name == "" && toState.name == "current_page" && toState.url !== "/current-page-url") {
$location.search({});
}
});
What it does is if I come to the page from other pages, it will have fromState populated but when I reload the current page, the fromState will have no data and toState will the details of the current page. To avoid continuous looping, I also check if the current url contains any querystring.
UPDATE
Even a better solution. Found some help from this link.
$rootScope.$on("$locationChangeStart", function (event, next, current) {
//Page reload detection
if (next == current && && performance.navigation.type == 1) {
event.preventDefault();
$location.search({});
}
});
The first solution removes the query string even when you load a page with query string for the first time (via some bookmark).
The second solution works just as intended.
See this for reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/performance