Does the Angular router have any restrictions to be used inside an NgRx effect?
I just started learning NgRx and I have the following code:
@Effect() public authenticate$ = this.actions$
.ofType(authenticationActions.AUTHENTICATE)
.switchMap((action: AuthenticateAction) => this.authenticationService.authenticate(action.payload)
.map((data: TokenData) => {
const user: User = {
token: data.token,
username: 'dummy',
};
console.log(data);
this.router.navigateByUrl('/');
return new authenticationActions.AuthenticateSuccessAction(user);
})
.catch(error => { console.log(error); return Observable.throw(error); })
);
The console logs the data variable and the AuthenticateSuccessAction
action is being triggered, so the router line is being executed but the navigation doesn't happen.
this.router.navigateByUrl('/login')
; Ensure you're not using something like an AuthGuard that redirects you back to your login screen. – Joshua Chan May 28 '18 at 14:40tap
operator (in older versions of rxjs it was calleddo
). – dee zg May 29 '18 at 16:58