Angular JS $on "$locationChangeStart" triggered twice when event.preventDefault()
angularjs, javascript
Solution
Okey, I've seen a very similar situation and found one possible cause. Angular (or our custom route-segment routing, not sure which) will sometimes trim a URL after routing processes it. Try logging `next` and `current` and see, what routes exactly you are dealing with. In our case the change was from this `http://wof/Admin#/someRoute` to `http://wof/Admin#/someRoute/` (notice added slash). After we accounted for this - it worked ok.
Problem
I'm trying to listen to the $on "$locationChangeStart" event in Angular JS and prevent the event from happening under certain circumstances. As soon as I do event.preventDefault(), the $on "$locationChangeStart" event gets fired again. Is that a Angular JS Bug? ``` $rootScope.$on "$locationChangeStart", (event, next, current) -> if doNotLeave event.preventDefault() ``` Thanks in advance, Steff