Issues (6)

src/middleware.js (2 issues)

1
import { ACTION_PREFIX, ACTION_TYPES, HISTORY_METHODS} from './constants';
2
import { parsePath } from 'history';
3
4
export default ({ history, routeParser }) => ({ dispatch, getState }) => next => action => {
0 ignored issues
show
The parameter getState is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
The parameter dispatch is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
5
6
    if (action.type.indexOf(ACTION_PREFIX) === 0 && action.type !== ACTION_TYPES.LOCATION_CHANGED) {
7
8
        if (action.type === ACTION_TYPES.GO_TO_ROUTE) {
9
            action.type = ACTION_TYPES.PUSH;
10
            action.payload = routeParser(action.payload);
11
        }
12
13
        if ([ACTION_TYPES.PUSH, ACTION_TYPES.REPLACE].includes(action.type)) {
14
15
            action.payload = typeof action.payload === 'string' ? parsePath(action.payload) : action.payload;
16
17
            const sameLocation = history.location.pathname === action.payload.pathname
18
                              && history.location.search === action.payload.search
19
                              && history.location.hash === action.payload.hash;
20
21
            action.type = sameLocation ? ACTION_TYPES.REPLACE : action.type;
22
        }
23
24
        if (HISTORY_METHODS[action.type]) {
25
            history[HISTORY_METHODS[action.type]](action.payload);
26
        }
27
28
        return;
29
    }
30
31
    return next(action); // eslint-disable-line consistent-return
32
};