diff --git a/modules/router-store/spec/router_store_module.spec.ts b/modules/router-store/spec/router_store_module.spec.ts index 0dc0bfd6b1..72d4bd04c4 100644 --- a/modules/router-store/spec/router_store_module.spec.ts +++ b/modules/router-store/spec/router_store_module.spec.ts @@ -141,7 +141,7 @@ describe('Router Store Module', () => { }); describe('routerState', () => { - function setup(routerState: RouterState, serializer?: any) { + function setup(routerState?: RouterState, serializer?: any) { createTestModule({ reducers: {}, config: { @@ -172,7 +172,17 @@ describe('Router Store Module', () => { await router.navigateByUrl('/'); }); - it('should use the default router serializer', () => { + it('should use the minimal router serializer by default', () => { + const { serializer } = setup(); + expect(serializer).toEqual(new MinimalRouterStateSerializer()); + }); + + it('should use the minimal router serializer if minimal state option is passed in', () => { + const { serializer } = setup(RouterState.Minimal); + expect(serializer).toEqual(new MinimalRouterStateSerializer()); + }); + + it('should use the default router serializer if full state option is passed in', () => { const { serializer } = setup(RouterState.Full); expect(serializer).toEqual(new DefaultRouterStateSerializer()); }); diff --git a/modules/router-store/src/router_store_module.ts b/modules/router-store/src/router_store_module.ts index a6e6724950..0f2ace934f 100644 --- a/modules/router-store/src/router_store_module.ts +++ b/modules/router-store/src/router_store_module.ts @@ -94,7 +94,7 @@ export function _createRouterConfig( ): StoreRouterConfig { return { stateKey: DEFAULT_ROUTER_FEATURENAME, - serializer: DefaultRouterStateSerializer, + serializer: MinimalRouterStateSerializer, navigationActionTiming: NavigationActionTiming.PreActivation, ...config, }; @@ -168,9 +168,9 @@ export class StoreRouterConnectingModule { provide: RouterStateSerializer, useClass: config.serializer ? config.serializer - : config.routerState === RouterState.Minimal - ? MinimalRouterStateSerializer - : DefaultRouterStateSerializer, + : config.routerState === RouterState.Full + ? DefaultRouterStateSerializer + : MinimalRouterStateSerializer, }, ], }; @@ -328,9 +328,9 @@ export class StoreRouterConnectingModule { routerState: this.routerState, ...payload, event: - this.config.routerState === RouterState.Minimal - ? { id: payload.event.id, url: payload.event.url } - : payload.event, + this.config.routerState === RouterState.Full + ? payload.event + : { id: payload.event.id, url: payload.event.url }, }, }); } finally { diff --git a/projects/example-app/src/app/app.module.ts b/projects/example-app/src/app/app.module.ts index 6262bd8eb2..04953043fe 100644 --- a/projects/example-app/src/app/app.module.ts +++ b/projects/example-app/src/app/app.module.ts @@ -15,10 +15,7 @@ import { ROOT_REDUCERS, metaReducers } from '@example-app/reducers'; import { CoreModule } from '@example-app/core'; import { AppRoutingModule } from '@example-app/app-routing.module'; -import { - UserEffects, - RouterEffects -} from '@example-app/core/effects'; +import { UserEffects, RouterEffects } from '@example-app/core/effects'; import { AppComponent } from '@example-app/core/containers'; @NgModule({ @@ -50,9 +47,7 @@ import { AppComponent } from '@example-app/core/containers'; /** * @ngrx/router-store keeps router state up-to-date in the store. */ - StoreRouterConnectingModule.forRoot({ - routerState: RouterState.Minimal, - }), + StoreRouterConnectingModule.forRoot(), /** * Store devtools instrument the store retaining past versions of state diff --git a/projects/ngrx.io/content/guide/router-store/configuration.md b/projects/ngrx.io/content/guide/router-store/configuration.md index 685f9cfd59..b8dce24d16 100644 --- a/projects/ngrx.io/content/guide/router-store/configuration.md +++ b/projects/ngrx.io/content/guide/router-store/configuration.md @@ -16,12 +16,12 @@ interface StoreRouterConfig { ## Default Router State Serializer -If no router state serializer is provided through the [configuration](#configuration-options) of router store, the `DefaultRouterStateSerializer` is used. This router state serializer, serializes the URL together with the [ActivatedRouteSnapshot](https://angular.io/api/router/ActivatedRouteSnapshot) from [Angular Router](https://angular.io/guide/router). The latter is serialized recursively, but only with the possibility to traverse the route downward since `root` and `parent` parameters are set to `undefined`. +`DefaultRouterStateSerializer` router state serializer, serializes the URL together with the [ActivatedRouteSnapshot](https://angular.io/api/router/ActivatedRouteSnapshot) from [Angular Router](https://angular.io/guide/router). The latter is serialized recursively, but only with the possibility to traverse the route downward since `root` and `parent` parameters are set to `undefined`.