问题:
登录到应用程序后,当我单击signOut
按钮时,它成功signOut
并重定向到登录页面。但是,当我刷新页面然后尝试注销时,它将无济于事。有人知道会有什么问题吗?
代码:
// action
export class Logout implements Action {
readonly type = LOGOUT;
}
// effect
@Effect()
logout$ = this.actions$
.ofType(authAction.LOGOUT)
.pipe(
map( () => {
debugger;
this.authService.logoutUser();
return new fromRoot.Go({
path: ['/account/login'],
});
})
);
// calling action on signout
public signOut() {
this.store.dispatch(new fromStore.Logout());
}
Chrome Redux DevTools的屏幕显示
刷新页面之前: http://prntscr.com/ne3pc0
刷新页面后: http://prntscr.com/ne3qpr(注销操作后什么都没有)
答案 0 :(得分:0)
尝试一下
import { throwError } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
// effect
@Effect()
logout$ = this.actions$.pipe(
.ofType(authAction.LOGOUT),
switchMap(() => {
return this.authService.logoutUser()
.pipe(map(() => {
return new fromRoot.Go({path: ['/account/login']})
}),
catchError((error: any) =>{
return of(error)
}),
finalize(() => {
//do something like hide loader
}))
})
);
如有任何问题,请告诉我