我正在尝试安装一个Redux + React路由器应用程序。我认为问题在于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 : state.get不是函数

在state中,这个对象

我用"react": "^15.3.2","redux": "^3.6.0","react-router": "^3.0.0"
更新1我现在使用来自redux-immutable的combineReducers
import {combineReducers} from 'redux-immutable'但是得到一个错误:
Uncaught : routingState.equals不是函数

在此:

更新2
我修正了上面的问题,但是还有一个错误

我在这存储库中发布的所有代码
发布于 2016-12-09 10:07:29
问题仍然存在于src/index.js文件和route.js的require语句中。
当您使用具有require es6模块的default时,您必须使用required模块中的默认值。就像,
const routes = require('./routes').default;这解决了你的问题,没有任何其他改变你的git回购。
发布于 2016-11-30 09:57:16
您使用的combineReducers不使用immutable。通过设置immutable,每个分支都是fromJS(blah),但不是在状态的最高级别上。使用redux-immutable代替:
import {combineReducers} from 'redux-immutable';
https://stackoverflow.com/questions/40883357
复制相似问题