我正在尝试设置Redux React Router应用程序.我认为问题出在ImmutableJS上,但我不明白如何解决它.
client.js
import { fromJS } from 'immutable' import React from 'react' import { render,unmountComponentAtNode } from 'react-dom' import { AppContainer } from 'react-hot-loader' import { Provider } from 'react-redux' import { match,Router,browserHistory } from 'react-router' import { syncHistoryWithStore } from 'react-router-redux' import { createStore,combineReducers,compose,applyMiddleware } from 'redux' import { routerReducer,routerMiddleware } from 'react-router-redux' function createSelectLocationState(reducerName) { let prevRoutingState; let prevRoutingStateJS; return (state) => { const routingState = state.get(reducerName); // or state.routing if (!routingState.equals(prevRoutingState)) { prevRoutingState = routingState; prevRoutingStateJS = routingState.toJS(); } return prevRoutingStateJS; }; } function configureStore(history,initialState) { const reducer = combineReducers({ routing: routerReducer }); return createStore( reducer,initialState,compose( applyMiddleware( routerMiddleware(history) ) ) ); } const initialState = fromJS(window.__INITIAL_STATE__); const store = configureStore(browserHistory,initialState); const history = syncHistoryWithStore(browserHistory,store,{ selectLocationState: createSelectLocationState('routing') }); const rootNode = document.getElementById('root'); const renderApp = () => { const routes = require('./routes'); match({ history,routes },(error,redirectLocation,renderProps) => { render( <AppContainer> <Provider store={store}> <Router {...renderProps} /> </Provider> </AppContainer>,rootNode ); }); }; // Enable hot reload by react-hot-loader if (module.hot) { const reRenderApp = () => { try { renderApp(); } catch (error) { const RedBox = require('redBox-react').default; render(<RedBox error={error} />,rootNode); } }; module.hot.accept('./routes',() => { setImmediate(() => { // Preventing the hot reloading error from react-router unmountComponentAtNode(rootNode); reRenderApp(); }); }); } renderApp();
我收到此错误:
Uncaught TypeError: state.get is not a function
在状态这个对象
我使用“react”:“^ 15.3.2”,“redux”:“^ 3.6.0”,“react-router”:“^ 3.0.0”
更新1
我现在使用redux-immutable的combineReducers:
import {combineReducers} from 'redux-immutable'
Uncaught TypeError: routingState.equals is not a function
这里:
更新2
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。