2017-02-13 14 views
0

でストアを作成し、少し古いですチュートリアルに従うことをしようとしたとき、私はこのコードを実行しようとするので、私は取得エラー:リアクト - ルータ - Reduxのエラー反応-Reduxのをするために、私は新たなんだミドルウェア

キャッチされませんエラー:ルーティング状態がstate.routing、またはsyncHistoryWithStore()オプションでselectLocationStateとして指定できるカスタム式として使用できるようになりました。店舗のレデューサーにrouterReducerを追加したことを確認してください。combineReducersまたはレデューサーの分離方法は問わないものとします。

ヒント? :)

index.js

import React from 'react' 
import ReactDOM from "react-dom" 
import { createStore, applyMiddleware } from 'redux' 
import { Provider } from 'react-redux' 
import { Router, Route, browserHistory } from 'react-router' 
import { syncHistoryWithStore, routerReducer } from 'react-router-redux' 
import App from './containers/App' 
import rootReducer from './reducers/reducers' 
import thunkMiddleware from 'redux-thunk' 
import api from './middleware/api' 

let createStoreWithMiddleware = applyMiddleware(thunkMiddleware, api)(createStore) 

let store = createStoreWithMiddleware(rootReducer) 

let history = syncHistoryWithStore(browserHistory, store) 

let rootElement = document.getElementById('root') 

ReactDOM.render(
    <Provider store={store}> 
    <Router history={history}> 
     <Route path='/' component={App} /> 
    </Router> 
    </Provider>, 
    rootElement 
) 

私reducers.js次のようになります。

import { combineReducers } from 'redux' 

import Auth from './auth' 
import Quotes from './quotes' 

const rootReducer = combineReducers({ 
    auth: Auth, 
    quotes: Quotes 
}) 

export default rootReducer 
+0

あなたは '/減速/ reducers'ファイルを含めることはできますか? –

答えて

1

あなたが反応し、ルータ - Reduxのを仕事に同期するためrouterReducer()を追加する必要があります。

この縮小機能は、履歴からのロケーション更新を保存します。 combineReducersを使用する場合は、ルーティングキーの下にネストする必要があります。

あなたのコンビネーションレデューサーに以下を含めてください。

import { routerReducer } from 'react-router-redux'; 

export const reducers = combineReducers({ 
    ... // other reducers 
    routing: routerReducer 
}); 

だからあなたの減速ファイルは次のようになります。

import { routerReducer } from 'react-router-redux'; 
import { combineReducers } from 'redux' 

import Auth from './auth' 
import Quotes from './quotes' 

const rootReducer = combineReducers({ 
    auth: Auth, 
    quotes: Quotes, 
    routing: routerReducer 
}) 

export default rootReducer 
+0

はい、それは正解です!私はまだそれがエラーを投げたので、以前の提案は "作成"を持っていたが、今これで動作:) –

関連する問題