1

目前,我的 redux 设置(它使用 Immutable.js 作为其状态)完全按照需要运行。但是,redux 开发工具扩展在打开时会输出以下错误:

reducer 发生错误 TypeError: n.withMutations is not a function

对于上下文,我将redux-immutable用于它的 combine reducers 功能,以组合我的 react-router-redux reducer:

import { fromJS } from 'immutable';
import { LOCATION_CHANGE } from 'react-router-redux';

const initialState = fromJS({
  locationBeforeTransitions: null,
});

export default (state = initialState, action) => {
  if (action.type === LOCATION_CHANGE) {
    return state.merge({
      locationBeforeTransitions: action.payload,
    });
  }
  return state;
};

和我的业务逻辑减速器。

更新:使用 webpack 构建生产包,在生产模式下测试应用程序(在 docker 容器中),并在开发模式下再次测试应用程序(在没有 docker 的本地机器上)似乎已经解决了问题?奇怪的...

4

1 回答 1

1

如果你想使用react-router-redux,不需要自己实现reducer,只需从react-router-redux下面导入routerReducer作为关键路由(重要)并与其他reducer结合,

import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
// Add the reducer to your store on the `routing` key
const store = createStore(
  combineReducers({
    ...reducers,
    routing: routerReducer
  })
)

//To Sync navigation events with the store
const history = syncHistoryWithStore(browserHistory, store)

ReactDOM.render(
  <Provider store={store}>
    { /* Tell the Router to use our enhanced history */ }
    <Router history={history}>
      <Route path="/" component={App}>
        <Route path="foo" component={Foo}/>
        <Route path="bar" component={Bar}/>
      </Route>
    </Router>
  </Provider>,
  document.getElementById('mount')
)

希望这是您要实施的

于 2016-04-30T04:54:34.560 回答