Angular 取消订阅路由器事件

Angular 取消订阅路由器事件,angular,ngrx-effects,Angular,Ngrx Effects,在登录后被重定向到上一个站点后,我正在与路由进行斗争。e、 g我调用“localhost:4200/results”,如果我没有登录,我将被引导到带有“localhost:4200?returnUrl=%2Fresults#login”的登录名。重定向可以工作,但是如果我想在导航栏中导航到“localhost:4200/dashboard”,它就不工作了。它显示“localhost:4200/dashboard”1秒,但没有路由,url仍然显示“localhost:4200/results”。试

在登录后被重定向到上一个站点后,我正在与路由进行斗争。e、 g我调用“localhost:4200/results”,如果我没有登录,我将被引导到带有“localhost:4200?returnUrl=%2Fresults#login”的登录名。重定向可以工作,但是如果我想在导航栏中导航到“localhost:4200/dashboard”,它就不工作了。它显示“localhost:4200/dashboard”1秒,但没有路由,url仍然显示“localhost:4200/results”。试图取消订阅。没用

特效

@Effect()
signInSuccess$ = this.actions$.pipe(
ofType(AuthActions.signInSuccessAction),
map(action => {
  const authenticatedUser = action.user;
  if (authenticatedUser.competenceCenterMappings.length === 0) {
    return openModal({component: CreateCompetenceCenterComponent});
  } else  {
    const returnUrl = this.prevRouteService.redirectUrl;
    this.router.events.pipe(
      filter(event => event instanceof NavigationEnd),
    ).subscribe(() => {
      this.router.navigateByUrl(returnUrl);
    }).unsubscribe();
    return closeModal();
  }
})
);
auth-guard.ts

  canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return combineLatest([
  this.store.select(AuthenticationStore.Selectors.isAuthenticated),
  this.store.select(AuthenticationStore.Selectors.getUser)
]).pipe(
  mergeMap(
    ([isAuthenticated, authUser]) => isAuthenticated ? this.handleEnvironment(authUser) : this.router.navigate([], {
      fragment: 'login',
      queryParams: { returnUrl: state.url }
    })
  )
);
canActivate(
下一步:ActivatedRouteSnapshot,
状态:RouterStateSnashot):可观察的|承诺|布尔| UrlTree{
返回组合测试([
this.store.select(AuthenticationStore.Selectors.isAuthenticated),
this.store.select(AuthenticationStore.Selectors.getUser)
]).烟斗(
合并地图(
([isAuthenticated,authUser])=>isAuthenticated?this.handleenEnvironment(authUser):this.router.navigate([]{
片段:“登录”,
查询参数:{returnUrl:state.url}
})
)
);