connected-react-router#CALL_HISTORY_METHOD TypeScript Examples
The following examples show how to use
connected-react-router#CALL_HISTORY_METHOD.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: router.tsx From reactant with MIT License | 6 votes |
constructor(@inject(RouterOptions) protected options: IRouterOptions) {
super();
const { autoProvide = true, stateKey = 'router' } = this.options || {};
this.autoProvide = autoProvide;
this.stateKey = stateKey;
this.autoCreateHistory = this.options?.autoCreateHistory ?? true;
if (this.autoCreateHistory) {
this.history = this.options.createHistory();
this.middleware = (store) => (next) => (action: RouterAction) => {
if (action.type !== CALL_HISTORY_METHOD) {
if (
action.type === LOCATION_CHANGE &&
action?.payload?.isFirstRendering === false &&
this.history.location !== action.payload.location
) {
this.history.replace(action.payload.location);
}
return next(action);
}
const {
payload: { method, args = [] },
} = action;
const history: Record<string, Function> = this.history as any;
history[method](...args);
};
}
}