Skip to content

Commit

Permalink
feat(router-store) Add base router selectors
Browse files Browse the repository at this point in the history
- update documentation based off review
  • Loading branch information
jasonhodges committed May 29, 2019
1 parent a8d9738 commit e354684
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion modules/router-store/spec/router_selectors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RouterReducerState, getSelectors } from '@ngrx/router-store';
import { RouterStateSelectors } from '../src/models';

let mockData = {
const mockData = {
state: {
root: {
params: {},
Expand Down
28 changes: 10 additions & 18 deletions projects/ngrx.io/content/guide/router-store/selectors.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## Router selectors
# Router selectors

The `getSelectors` method supplied within `@ngrx/router-store` provides functions for selecting information from router state.
The `getSelectors` method supplied within `@ngrx/router-store` provides functions for selecting common information from the router state.

The `getSelectors` method takes a selector function as its only argument to select the piece of state.
The `getSelectors` method takes a selector function as its only argument to select the piece of state where the router state is being stored.
The example below shows how to provide a selector for the top level `router` key in your state object.

**Note:** The `getSelectors` method works with the `routerReducer` provided by `@ngrx/router-store`. If you use a custom serializer, you'll need to provide your own selectors if they do not adhere to `RouterReducerState`.

Usage:

Expand All @@ -21,21 +24,10 @@ export const selectRouter = createFeatureSelector<
>('router');

const {
selectQueryParams,
selectRouteParams,
selectRouteData,
selectUrl,
selectQueryParams, // select the current route query params
selectRouteParams, // select the current route params
selectRouteData, // select the current route data
selectUrl, // select the current url
} = getSelectors(selectRouter);

// select the current url
export const selectCurrentUrl = selectUrl;

// select the current route query params
export const selectCurrentQueryParams = selectQueryParams;

// select the current route data
export const selectCurrentRouteData = selectRouteData;

// select the current route params
export const selectCurrentRouteParams = selectRouteParams;
```
8 changes: 4 additions & 4 deletions projects/ngrx.io/content/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@
"title": "Actions",
"url": "guide/router-store/actions"
},
{
"title": "Configuration",
"url": "guide/router-store/configuration"
},
{
"title": "Selectors",
"url": "guide/router-store/selectors"
},
{
"title": "Configuration",
"url": "guide/router-store/configuration"
}
]
},
Expand Down

0 comments on commit e354684

Please sign in to comment.