diff --git a/modules/router-store/spec/router_store_module.spec.ts b/modules/router-store/spec/router_store_module.spec.ts index 93fa6caa6d..0e55ab71b9 100644 --- a/modules/router-store/spec/router_store_module.spec.ts +++ b/modules/router-store/spec/router_store_module.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@angular/core/testing'; -import { Router, RouterEvent } from '@angular/router'; +import { Router, RouterEvent, NavigationEnd } from '@angular/router'; import { routerReducer, RouterReducerState, @@ -11,7 +11,7 @@ import { DefaultRouterStateSerializer, } from '@ngrx/router-store'; import { select, Store, ActionsSubject } from '@ngrx/store'; -import { withLatestFrom, filter } from 'rxjs/operators'; +import { withLatestFrom, filter, skip } from 'rxjs/operators'; import { createTestModule } from './utils'; @@ -155,13 +155,12 @@ describe('Router Store Module', () => { a.payload && a.payload.event; describe('Full', () => { - it('should dispatch the full event', async () => { + it('should dispatch the full event', async (done) => { const { actions, router } = setup(RouterState.Full); - actions - .pipe(filter(onlyRouterActions)) - .subscribe(({ payload }) => - expect(payload.event instanceof RouterEvent).toBe(true) - ); + actions.pipe(filter(onlyRouterActions)).subscribe(({ payload }) => { + expect(payload.event instanceof RouterEvent).toBe(true); + done(); + }); await router.navigateByUrl('/'); }); @@ -191,18 +190,43 @@ describe('Router Store Module', () => { }); describe('Minimal', () => { - it('should dispatch the navigation id with url', async () => { + it('should dispatch the navigation id with url', async (done) => { const { actions, router } = setup(RouterState.Minimal); actions .pipe(filter(onlyRouterActions)) .subscribe(({ payload }: any) => { expect(payload.event instanceof RouterEvent).toBe(false); expect(payload.event).toEqual({ id: 1, url: '/' }); + done(); }); await router.navigateByUrl('/'); }); + it('should dispatch the navigation with urlAfterRedirects', async (done) => { + const { actions, router } = setup(RouterState.Minimal); + actions + .pipe( + filter(onlyRouterActions), + // wait until NavigationEnd router event + filter( + ({ payload }) => + !!(payload.event as NavigationEnd).urlAfterRedirects + ) + ) + .subscribe(({ payload }: any) => { + expect(payload.event instanceof RouterEvent).toBe(false); + expect(payload.event).toEqual({ + id: 1, + url: '/redirect', + urlAfterRedirects: '/next', + }); + done(); + }); + + await router.navigateByUrl('/redirect'); + }); + it('should use the minimal router serializer', () => { const { serializer } = setup(RouterState.Minimal); expect(serializer).toEqual(new MinimalRouterStateSerializer()); diff --git a/modules/router-store/spec/utils.ts b/modules/router-store/spec/utils.ts index edcdcef265..d2fef95eeb 100644 --- a/modules/router-store/spec/utils.ts +++ b/modules/router-store/spec/utils.ts @@ -42,6 +42,11 @@ export function createTestModule( loadChildren: 'test', canLoad: ['CanLoadNext'], }, + { + path: 'redirect', + pathMatch: 'full', + redirectTo: 'next', + }, ]), StoreRouterConnectingModule.forRoot(opts.config), ], diff --git a/modules/router-store/src/router_store_module.ts b/modules/router-store/src/router_store_module.ts index 9641b497e8..e804709fc9 100644 --- a/modules/router-store/src/router_store_module.ts +++ b/modules/router-store/src/router_store_module.ts @@ -327,7 +327,13 @@ export class StoreRouterConnectingModule { event: this.config.routerState === RouterState.Full ? payload.event - : { id: payload.event.id, url: payload.event.url }, + : { + id: payload.event.id, + url: payload.event.url, + // safe, as it will just be `undefined` for non-NavigationEnd router events + urlAfterRedirects: (payload.event as NavigationEnd) + .urlAfterRedirects, + }, }, }); } finally {