Angular location service doesn't change path

I am trying to execute $location.path(path) from my code, but when I check my browser, I see that the URL changes for a millisecond or so and goes back to the previous URL, so my page does not change.

Any idea?

+4
source share
2 answers

FWIW, I also had a problem with an anchor defined as follows:

 <a href="#" ng-click="bookToday()">book today!</a> 

It turns out that the hash ( # ) in the href attribute caused the application to cycle back to the default route.

I changed the link by deleting the hash and then it worked:

 <a href="" ng-click="bookToday()">book today!</a> 
+4
source

$location.path() is a getter function to set that you need to call $location.path('/yourpath')

0
source

Source: https://habr.com/ru/post/1482393/


All Articles