0.4.0 • Published 9 years ago
ngrx-store-router v0.4.0
ngrx-store-router
Sync between the current Angular 2 Router URL and @ngrx/store
This service is to be used along with @ngrx/store and @ngrx/store-devtools to navigate between routes while changing state
Demo
http://plnkr.co/edit/Gvg9fW?p=preview
Installation
- Install from npm : DEPRECATED Router
npm install ngrx-store-router@0.2.0 --save - Install from npm :
npm install ngrx-store-router --save
Usage
- In your app's main module, import the router reducer, add the reducer to the
provideStore()function under the namerouter, and add theprovideRouterConnector()to provide them to Angular 2.
import {bootstrap} from '@angular/platform-browser-dynamic';
import {provideStore} from '@ngrx/store';
import {App} from './app';
import {routerReducer, provideRouterConnector} from 'ngrx-store-router';
bootstrap(App, [
provideStore({router: routerReducer}),
provideRouterConnector()
]);- In your app's main component, import the
RouterConnectorservice and call theconnectfunction to initialize the router sync to the store. To stop the router from syncing with the store, use thedisconnectfunction.
import {Component, OnInit, OnDestroy} from '@angular/core';
import {RouterConnector} from 'ngrx-store-router';
@Component({ ... })
export class App implements OnInit, OnDestroy {
constructor(private rc: RouterConnector) {}
ngOnInit() {
this.rc.connect();
}
ngOnDestroy() {
this.rc.disconnect();
}
}Contributing
Pull requests and issues are welcome