Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript react router redux破坏我的应用程序状态_Javascript_Reactjs_Ecmascript 6_React Router_Redux - Fatal编程技术网

Javascript react router redux破坏我的应用程序状态

Javascript react router redux破坏我的应用程序状态,javascript,reactjs,ecmascript-6,react-router,redux,Javascript,Reactjs,Ecmascript 6,React Router,Redux,我试图在我的应用程序中设置react router redux(如图所示),但它破坏了我的状态 以下是我的店铺设置: import { createStore, applyMiddleware } from 'redux' import { combineReducers } from 'redux' import thunk from 'redux-thunk' import { syncHistory, routeReducer } from 'react-router-redux' imp

我试图在我的应用程序中设置react router redux(如图所示),但它破坏了我的状态

以下是我的店铺设置:

import { createStore, applyMiddleware } from 'redux'
import { combineReducers } from 'redux'
import thunk from 'redux-thunk'
import { syncHistory, routeReducer } from 'react-router-redux'
import rootReducer from '../reducers'
import Immutable, {Map} from 'immutable'
[Other imports]

const middleware = [X,Y]

const reducer = combineReducers(Object.assign({}, rootReducer, {
  routing: routeReducer
}));

export default function configureStore(initialState, history) {

   const reduxRouterMiddleware = syncHistory(history);
   middleware.push(reduxRouterMiddleware);

   const createStoreWithMiddleware = applyMiddleware(...middleware)(createStore);

   const store = createStoreWithMiddleware(reducer, initialState);     

   return store

}
这是我的reducers/index.js:

import { combineReducers } from 'redux'
import A from './A'
import B from './B'
import C from './C'
...

const rootReducer = combineReducers({
  A,
  B,
  C,
  ...
})

export default rootReducer
当我在我的应用程序my store.getState()中输入console.log时,我得到:仅一个routing.location树

如果在创建存储时使用“rootReducer”而不是“reducer”,则会得到正常的状态树(A、B、C…)

但我当然不再得到我感兴趣的路由。位置部分

我做错了什么


谢谢大家!

我认为这是因为您在自己的reducer上调用
combineReducer
,然后再次合并到
路由
reducer中。我只需从您自己的减速器中导出一个对象,然后执行一次
组合减速器
调用,在那里您可以
对象。将
路由减速器分配到中。

我认为问题出在这里:

const reducer = combineReducers(Object.assign({}, rootReducer, {
  routing: routeReducer
}));
rootReducer不是普通对象,而是由方法combineReducer返回的函数,如下所示:

function combination() {
    var state = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
    var action = arguments[1]; ...
}
函数组合(){

var state=arguments.length谢谢Steven!删除对CombineReducer的第一个调用(在reducers/index.js中)是有效的!因为reducer已经是一个函数,我认为可以将一个reducer组合与另一个reducer合并…显然这是不可能的:-)…也谢谢@larrydahooster!删除对CombineReducer的第一个调用(在reducers/index.js中)成功了!如果我写了
combinereducer({rootReducer,routing:routeReducer})