@ngrx/router-store

  • Version 17.2.0
  • Published
  • 498 kB
  • 1 dependency
  • MIT license

Install

npm i @ngrx/router-store
yarn add @ngrx/router-store
pnpm add @ngrx/router-store

Overview

Bindings to connect @angular/router to @ngrx/store

Index

Variables

variable DEFAULT_ROUTER_FEATURENAME

const DEFAULT_ROUTER_FEATURENAME: string;

    variable ROUTER_CANCEL

    const ROUTER_CANCEL: string;
    • An action dispatched when the router cancels navigation.

    variable ROUTER_CONFIG

    const ROUTER_CONFIG: InjectionToken<unknown>;

      variable ROUTER_ERROR

      const ROUTER_ERROR: string;
      • An action dispatched when the router errors.

      variable ROUTER_NAVIGATED

      const ROUTER_NAVIGATED: string;
      • An action dispatched after navigation has ended and new route is active.

      variable ROUTER_NAVIGATION

      const ROUTER_NAVIGATION: string;
      • An action dispatched when the router navigates.

      variable ROUTER_REQUEST

      const ROUTER_REQUEST: string;
      • An action dispatched when a router navigation request is fired.

      variable routerCancelAction

      const routerCancelAction: any;

        variable routerErrorAction

        const routerErrorAction: any;

          variable routerNavigatedAction

          const routerNavigatedAction: any;

            variable routerNavigationAction

            const routerNavigationAction: any;

              variable routerRequestAction

              const routerRequestAction: any;

                Functions

                function createRouterSelector

                createRouterSelector: <State extends Record<string, any>>() => MemoizedSelector<
                State,
                RouterReducerState<SerializedRouterStateSnapshot>
                >;

                  function getRouterSelectors

                  getRouterSelectors: <V extends Record<string, any>>(
                  selectState?: (state: V) => RouterReducerState<any>
                  ) => RouterStateSelectors<V>;

                    function provideRouterStore

                    provideRouterStore: <
                    T extends BaseRouterStoreState = SerializedRouterStateSnapshot
                    >(
                    config?: StoreRouterConfig<T>
                    ) => EnvironmentProviders;
                    • Connects the Angular Router to the Store.

                      bootstrapApplication(AppComponent, {
                      providers: [
                      provideStore({ router: routerReducer }),
                      provideRouterStore(),
                      ],
                      });

                    function routerReducer

                    routerReducer: <
                    RouterState extends BaseRouterStoreState = SerializedRouterStateSnapshot,
                    Result = RouterReducerState<RouterState>
                    >(
                    state: Result | undefined,
                    action: Action
                    ) => Result;

                      Classes

                      class FullRouterStateSerializer

                      class FullRouterStateSerializer
                      implements RouterStateSerializer<SerializedRouterStateSnapshot> {}

                        method serialize

                        serialize: (routerState: RouterStateSnapshot) => SerializedRouterStateSnapshot;

                          class MinimalRouterStateSerializer

                          class MinimalRouterStateSerializer
                          implements RouterStateSerializer<MinimalRouterStateSnapshot> {}

                            method serialize

                            serialize: (routerState: RouterStateSnapshot) => MinimalRouterStateSnapshot;

                              class RouterStateSerializer

                              abstract class RouterStateSerializer<
                              T extends BaseRouterStoreState = BaseRouterStoreState
                              > {}

                                method serialize

                                abstract serialize: (routerState: RouterStateSnapshot) => T;

                                  class StoreRouterConnectingModule

                                  class StoreRouterConnectingModule {}
                                  • Connects RouterModule with StoreModule.

                                    During the navigation, before any guards or resolvers run, the router will dispatch a ROUTER_NAVIGATION action, which has the following signature:

                                    export type RouterNavigationPayload = {
                                    routerState: SerializedRouterStateSnapshot,
                                    event: RoutesRecognized
                                    }

                                    Either a reducer or an effect can be invoked in response to this action. If the invoked reducer throws, the navigation will be canceled.

                                    If navigation gets canceled because of a guard, a ROUTER_CANCEL action will be dispatched. If navigation results in an error, a ROUTER_ERROR action will be dispatched.

                                    Both ROUTER_CANCEL and ROUTER_ERROR contain the store state before the navigation which can be used to restore the consistency of the store.

                                    Usage:

                                    @NgModule({
                                    declarations: [AppCmp, SimpleCmp],
                                    imports: [
                                    BrowserModule,
                                    StoreModule.forRoot(mapOfReducers),
                                    RouterModule.forRoot([
                                    { path: '', component: SimpleCmp },
                                    { path: 'next', component: SimpleCmp }
                                    ]),
                                    StoreRouterConnectingModule.forRoot()
                                    ],
                                    bootstrap: [AppCmp]
                                    })
                                    export class AppModule {
                                    }

                                  property ɵfac

                                  static ɵfac: i0.ɵɵFactoryDeclaration<StoreRouterConnectingModule, never>;

                                    property ɵinj

                                    static ɵinj: i0.ɵɵInjectorDeclaration<StoreRouterConnectingModule>;

                                      property ɵmod

                                      static ɵmod: i0.ɵɵNgModuleDeclaration<
                                      StoreRouterConnectingModule,
                                      never,
                                      never,
                                      never
                                      >;

                                        method forRoot

                                        static forRoot: <T extends BaseRouterStoreState = SerializedRouterStateSnapshot>(
                                        config?: StoreRouterConfig<T>
                                        ) => ModuleWithProviders<StoreRouterConnectingModule>;

                                          Interfaces

                                          interface BaseRouterStoreState

                                          interface BaseRouterStoreState {}
                                          • Simple router state. All custom router states / state serializers should have at least the properties of this interface.

                                          property url

                                          url: string;

                                            interface MinimalActivatedRouteSnapshot

                                            interface MinimalActivatedRouteSnapshot {}

                                              property children

                                              children: MinimalActivatedRouteSnapshot[];

                                                property data

                                                data: ActivatedRouteSnapshot['data'];

                                                  property firstChild

                                                  firstChild?: MinimalActivatedRouteSnapshot;

                                                    property fragment

                                                    fragment: ActivatedRouteSnapshot['fragment'];

                                                      property outlet

                                                      outlet: ActivatedRouteSnapshot['outlet'];

                                                        property params

                                                        params: ActivatedRouteSnapshot['params'];

                                                          property queryParams

                                                          queryParams: ActivatedRouteSnapshot['queryParams'];

                                                            property routeConfig

                                                            routeConfig: ActivatedRouteSnapshot['routeConfig'];

                                                              property title

                                                              title: ActivatedRouteSnapshot['title'];

                                                                property url

                                                                url: ActivatedRouteSnapshot['url'];

                                                                  interface MinimalRouterStateSnapshot

                                                                  interface MinimalRouterStateSnapshot extends BaseRouterStoreState {}

                                                                    property root

                                                                    root: MinimalActivatedRouteSnapshot;

                                                                      property url

                                                                      url: string;

                                                                        interface SerializedRouterStateSnapshot

                                                                        interface SerializedRouterStateSnapshot extends BaseRouterStoreState {}

                                                                          property root

                                                                          root: ActivatedRouteSnapshot;

                                                                            property url

                                                                            url: string;

                                                                              interface StoreRouterConfig

                                                                              interface StoreRouterConfig<
                                                                              T extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                              > {}

                                                                                property navigationActionTiming

                                                                                navigationActionTiming?: NavigationActionTiming;
                                                                                • By default, ROUTER_NAVIGATION is dispatched before guards and resolvers run. Therefore, the action could run too soon, for example there may be a navigation cancel due to a guard saying the navigation is not allowed. To run ROUTER_NAVIGATION after guards and resolvers, set this property to NavigationActionTiming.PostActivation.

                                                                                property routerState

                                                                                routerState?: RouterState;
                                                                                • Decides which router serializer should be used, if there is none provided, and the metadata on the dispatched @ngrx/router-store action payload. Set to Minimal to use the MinimalRouterStateSerializer and to set a minimal router event with the navigation id and url as payload. Set to Full to use the FullRouterStateSerializer and to set the angular router events as payload.

                                                                                property serializer

                                                                                serializer?: new (...args: any[]) => RouterStateSerializer;

                                                                                  property stateKey

                                                                                  stateKey?: StateKeyOrSelector<T>;

                                                                                    Enums

                                                                                    enum NavigationActionTiming {
                                                                                    PreActivation = 1,
                                                                                    PostActivation = 2,
                                                                                    }
                                                                                      PostActivation = 2
                                                                                        PreActivation = 1

                                                                                          enum RouterState

                                                                                          const enum RouterState {
                                                                                          Full = 0,
                                                                                          Minimal = 1,
                                                                                          }
                                                                                          • Minimal = Serializes the router event with MinimalRouterStateSerializer Full = Serializes the router event with FullRouterStateSerializer

                                                                                          member Full

                                                                                          Full = 0

                                                                                            member Minimal

                                                                                            Minimal = 1

                                                                                              Type Aliases

                                                                                              type RouterAction

                                                                                              type RouterAction<
                                                                                              T,
                                                                                              V extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                              > =
                                                                                              | RouterRequestAction<V>
                                                                                              | RouterNavigationAction<V>
                                                                                              | RouterCancelAction<T, V>
                                                                                              | RouterErrorAction<T, V>
                                                                                              | RouterNavigatedAction<V>;
                                                                                              • A union type of router actions.

                                                                                              type RouterCancelAction

                                                                                              type RouterCancelAction<
                                                                                              T,
                                                                                              V extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                              > = {
                                                                                              type: typeof ROUTER_CANCEL;
                                                                                              payload: RouterCancelPayload<T, V>;
                                                                                              };
                                                                                              • An action dispatched when the router cancels navigation.

                                                                                              type RouterCancelPayload

                                                                                              type RouterCancelPayload<
                                                                                              T,
                                                                                              V extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                              > = {
                                                                                              routerState: V;
                                                                                              storeState: T;
                                                                                              event: NavigationCancel;
                                                                                              };
                                                                                              • Payload of ROUTER_CANCEL.

                                                                                              type RouterErrorAction

                                                                                              type RouterErrorAction<
                                                                                              T,
                                                                                              V extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                              > = {
                                                                                              type: typeof ROUTER_ERROR;
                                                                                              payload: RouterErrorPayload<T, V>;
                                                                                              };
                                                                                              • An action dispatched when the router errors.

                                                                                              type RouterErrorPayload

                                                                                              type RouterErrorPayload<
                                                                                              T,
                                                                                              V extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                              > = {
                                                                                              routerState: V;
                                                                                              storeState: T;
                                                                                              event: NavigationError;
                                                                                              };
                                                                                              • Payload of ROUTER_ERROR.

                                                                                              type RouterNavigatedAction

                                                                                              type RouterNavigatedAction<
                                                                                              T extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                              > = {
                                                                                              type: typeof ROUTER_NAVIGATED;
                                                                                              payload: RouterNavigatedPayload<T>;
                                                                                              };
                                                                                              • An action dispatched after navigation has ended and new route is active.

                                                                                              type RouterNavigatedPayload

                                                                                              type RouterNavigatedPayload<
                                                                                              T extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                              > = {
                                                                                              routerState: T;
                                                                                              event: NavigationEnd;
                                                                                              };
                                                                                              • Payload of ROUTER_NAVIGATED.

                                                                                              type RouterNavigationAction

                                                                                              type RouterNavigationAction<
                                                                                              T extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                              > = {
                                                                                              type: typeof ROUTER_NAVIGATION;
                                                                                              payload: RouterNavigationPayload<T>;
                                                                                              };
                                                                                              • An action dispatched when the router navigates.

                                                                                              type RouterNavigationPayload

                                                                                              type RouterNavigationPayload<
                                                                                              T extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                              > = {
                                                                                              routerState: T;
                                                                                              event: RoutesRecognized;
                                                                                              };
                                                                                              • Payload of ROUTER_NAVIGATION.

                                                                                              type RouterReducerState

                                                                                              type RouterReducerState<
                                                                                              T extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                              > = {
                                                                                              state: T;
                                                                                              navigationId: number;
                                                                                              };

                                                                                                type RouterRequestAction

                                                                                                type RouterRequestAction<
                                                                                                T extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                                > = {
                                                                                                type: typeof ROUTER_REQUEST;
                                                                                                payload: RouterRequestPayload<T>;
                                                                                                };
                                                                                                • An action dispatched when a router navigation request is fired.

                                                                                                type RouterRequestPayload

                                                                                                type RouterRequestPayload<
                                                                                                T extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                                > = {
                                                                                                routerState: T;
                                                                                                event: NavigationStart;
                                                                                                };
                                                                                                • Payload of ROUTER_REQUEST

                                                                                                type StateKeyOrSelector

                                                                                                type StateKeyOrSelector<
                                                                                                T extends BaseRouterStoreState = SerializedRouterStateSnapshot
                                                                                                > = string | Selector<any, RouterReducerState<T>>;

                                                                                                  Package Files (10)

                                                                                                  Dependencies (1)

                                                                                                  Dev Dependencies (0)

                                                                                                  No dev dependencies.

                                                                                                  Peer Dependencies (5)

                                                                                                  Badge

                                                                                                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@ngrx/router-store.

                                                                                                  • Markdown
                                                                                                    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@ngrx/router-store)
                                                                                                  • HTML
                                                                                                    <a href="https://www.jsdocs.io/package/@ngrx/router-store"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>