2.0.0 • Published 8 years ago

ng2-redux-router v2.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

ng2-redux-router 2.0.0

Bindings to connect @angular/router to ng2-redux

Updated for Angular 2 final release.

This package uses the new v3 router for angular 2 @angular/router@^3.1.2.

Setup

  1. Use npm to install the bindings:

    npm install ng2-redux-router --save
  2. Use the routerReducer when providing Store:

    import { combineReducers } from 'redux';
    import { routerReducer } from 'ng2-redux-router';
    
    export default combineReducers<IAppState>({
      // your reducers..
      router: routerReducer
    });
  3. Add the bindings to your root module.

    import { NgModule } from '@angular/core';
    import { NgReduxModule, NgRedux } from 'ng2-redux';
    import { NgReduxRouterModule, NgReduxRouter } from 'ng2-redux-router';
    import { RouterModule } from '@angular/router';
    import { routes } from './routes';
    
    @NgModule({
      imports: [
        RouterModule.forRoot(routes),
        NgReduxModule.forRoot(),
        NgReduxRouterModule
        // ...your imports
      ],
      // Other stuff..
    })
    export class AppModule {
      constructor(
        ngRedux: NgRedux<IAppState>,
        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<string>` 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

* [Counter: basic setup of ng2-redux-router](examples/counter)
2.0.0

8 years ago

1.3.3

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago