[英]Logout Action is not working after reloading Angular Page
問題:
登錄到應用程序后,當我點擊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());
}
SCREENSHOT Chrome Redux DevTools
在刷新頁面之前: http : //prntscr.com/ne3pc0
刷新頁面后: http : //prntscr.com/ne3qpr (注銷操作后沒有任何內容)
嘗試這個
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
}))
})
);
如有任何問題,請通知我
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.