24 lines
699 B
JavaScript
24 lines
699 B
JavaScript
import { CALL_HISTORY_METHOD } from './actions';
|
|
|
|
/**
|
|
* This middleware captures CALL_HISTORY_METHOD actions to redirect to the
|
|
* provided history object. This will prevent these actions from reaching your
|
|
* reducer or any middleware that comes after this one.
|
|
*/
|
|
export default function routerMiddleware(history) {
|
|
return function () {
|
|
return function (next) {
|
|
return function (action) {
|
|
if (action.type !== CALL_HISTORY_METHOD) {
|
|
return next(action);
|
|
}
|
|
|
|
var _action$payload = action.payload,
|
|
method = _action$payload.method,
|
|
args = _action$payload.args;
|
|
|
|
history[method].apply(history, args);
|
|
};
|
|
};
|
|
};
|
|
} |