fixing more routing issues

This commit is contained in:
lotte
2019-07-25 15:41:13 +02:00
parent 170377f209
commit f4ee930c4a
24 changed files with 149 additions and 242 deletions

View File

@@ -0,0 +1,31 @@
import { filter, map, pairwise } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects'
import * as fromRouter from '@ngrx/router-store';
import { RouterNavigationAction } from '@ngrx/router-store';
import { Router } from '@angular/router';
import { RouteUpdateAction } from './router.actions';
@Injectable()
export class RouterEffects {
/**
* Effect that fires a new RouteUpdateAction when then path of route is changed
* @type {Observable<RouteUpdateAction>}
*/
@Effect() routeChange$ = this.actions$
.pipe(
ofType(fromRouter.ROUTER_NAVIGATION),
pairwise(),
map((actions: RouterNavigationAction[]) =>
actions.map((navigateAction) => {
const urlTree = this.router.parseUrl(navigateAction.payload.routerState.url);
return urlTree.root.children['primary'].segments.map(it => it.path).join('/');
})),
filter((actions: string[]) => actions[0] !== actions[1]),
map(() => new RouteUpdateAction())
);
constructor(private actions$: Actions, private router: Router) {
}
}