@@ -832,32 +832,40 @@ function $LocationProvider(){
832
832
} ) ;
833
833
834
834
// update browser
835
- var changeCounter = 0 ;
835
+ var initializing = true ;
836
+
836
837
$rootScope . $watch ( function $locationWatch ( ) {
837
838
var oldUrl = $browser . url ( ) ;
838
839
var oldState = $browser . state ( ) ;
839
840
var currentReplace = $location . $$replace ;
840
- var currentStateSent = $location . $$stateSent && changeCounter ;
841
+ var currentStateSent = $location . $$stateSent ;
842
+ var origInitializing = initializing ;
841
843
842
- if ( ! changeCounter || oldUrl !== $location . absUrl ( ) ||
844
+ if ( initializing || oldUrl !== $location . absUrl ( ) ||
843
845
( $location . $$html5 && $sniffer . history && oldState !== $location . $$state ) ) {
844
- changeCounter ++ ;
846
+ initializing = false ;
847
+
845
848
$rootScope . $evalAsync ( function ( ) {
846
849
if ( $rootScope . $broadcast ( '$locationChangeStart' , $location . absUrl ( ) , oldUrl ,
847
850
$location . $$state , oldState ) . defaultPrevented ) {
848
851
$location . $$parse ( oldUrl ) ;
849
852
$location . $$state = oldState ;
850
853
} else {
851
- setBrowserUrlWithFallback ( $location . absUrl ( ) , currentReplace ,
852
- currentStateSent ? null : $location . $$state ) ;
854
+ if ( ! origInitializing ) {
855
+ setBrowserUrlWithFallback ( $location . absUrl ( ) , currentReplace ,
856
+ currentStateSent ? null : $location . $$state ) ;
857
+ }
858
+
853
859
afterLocationChange ( oldUrl , oldState ) ;
854
860
}
855
861
} ) ;
856
862
}
863
+
857
864
$location . $$stateSent = true ;
858
865
$location . $$replace = false ;
859
866
860
- return changeCounter ;
867
+ // we don't need to return anything because $evalAsync will make the digest loop dirty when
868
+ // there is a change
861
869
} ) ;
862
870
863
871
return $location ;
0 commit comments