How to use the @ngrx/router-store.ROUTER_NAVIGATION function in @ngrx/router-store

To help you get started, we’ve selected a few @ngrx/router-store examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DSpace / dspace-angular / src / app / +admin / admin-registries / metadata-registry / metadata-registry.effects.ts View on Github external
/**
 * Makes sure that if the user navigates to another route, the sidebar is collapsed
 */
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { filter, map, tap } from 'rxjs/operators';
import { SearchSidebarCollapseAction } from '../../../+search-page/search-sidebar/search-sidebar.actions';
import * as fromRouter from '@ngrx/router-store';
import { URLBaser } from '../../../core/url-baser/url-baser';

@Injectable()
export class SearchSidebarEffects {
  private previousPath: string;
  @Effect() routeChange$ = this.actions$
    .pipe(
      ofType(fromRouter.ROUTER_NAVIGATION),
      filter((action) => this.previousPath !== this.getBaseUrl(action)),
      tap((action) => {
        this.previousPath = this.getBaseUrl(action)
      }),
      map(() => new SearchSidebarCollapseAction())
    );

  constructor(private actions$: Actions) {

  }

  getBaseUrl(action: any): string {
    /* tslint:disable:no-string-literal */
    const url: string = action['payload'].routerState.url;
    return new URLBaser(url).toString();
    /* tslint:enable:no-string-literal */
github chef / automate / components / automate-ui / src / app / modules / team / team-details / team-details.component.spec.ts View on Github external
'params': {
              'id': 'admin'
            },
            'queryParams': {},
            'fragment': null,
            'path': ['/', 'settings', 'users', 'admin']}
        }
      }));

    // GetTeam should not be called because we are not on the teams page any more.
    expect(store.dispatch).not.toHaveBeenCalledWith(new GetTeam({id: 'admin'}));
  });
});

export class GetRoute implements Action {
  readonly type = routerStore.ROUTER_NAVIGATION;

  constructor(public payload: any) { }
}
github DSpace / dspace-angular / src / app / +search-page / search-sidebar / search-sidebar.effects.ts View on Github external
import { Injectable } from '@angular/core';
import { Effect, Actions, ofType } from '@ngrx/effects'
import * as fromRouter from '@ngrx/router-store';

import { SearchSidebarCollapseAction } from './search-sidebar.actions';
import { URLBaser } from '../../core/url-baser/url-baser';

/**
 * Makes sure that if the user navigates to another route, the sidebar is collapsed
 */
@Injectable()
export class SearchSidebarEffects {
  private previousPath: string;
  @Effect() routeChange$ = this.actions$
    .pipe(
      ofType(fromRouter.ROUTER_NAVIGATION),
      filter((action) => this.previousPath !== this.getBaseUrl(action)),
      tap((action) => {
        this.previousPath = this.getBaseUrl(action)
      }),
      map(() => new SearchSidebarCollapseAction())
    );

  constructor(private actions$: Actions) {

  }

  getBaseUrl(action: any): string {
    /* tslint:disable:no-string-literal */
    const url: string = action['payload'].routerState.url;
    return new URLBaser(url).toString();
    /* tslint:enable:no-string-literal */
github DSpace / dspace-angular / src / app / header / header.effects.spec.ts View on Github external
it('should return a COLLAPSE action in response to an UPDATE_LOCATION action', () => {
      actions = hot('--a-', { a: { type: fromRouter.ROUTER_NAVIGATION } });

      const expected = cold('--b-', { b: new HeaderCollapseAction() });

      expect(headerEffects.routeChange$).toBeObservable(expected);
    });
github DSpace / dspace-angular / src / app / shared / sidebar / search-sidebar.effects.spec.ts View on Github external
it('should return a COLLAPSE action in response to an UPDATE_LOCATION action to a new route', () => {
      actions = hot('--a-', { a: { type: fromRouter.ROUTER_NAVIGATION, payload: {routerState: {url: dummyURL}} } });

      const expected = cold('--b-', { b: new SidebarCollapseAction() });

      expect(sidebarEffects.routeChange$).toBeObservable(expected);
    });
  });
github DSpace / dspace-angular / src / app / core / router / router.effects.ts View on Github external
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}
   */
  @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) {
  }

}
github SAP / cloud-commerce-spartacus-storefront / projects / core / src / routing / store / reducers / router.reducer.ts View on Github external
export function reducer(
  state: RouterState = initialState,
  action: any
): RouterState {
  switch (action.type) {
    case fromNgrxRouter.ROUTER_NAVIGATION: {
      return {
        ...state,
        nextState: action.payload.routerState,
        navigationId: action.payload.event.id,
      };
    }

    case fromNgrxRouter.ROUTER_ERROR:
    case fromNgrxRouter.ROUTER_CANCEL: {
      return {
        ...state,
        nextState: undefined,
      };
    }

    case fromNgrxRouter.ROUTER_NAVIGATED: {
github DSpace / dspace-angular / src / app / navbar / navbar.effects.ts View on Github external
* Effect that collapses the public menu on window resize
   * @type {Observable}
   */
  @Effect() resize$ = this.actions$
    .pipe(
      ofType(HostWindowActionTypes.RESIZE),
      map(() => new CollapseMenuAction(this.menuID))
    );

  /**
   * Effect that collapses the public menu on reroute
   * @type {Observable}
   */
  @Effect() routeChange$ = this.actions$
    .pipe(
      ofType(fromRouter.ROUTER_NAVIGATION),
      map(() => new CollapseMenuAction(this.menuID))
    );
  /**
   * Effect that collapses the public menu when the admin sidebar opens
   * @type {Observable}
   */
  @Effect() openAdminSidebar$ = this.actions$
    .pipe(
      ofType(MenuActionTypes.EXPAND_MENU_PREVIEW),
      switchMap((action: ExpandMenuPreviewAction) => {
        return this.menuService.getMenu(action.menuID).pipe(
          first(),
          map((menu: MenuState) => {
            if (menu.id === MenuID.ADMIN) {
              if (!menu.previewCollapsed && menu.collapsed) {
                return new CollapseMenuAction(MenuID.PUBLIC)
github DSpace / dspace-angular / src / app / core / services / route.effects.ts View on Github external
import { map } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects'
import * as fromRouter from '@ngrx/router-store';
import { ResetRouteStateAction } from './route.actions';

@Injectable()
export class RouteEffects {
  /**
   * Effect that resets the route state on reroute
   * @type {Observable}
   */
  @Effect() routeChange$ = this.actions$
    .pipe(
      ofType(fromRouter.ROUTER_NAVIGATION),
      map(() => new ResetRouteStateAction())
    );

  constructor(private actions$: Actions) {

  }

}
github chef / automate / components / automate-ui / src / app / ngrx.reducers.ts View on Github external
export function routerReducer(state = defaultRouterState, action) {
  switch (action.type) {
    case router.ROUTER_NAVIGATION:
      const newRouterState =
        set('previousRoute', get('state', state), router.routerReducer(state, action));
      return newRouterState;
    default:
      return state;
  }
}