UNPKG

4.51 kBTypeScriptView Raw
1import { InjectionToken, ModuleWithProviders, ErrorHandler } from '@angular/core';
2import { Router } from '@angular/router';
3import { RuntimeChecks, Selector, Store } from '@ngrx/store';
4import { RouterReducerState } from './reducer';
5import { RouterStateSerializer, BaseRouterStoreState } from './serializers/base';
6import { SerializedRouterStateSnapshot } from './serializers/default_serializer';
7export declare type StateKeyOrSelector<T extends BaseRouterStoreState = SerializedRouterStateSnapshot> = string | Selector<any, RouterReducerState<T>>;
8/**
9 * Full = Serializes the router event with DefaultRouterStateSerializer
10 * Minimal = Serializes the router event with MinimalRouterStateSerializer
11 */
12export declare const enum RouterState {
13 Full = 0,
14 Minimal = 1
15}
16export interface StoreRouterConfig<T extends BaseRouterStoreState = SerializedRouterStateSnapshot> {
17 stateKey?: StateKeyOrSelector<T>;
18 serializer?: new (...args: any[]) => RouterStateSerializer;
19 /**
20 * By default, ROUTER_NAVIGATION is dispatched before guards and resolvers run.
21 * Therefore, the action could run too soon, for example
22 * there may be a navigation cancel due to a guard saying the navigation is not allowed.
23 * To run ROUTER_NAVIGATION after guards and resolvers,
24 * set this property to NavigationActionTiming.PostActivation.
25 */
26 navigationActionTiming?: NavigationActionTiming;
27 /**
28 * Decides which router serializer should be used, if there is none provided, and the metadata on the dispatched @ngrx/router-store action payload.
29 * Set to `Full` to use the `DefaultRouterStateSerializer` and to set the angular router events as payload.
30 * Set to `Minimal` to use the `MinimalRouterStateSerializer` and to set a minimal router event with the navigation id and url as payload.
31 */
32 routerState?: RouterState;
33}
34export declare enum NavigationActionTiming {
35 PreActivation = 1,
36 PostActivation = 2
37}
38export declare const _ROUTER_CONFIG: InjectionToken<unknown>;
39export declare const ROUTER_CONFIG: InjectionToken<unknown>;
40export declare const DEFAULT_ROUTER_FEATURENAME = "router";
41export declare function _createRouterConfig(config: StoreRouterConfig): StoreRouterConfig;
42/**
43 * Connects RouterModule with StoreModule.
44 *
45 * During the navigation, before any guards or resolvers run, the router will dispatch
46 * a ROUTER_NAVIGATION action, which has the following signature:
47 *
48 * ```
49 * export type RouterNavigationPayload = {
50 * routerState: SerializedRouterStateSnapshot,
51 * event: RoutesRecognized
52 * }
53 * ```
54 *
55 * Either a reducer or an effect can be invoked in response to this action.
56 * If the invoked reducer throws, the navigation will be canceled.
57 *
58 * If navigation gets canceled because of a guard, a ROUTER_CANCEL action will be
59 * dispatched. If navigation results in an error, a ROUTER_ERROR action will be dispatched.
60 *
61 * Both ROUTER_CANCEL and ROUTER_ERROR contain the store state before the navigation
62 * which can be used to restore the consistency of the store.
63 *
64 * Usage:
65 *
66 * ```typescript
67 * @NgModule({
68 * declarations: [AppCmp, SimpleCmp],
69 * imports: [
70 * BrowserModule,
71 * StoreModule.forRoot(mapOfReducers),
72 * RouterModule.forRoot([
73 * { path: '', component: SimpleCmp },
74 * { path: 'next', component: SimpleCmp }
75 * ]),
76 * StoreRouterConnectingModule.forRoot()
77 * ],
78 * bootstrap: [AppCmp]
79 * })
80 * export class AppModule {
81 * }
82 * ```
83 */
84export declare class StoreRouterConnectingModule {
85 private store;
86 private router;
87 private serializer;
88 private errorHandler;
89 private config;
90 private activeRuntimeChecks;
91 private lastEvent;
92 private routerState;
93 private storeState;
94 private trigger;
95 private stateKey;
96 static forRoot<T extends BaseRouterStoreState = SerializedRouterStateSnapshot>(config?: StoreRouterConfig<T>): ModuleWithProviders<StoreRouterConnectingModule>;
97 constructor(store: Store<any>, router: Router, serializer: RouterStateSerializer<SerializedRouterStateSnapshot>, errorHandler: ErrorHandler, config: StoreRouterConfig, activeRuntimeChecks: RuntimeChecks);
98 private setUpStoreStateListener;
99 private navigateIfNeeded;
100 private setUpRouterEventsListener;
101 private dispatchRouterRequest;
102 private dispatchRouterNavigation;
103 private dispatchRouterCancel;
104 private dispatchRouterError;
105 private dispatchRouterNavigated;
106 private dispatchRouterAction;
107 private reset;
108}