Skip to content

Commit e8173d9

Browse files
timdeschryverbrandonroberts
authored andcommitted
refactor(routerstore): change default state key to router (#1258)
BREAKING CHANGE: The default state key is changed from routerReducer to router
1 parent 32cc36e commit e8173d9

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

docs/router-store/README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ export declare type RouterNavigationAction<T = RouterStateSnapshot> = {
3434
};
3535
```
3636

37-
* Reducers receive this action, throwing an error in the reducer cancels navigation.
38-
* Effects can listen for this action.
39-
* The `ROUTER_CANCEL` action represents a guard canceling navigation.
40-
* A `ROUTER_ERROR` action represents a navigation error .
41-
* `ROUTER_CANCEL` and `ROUTER_ERROR` contain the store state before the navigation. Use the previous state to restore the consistency of the store.
37+
- Reducers receive this action, throwing an error in the reducer cancels navigation.
38+
- Effects can listen for this action.
39+
- The `ROUTER_CANCEL` action represents a guard canceling navigation.
40+
- A `ROUTER_ERROR` action represents a navigation error .
41+
- `ROUTER_CANCEL` and `ROUTER_ERROR` contain the store state before the navigation. Use the previous state to restore the consistency of the store.
4242

4343
## Setup
4444

@@ -56,9 +56,7 @@ import { AppComponent } from './app.component';
5656
// routes
5757
]),
5858
// Connects RouterModule with StoreModule
59-
StoreRouterConnectingModule.forRoot({
60-
stateKey: 'router', // name of reducer key
61-
}),
59+
StoreRouterConnectingModule.forRoot(),
6260
],
6361
bootstrap: [AppComponent],
6462
})
@@ -67,6 +65,7 @@ export class AppModule {}
6765

6866
## API Documentation
6967

70-
* [Navigation actions](./api.md#navigation-actions)
71-
* [Effects](./api.md#effects)
72-
* [Custom Router State Serializer](./api.md#custom-router-state-serializer)
68+
- [Configuration Options](./api.md#configuration-options)
69+
- [Navigation actions](./api.md#navigation-actions)
70+
- [Effects](./api.md#effects)
71+
- [Custom Router State Serializer](./api.md#custom-router-state-serializer)

docs/router-store/api.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# API
22

3+
## Configuration Options
4+
5+
To connect the Angular router module with the NgRx store module, import the store module via
6+
`StoreRouterConnectingModule.forRoot()`.
7+
8+
```ts
9+
interface StoreRouterConfig {
10+
stateKey?: string;
11+
}
12+
```
13+
14+
- `stateKey`: The name of reducer key, defaults to `router`
15+
316
## Navigation actions
417

518
Navigation actions are not provided as part of the router package. You provide your own
@@ -150,9 +163,7 @@ export const reducers: ActionReducerMap<State> = {
150163
RouterModule.forRoot([
151164
// routes
152165
]),
153-
StoreRouterConnectingModule.forRoot({
154-
stateKey: 'router',
155-
}),
166+
StoreRouterConnectingModule.forRoot(),
156167
],
157168
providers: [{ provide: RouterStateSerializer, useClass: CustomSerializer }],
158169
})

modules/router-store/spec/integration.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,16 @@ describe('integration spec', () => {
244244
: null;
245245
};
246246

247-
createTestModule({ reducers: { routerReducer, reducer } });
247+
createTestModule({ reducers: { router: routerReducer, reducer } });
248248

249249
const router = TestBed.get(Router);
250250
const store = TestBed.get(Store);
251251
const log = logOfRouterAndStore(router, store);
252252

253253
const routerReducerStates: any[] = [];
254254
store.subscribe((state: any) => {
255-
if (state.routerReducer) {
256-
routerReducerStates.push(state.routerReducer);
255+
if (state.router) {
256+
routerReducerStates.push(state.router);
257257
}
258258
});
259259

modules/router-store/src/router_store_module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const _ROUTER_CONFIG = new InjectionToken(
126126
export const ROUTER_CONFIG = new InjectionToken(
127127
'@ngrx/router-store Configuration'
128128
);
129-
export const DEFAULT_ROUTER_FEATURENAME = 'routerReducer';
129+
export const DEFAULT_ROUTER_FEATURENAME = 'router';
130130

131131
export function _createDefaultRouterConfig(
132132
config: StoreRouterConfig | StoreRouterConfigFunction

projects/example-app/src/app/app.module.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
77
import { StoreModule } from '@ngrx/store';
88
import { EffectsModule } from '@ngrx/effects';
99
import { DBModule } from '@ngrx/db';
10-
import {
11-
StoreRouterConnectingModule,
12-
RouterStateSerializer,
13-
} from '@ngrx/router-store';
10+
import { StoreRouterConnectingModule } from '@ngrx/router-store';
1411
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
1512

1613
import { CoreModule } from './core/core.module';
@@ -44,13 +41,7 @@ import { AppRoutingModule } from './app-routing.module';
4441
/**
4542
* @ngrx/router-store keeps router state up-to-date in the store.
4643
*/
47-
StoreRouterConnectingModule.forRoot({
48-
/*
49-
They stateKey defines the name of the state used by the router-store reducer.
50-
This matches the key defined in the map of reducers
51-
*/
52-
stateKey: 'router',
53-
}),
44+
StoreRouterConnectingModule.forRoot(),
5445

5546
/**
5647
* Store devtools instrument the store retaining past versions of state

0 commit comments

Comments
 (0)