Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@angular-redux/router

Package Overview
Dependencies
Maintainers
8
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@angular-redux/router

Keep your Angular 2+ router state in Redux.

  • 10.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.5K
decreased by-5.36%
Maintainers
8
Weekly downloads
 
Created
Source

@angular-redux/router

npm version downloads per month

Bindings to connect @angular/router to @angular-redux/core

Setup

  1. Use npm to install the bindings:
npm install @angular-redux/router --save
  1. Use the routerReducer when providing Store:
import { combineReducers } from 'redux';
import { routerReducer } from '@angular-redux/router';

export default combineReducers<IAppState>({
  // your reducers..
  router: routerReducer,
});
  1. 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..
})
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

Keywords

FAQs

Package last updated on 04 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc