javascript – React Redux路由器错误

我正在尝试设置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

enter image description here

在状态这个对象

enter image description here

我使用“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

enter image description here

这里:

enter image description here

更新2

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

enter image description here

我在this存储库中发布的所有代码

解决方法

问题保留在带有route.js的require语句的src / index.js文件中.

当您需要具有认值的es6模块时,您必须使用所需模块的认值.就像是,

const routes = require('./routes').default;

解决了你的问题,而你的git仓库没有任何其他变化.

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...