Reputation: 4799
We are using angularJS and angular ui-router and want to change the URL in the address bar but keep the view/state the same.
I have tried using history pushstate but I am having conflicts with it causing an infinite $digest loop.
I have also tried the method described in sync() https://github.com/angular-ui/ui-router/wiki/Quick-Reference#urlroutersync - which is essentially calling preventDefault
on $locationChangeSuccess
. However, this doesn't seem to work - as demonstrated by this plunkr: http://plnkr.co/pLC2Ai
Does anyone know of any solutions to this issue?
Upvotes: 4
Views: 864
Reputation: 20977
Have you tried the history.pushState method?
On Mozilla's site the say: "This will cause the URL bar to display http://mozilla.org/bar.html, but won't cause the browser to load bar.html or even check that bar.html exists."
history.pushState(stateObj, "page 2", "bar.html");
You may need to inject $locationProvider and then set $locationProvider.html5Mode(true).
Upvotes: 0
Reputation: 3464
Of course, my mate! :)
use $stateChangeStart
, not $locationChangeSuccess
Upvotes: 2