Whenever a button is clicked on my webpage, this particular function is triggered.
$scope.go=function(takenAt){
var path = '/oneMinuteMetric/loadCapturedMetrics?'+'×tamp=' + takenAt + '&tagName='+ $stateParams.tagName;
console.log(path); //first
$location.path(path);
console.log($location.path()); //second
};
However, it's strange that after the redirection, the new location seems to be incorrect.
The initial console.log
result displays
/oneMinuteMetric/loadCapturedMetrics?×tamp=1467976859092&tagName=TestTag
and the subsequent console.log
output also shows
/oneMinuteMetric/loadCapturedMetrics?×tamp=1467976859092&tagName=TestTag
But in the browser window, the displayed path is
/oneMinuteMetric/loadCapturedMetrics?tagName=TestTag×tamp=1468143868308%2F%3FtagName%3DTestTag
An unexpected addition of "%2F%3FtagName%3DTestTag
" leads to a bad request error from the server. Although we have used similar methods for redirecting in other parts of the website without any issues, why does it fail here?
PS: The current location of the webpage is
/oneMinuteMetric/tagHistory?tagName=TestTag
. This is where the button click triggers the mentioned function.
Solution: In this scenario, using $location.url(path) resolves the problem.