重新加载角度页面后,注销操作不起作用

时间:2019-04-19 05:13:29

标签: angular ngrx ngrx-store-4.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(注销操作后什么都没有)

1 个答案:

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

如有任何问题,请告诉我