1 | # Angular Redux Router
|
2 | Sync Angular Router state with the Redux app state, gaining easy access to the entire route, not just the activated route.
|
3 |
|
4 | ## Dependencies
|
5 | * `@angular/router`
|
6 |
|
7 | ## Installation
|
8 | ```
|
9 | npm install @district01/ng-redux-router --save
|
10 | ```
|
11 |
|
12 | Import component in **app.module.ts**:
|
13 | ```
|
14 | import { ReduxRouterModule } from '@district01/ng-redux-router';
|
15 |
|
16 | @NgModule({
|
17 | imports: [
|
18 | ReduxRouterModule
|
19 | ]
|
20 | })
|
21 |
|
22 | export class AppModule {}
|
23 | ```
|
24 |
|
25 | Initialize `ReduxRouter` with a dispatch function (e.g. using the [`@angular-redux/store`](https://github.com/angular-redux/store) package:
|
26 | ```
|
27 | constructor(
|
28 | private ngRedux: NgRedux<MyAppState>,
|
29 | private reduxRouter: ReduxRouter
|
30 | ) {
|
31 | reduxRouter.initialize(ngRedux.dispatch);
|
32 | }
|
33 | ```
|
34 |
|
35 | ## Usage
|
36 |
|
37 | The `ReduxRouter` will listen for route changes and store the current, previous and active (pending) route in the state. The following properties are stored for each route:
|
38 |
|
39 | * url: the complete path including queryParams & fragments
|
40 | * path: the url path without queryParams & fragments
|
41 | * frament: the current active fragment
|
42 | * query: all queryParams found on the route
|
43 | * params: all route params found on the route
|
44 |
|
45 | The `ROUTE_UPDATE` action will only be dispatched once the `NavigationEnd` event is triggered.
|