Within my AngularJS application, I have implemented the following routing mechanism:
$routeProvider.when('/questions',
route.resolve('questions',
'questions/',
'questions',
'overview',
access.authorizedAccess))
Currently, this routing mechanism functions correctly, allowing access to URLs like domain.com/app/#/questions
and loading the appropriate controller and template.
However, I am seeking to enhance this functionality by enabling the addition of parameters to the existing URL without triggering a page reload. In other words, I want to reinterpret the URL. The challenge I am facing is that when I attempt to add parameters with
window.location.hash = '#/questions?query=test';
, the route is reinterpreted, resulting in a page reload.
To address this issue, I have experimented with the following solution:
$rootScope.$on("$locationChangeStart", function (event, next, current) {
if (next.indexOf('?') > -1)
event.preventDefault();
});
While this approach successfully prevents a route reinterpretation, it also removes the parameter from the hash, reverting it to '/questions'
.