Skip to content

Commit 6b6b404

Browse files
committed
fix #79
1 parent f434fea commit 6b6b404

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-first-history",
3-
"version": "5.1.0",
3+
"version": "5.1.1",
44
"description": "Redux First History - Redux history binding support react-router - @reach/router - wouter",
55
"main": "build/es5/index.js",
66
"module": "build/es6/index.js",

src/actions.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Location, Action, History } from 'history';
2-
import type { AnyAction as ReduxAction } from 'redux';
32

43
export const CALL_HISTORY_METHOD = '@@router/CALL_HISTORY_METHOD';
54
export const LOCATION_CHANGE = '@@router/LOCATION_CHANGE';
@@ -19,22 +18,43 @@ export const locationChangeAction = (location: Location, action: Action) => ({
1918
payload: { location, action } as { location: Location; action: Action },
2019
});
2120

21+
export interface LocationActionPayload<A = unknown[]> {
22+
method: string;
23+
args?: A;
24+
}
25+
26+
export interface CallHistoryMethodAction<A = unknown[]> {
27+
type: typeof CALL_HISTORY_METHOD;
28+
payload: LocationActionPayload<A>;
29+
}
30+
2231
function updateLocation<T extends HistoryMethods>(method: T) {
23-
// @ts-ignore
24-
return (...args: Parameters<History[T]>): ReduxAction => ({
32+
// @ts-ignore //support history 5.x back/forward
33+
return (...args: Parameters<History[T]>): CallHistoryMethodAction<Parameters<History[T]>> => ({
2534
type: CALL_HISTORY_METHOD as typeof CALL_HISTORY_METHOD,
2635
payload: { method, args },
2736
});
2837
}
2938

30-
export const push: (...args: Parameters<History['push']>) => ReduxAction = updateLocation('push');
31-
export const replace: (...args: Parameters<History['replace']>) => ReduxAction =
32-
updateLocation('replace');
33-
export const go: (...args: Parameters<History['go']>) => ReduxAction = updateLocation('go');
34-
export const goBack: () => ReduxAction = updateLocation('goBack');
35-
export const goForward: () => ReduxAction = updateLocation('goForward');
36-
export const back: () => ReduxAction = updateLocation('back');
37-
export const forward: () => ReduxAction = updateLocation('forward');
39+
export const push: (
40+
...args: Parameters<History['push']>
41+
) => CallHistoryMethodAction<Parameters<History['push']>> = updateLocation('push');
42+
export const replace: (
43+
...args: Parameters<History['replace']>
44+
) => CallHistoryMethodAction<Parameters<History['replace']>> = updateLocation('replace');
45+
export const go: (
46+
...args: Parameters<History['go']>
47+
) => CallHistoryMethodAction<Parameters<History['go']>> = updateLocation('go');
48+
export const goBack: () => CallHistoryMethodAction<Parameters<History['goBack']>> =
49+
updateLocation('goBack');
50+
export const goForward: () => CallHistoryMethodAction<Parameters<History['goForward']>> =
51+
updateLocation('goForward');
52+
// @ts-ignore //support history 5.x back/forward
53+
export const back: () => CallHistoryMethodAction<Parameters<History['back']>> =
54+
updateLocation('back');
55+
// @ts-ignore //support history 5.x back/forward
56+
export const forward: () => CallHistoryMethodAction<Parameters<History['forward']>> =
57+
updateLocation('forward');
3858

3959
export type RouterActions =
4060
| ReturnType<typeof push>

0 commit comments

Comments
 (0)