Skip to content

Commit

Permalink
docs(RouterStore): change default state key to router
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Aug 22, 2018
1 parent f1ea79d commit e214dfe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
21 changes: 10 additions & 11 deletions docs/router-store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export declare type RouterNavigationAction<T = RouterStateSnapshot> = {
};
```

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

## Setup

Expand All @@ -56,9 +56,7 @@ import { AppComponent } from './app.component';
// routes
]),
// Connects RouterModule with StoreModule
StoreRouterConnectingModule.forRoot({
stateKey: 'router', // name of reducer key
}),
StoreRouterConnectingModule.forRoot(),
],
bootstrap: [AppComponent],
})
Expand All @@ -67,6 +65,7 @@ export class AppModule {}

## API Documentation

* [Navigation actions](./api.md#navigation-actions)
* [Effects](./api.md#effects)
* [Custom Router State Serializer](./api.md#custom-router-state-serializer)
- [StoreRouterConnectingModule.forRoot](./api.md#StoreRouterConnectingModule.forRoot)
- [Navigation actions](./api.md#navigation-actions)
- [Effects](./api.md#effects)
- [Custom Router State Serializer](./api.md#custom-router-state-serializer)
17 changes: 14 additions & 3 deletions docs/router-store/api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# API

## StoreRouterConnectingModule.forRoot

To connect the Angular router module with the NgRx store module, import the store module via
`StoreRouterConnectingModule.forRoot()`. This function accepts a config object `StoreRouterConfig` or a function returning `StoreRouterConfig`.

```ts
interface StoreRouterConfig {
stateKey?: string;
}
```

- `stateKey`: The store module state key

## Navigation actions

Navigation actions are not provided as part of the router package. You provide your own
Expand Down Expand Up @@ -150,9 +163,7 @@ export const reducers: ActionReducerMap<State> = {
RouterModule.forRoot([
// routes
]),
StoreRouterConnectingModule.forRoot({
stateKey: 'router',
}),
StoreRouterConnectingModule.forRoot(),
],
providers: [{ provide: RouterStateSerializer, useClass: CustomSerializer }],
})
Expand Down
13 changes: 2 additions & 11 deletions projects/example-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
import { DBModule } from '@ngrx/db';
import {
StoreRouterConnectingModule,
RouterStateSerializer,
} from '@ngrx/router-store';
import { StoreRouterConnectingModule } from '@ngrx/router-store';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';

import { CoreModule } from './core/core.module';
Expand Down Expand Up @@ -44,13 +41,7 @@ import { AppRoutingModule } from './app-routing.module';
/**
* @ngrx/router-store keeps router state up-to-date in the store.
*/
StoreRouterConnectingModule.forRoot({
/*
They stateKey defines the name of the state used by the router-store reducer.
This matches the key defined in the map of reducers
*/
stateKey: 'router',
}),
StoreRouterConnectingModule.forRoot(),

/**
* Store devtools instrument the store retaining past versions of state
Expand Down

0 comments on commit e214dfe

Please sign in to comment.