- Notifications
You must be signed in to change notification settings - Fork7
Keep your Angular2+ router state in Redux
License
angular-redux/router
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Please note that this repo has been deprecated. Code and issues are being migrated to a monorepo athttps://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!
Bindings to connect @angular/router to @angular-redux/core
For use with Angular 6: Use v9.
For use with Angular 5: Use v7.
For use with Angular 2-4: Use v6.
- Use npm to install the bindings:
npm install @angular-redux/router --save- Use the
routerReducerwhen providingStore:
import{combineReducers}from'redux';import{routerReducer}from'@angular-redux/router';exportdefaultcombineReducers<IAppState>({// your reducers..router:routerReducer});
- Add the bindings to your root module.
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..})exportclassAppModule{constructor(ngRedux:NgRedux<IAppState>,ngReduxRouter:NgReduxRouter){ngRedux.configureStore(/* args */);ngReduxRouter.initialize(/* args */);}}
When using a wrapper for your store's state, such as Immutable.js, you will need to change two things from the standard setup:
- Provide your own reducer function that will receive actions of type
UPDATE_LOCATIONand return the payload merged into state. - Pass a selector to access the payload state and convert it to a JS object via the
selectLocationFromStateoption onNgReduxRouter'sinitialize().
These two hooks will allow you to store the state that this library uses in whatever format or wrapper you would like.
Depending on your app's needs. It may need to supply the current URL of the page differently than directlythrough the router. This can be achieved by initializing the bindings with a second argument:urlState$.TheurlState$ argument lets you giveNgReduxRouter anObservable<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, andgetting the URL from there.
About
Keep your Angular2+ router state in Redux
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.