0

问题:

当我点击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(Logout Action 后什么都没有)

4

1 回答 1

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
         }))
  })  
);

如果有任何问题,请告诉我

于 2019-04-19T06:53:14.010 回答