在 reducer 之后调用 Redux 中间件

Redux middleware is being called after reducer

我创建了一个这样的中间件:

export default store => next => action => {
    const res = next(action)

    console.log("Middleware", action.type)

    return res
} 

我的商店配置是:

import { createBrowserHistory } from 'history';
import { applyMiddleware, compose, createStore } from 'redux';
import { routerMiddleware } from 'connected-react-router';
import middleware from './middleware'

import rootReducer from './reducers';

export const history = createBrowserHistory();

const defaultState = {};

const composeEnhancers =
  typeof window === 'object' &&
  window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?   
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
    }) : compose;

const enhancer = composeEnhancers(
  applyMiddleware(middleware, routerMiddleware(history)),
);

export const store = createStore(
  rootReducer(history),
  defaultState,
  enhancer
);

我也有一个减速器,我在日志和调试器中看到首先调用减速器,然后调用中间件。关于我配置错误的任何建议?

如果我没记错的话,reducer 在你调用 next(action) 时被调用。将你的 console.log 移到上面,这应该会给你你想要的日志顺序。