@lagunovsky/redux-react-router
Version:
A Redux binding for React Router v6
100 lines (99 loc) • 4.65 kB
TypeScript
import { Action, History, Location } from 'history';
import React from 'react';
import { Middleware, Reducer, UnknownAction } from 'redux';
export type Methods = 'push' | 'replace' | 'go' | 'back' | 'forward';
/**
* This action type will be dispatched when your history
* receives a location change.
*/
export declare const ROUTER_ON_LOCATION_CHANGED = "@@router/ON_LOCATION_CHANGED";
export type LocationChangeAction = {
type: typeof ROUTER_ON_LOCATION_CHANGED;
payload: {
location: Location;
action: Action;
};
};
export declare const onLocationChanged: (location: Location, action: Action) => LocationChangeAction;
export declare function matchLocationChangeAction(action: UnknownAction): action is LocationChangeAction;
/**
* This action type will be dispatched by the history actions below.
* If you're writing a middleware to watch for navigation events, be sure to
* look for actions of this type.
*/
export declare const ROUTER_CALL_HISTORY_METHOD = "@@router/CALL_HISTORY_METHOD";
type UpdateLocationAction<M extends Methods> = {
type: typeof ROUTER_CALL_HISTORY_METHOD;
payload: {
method: M;
args: Parameters<History[M]>;
asEffect: boolean;
};
};
export declare function matchUpdateLocationActions(action: UnknownAction): action is UpdateLocationActions;
/**
* Pushes a new location onto the history stack, increasing its length by one.
* If there were any entries in the stack after the current one, they are
* lost.
*
* @param to - The new URL
* @param state - Data to associate with the new location
*/
export declare const push: (to: import("history").To, state?: any) => UpdateLocationAction<"push">;
export declare const pushStraight: (to: import("history").To, state?: any) => UpdateLocationAction<"push">;
/**
* Replaces the current location in the history stack with a new one. The
* location that was replaced will no longer be available.
*
* @param to - The new URL
* @param state - Data to associate with the new location
*/
export declare const replace: (to: import("history").To, state?: any) => UpdateLocationAction<"replace">;
export declare const replaceStraight: (to: import("history").To, state?: any) => UpdateLocationAction<"replace">;
/**
* Navigates to the next entry in the stack. Identical to go(1).
*/
export declare const go: (delta: number) => UpdateLocationAction<"go">;
export declare const goStraight: (delta: number) => UpdateLocationAction<"go">;
/**
* Goes back one entry in the history stack. Identical to go(-1).
*/
export declare const back: () => UpdateLocationAction<"back">;
export declare const backStraight: () => UpdateLocationAction<"back">;
/**
* Navigates to the next entry in the stack. Identical to go(1).
*/
export declare const forward: () => UpdateLocationAction<"forward">;
export declare const forwardStraight: () => UpdateLocationAction<"forward">;
export declare const routerActions: {
push: (to: import("history").To, state?: any) => UpdateLocationAction<"push">;
replace: (to: import("history").To, state?: any) => UpdateLocationAction<"replace">;
go: (delta: number) => UpdateLocationAction<"go">;
back: () => UpdateLocationAction<"back">;
forward: () => UpdateLocationAction<"forward">;
};
export type UpdateLocationActions = ReturnType<typeof push> | ReturnType<typeof replace> | ReturnType<typeof go> | ReturnType<typeof back> | ReturnType<typeof forward>;
export type RouterActions = LocationChangeAction | UpdateLocationActions;
export declare function createRouterMiddleware(history: History): Middleware;
export declare const ROUTER_REDUCER_MAP_KEY = "router";
export type ReduxRouterState = {
location: Location;
action: Action;
};
export declare function createRouterReducer(history: History): Reducer<ReduxRouterState>;
export declare function createRouterReducerMapObject(history: History): {
router: Reducer<ReduxRouterState, UnknownAction, ReduxRouterState>;
};
export type ReduxRouterSelector<T = any> = (state: T) => ReduxRouterState;
export type ReduxRouterStoreState = {
[ROUTER_REDUCER_MAP_KEY]: ReduxRouterState;
};
export declare function reduxRouterSelector<T extends ReduxRouterStoreState = ReduxRouterStoreState>(state: T): ReduxRouterState;
export type ReduxRouterProps = {
history: History;
basename?: string;
children?: React.ReactNode;
routerSelector?: ReduxRouterSelector;
};
export declare function ReduxRouter({ routerSelector, ...props }: ReduxRouterProps): import("react/jsx-runtime").JSX.Element;
export {};