mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 05:53:03 +00:00
fixing more routing issues
This commit is contained in:
31
src/app/core/router/router.effects.ts
Normal file
31
src/app/core/router/router.effects.ts
Normal 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) {
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user