https://github.com/angular-redux/router
Keep your Angular2+ router state in Redux
https://github.com/angular-redux/router
angular angular2 angularjs redux router
Last synced: about 2 months ago
JSON representation
Keep your Angular2+ router state in Redux
- Host: GitHub
- URL: https://github.com/angular-redux/router
- Owner: angular-redux
- License: mit
- Created: 2017-01-04T05:32:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-13T20:27:06.000Z (almost 7 years ago)
- Last Synced: 2025-03-21T15:10:57.311Z (2 months ago)
- Topics: angular, angular2, angularjs, redux, router
- Language: TypeScript
- Size: 81.1 KB
- Stars: 28
- Watchers: 6
- Forks: 7
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ****REPO DEPRECATED****
Please note that this repo has been deprecated. Code and issues are being migrated to a monorepo at https://github.com/angular-redux/platform where we are beginning work on a new and improved v10. To file any new issues or see the state of the current code base, we would love to see you there! Thanks for your support!
# @angular-redux/router
[](https://gitter.im/angular-redux/ng2-redux?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://www.npmjs.com/package/@angular-redux/router)
[](https://www.npmjs.com/package/@angular-redux/router)Bindings to connect @angular/router to @angular-redux/core
## Which version should I use?
For use with Angular 6: Use v9.
For use with Angular 5: Use v7.
For use with Angular 2-4: Use v6.
### Setup
1. Use npm to install the bindings:
```
npm install @angular-redux/router --save
```2. Use the `routerReducer` when providing `Store`:
```ts
import { combineReducers } from 'redux';
import { routerReducer } from '@angular-redux/router';export default combineReducers({
// your reducers..
router: routerReducer
});
```3. Add the bindings to your root module.
```ts
import { NgModule } from '@angular/core';
import { NgReduxModule, NgRedux } from '@angular-redux/core';
import { NgReduxRouterModule, NgReduxRouter } from '@angular-redux/router';
import { RouterModule } from '@angular/router';
import { routes } from './routes';@NgModule({
imports: [
RouterModule.forRoot(routes),
NgReduxModule,
NgReduxRouterModule.forRoot()
// ...your imports
],
// Other stuff..
})
export class AppModule {
constructor(
ngRedux: NgRedux,
ngReduxRouter: NgReduxRouter
) {
ngRedux.configureStore(/* args */);
ngReduxRouter.initialize(/* args */);
}
}
```### What if I use Immutable.js with my Redux store?
When using a wrapper for your store's state, such as Immutable.js, you will need to change two things from the standard setup:
1. Provide your own reducer function that will receive actions of type `UPDATE_LOCATION` and return the payload merged into state.
2. Pass a selector to access the payload state and convert it to a JS object via the `selectLocationFromState` option on `NgReduxRouter`'s `initialize()`.These two hooks will allow you to store the state that this library uses in whatever format or wrapper you would like.
### What if I have a different way of supplying the current URL of the page?
Depending on your app's needs. It may need to supply the current URL of the page differently than directly
through the router. This can be achieved by initializing the bindings with a second argument: `urlState$`.
The `urlState$` argument lets you give `NgReduxRouter` an `Observable` of the current URL of the page.
If this argument is not given to the bindings, it defaults to subscribing to the `@angular/router`'s events, and
getting the URL from there.### Examples
* [Example-app: An example of using @angular-redux/router along with the other companion packages.](https://github.com/angular-redux/example-app)