@@ -681,9 +681,10 @@ describe('transition', function () {
681
681
} ) ;
682
682
683
683
describe ( 'redirected transition' , ( ) => {
684
- let urlRedirect ;
684
+ let urlRedirect , requiresAuth ;
685
685
beforeEach ( ( ) => {
686
686
urlRedirect = router . stateRegistry . register ( { name : 'urlRedirect' , url : '/urlRedirect' , redirectTo : 'redirectTarget' } ) ;
687
+ requiresAuth = router . stateRegistry . register ( { name : 'requiresAuth' , url : '/requiresAuth' } ) ;
687
688
router . stateRegistry . register ( { name : 'redirectTarget' , url : '/redirectTarget' } ) ;
688
689
} ) ;
689
690
@@ -703,6 +704,9 @@ describe('transition', function () {
703
704
router . transitionService . onSuccess ( { } , ( ) => {
704
705
expect ( transitionTo ) . toHaveBeenCalledWith ( urlRedirect , { } , { inherit : true , source : 'url' } ) ;
705
706
707
+ expect ( router . stateService . current . name ) . toBe ( 'redirectTarget' ) ;
708
+ expect ( router . urlService . path ( ) ) . toBe ( '/redirectTarget' ) ;
709
+
706
710
expect ( url . calls . count ( ) ) . toEqual ( 2 ) ;
707
711
expect ( url . calls . argsFor ( 0 ) ) . toEqual ( [ "/urlRedirect" ] ) ;
708
712
expect ( url . calls . argsFor ( 1 ) ) . toEqual ( [ "/redirectTarget" , true ] ) ;
@@ -713,6 +717,29 @@ describe('transition', function () {
713
717
router . urlService . url ( '/urlRedirect' ) ;
714
718
} ) ;
715
719
720
+ it ( "should not replace the current url when redirecting a url sync with { location: false }" , ( done ) => {
721
+ router . transitionService . onBefore ( { to : 'requiresAuth' } , trans => {
722
+ return router . stateService . target ( 'redirectTarget' , null , { location : false } )
723
+ } ) ;
724
+
725
+ let url = spyOn ( router . urlService , "url" ) . and . callThrough ( ) ;
726
+ let transitionTo = spyOn ( router . stateService , "transitionTo" ) . and . callThrough ( ) ;
727
+
728
+ router . transitionService . onSuccess ( { } , ( ) => {
729
+ expect ( transitionTo ) . toHaveBeenCalledWith ( requiresAuth , { } , { inherit : true , source : 'url' } ) ;
730
+
731
+ expect ( router . globals . current . name ) . toBe ( "redirectTarget" ) ;
732
+ expect ( router . urlService . path ( ) ) . toBe ( '/requiresAuth' ) ;
733
+
734
+ expect ( url . calls . count ( ) ) . toEqual ( 1 ) ;
735
+ expect ( url . calls . argsFor ( 0 ) ) . toEqual ( [ "/requiresAuth" ] ) ;
736
+
737
+ done ( ) ;
738
+ } ) ;
739
+
740
+ router . urlService . url ( '/requiresAuth' ) ;
741
+ } ) ;
742
+
716
743
} ) ;
717
744
} ) ;
718
745
0 commit comments