2015-12-02 84 views
1

我越來越終極版,簡單的路由器+反應路由器錯誤 「路由狀態不存在」

Uncaught Error: Cannot sync router: route state does not exist. Did you install the routing reducer?

代碼:

減速器/ index.js

const rootReducer = { 
    counter, 
    exampleData, 
    navigation, 
}; 

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

//const reducer = combineReducers(rootReducer); 

export default reducer 

and

app.jsx

var __DEBUG__ = __DEBUG__ || false; 
var __DEBUG_NW__ = __DEBUG_NW__ || false; 

const target = document.getElementById('app'); 
const history = createBrowserHistory(); 
const store = configureStore(window.__INITIAL_STATE__, __DEBUG__); 

syncReduxAndRouter(history, store); 

const node = (
    <Root 
    history={history} 
    store={store} 
    debug={__DEBUG__} 
    debugExternal={__DEBUG_NW__} 
    /> 
); 

ReactDOM.render(node, target); 

該錯誤是由syncReduxAndRouter調用觸發的,但我沒有看到我做錯了什麼。 我需要做什麼才能正確使用redux-simple-router? (此外,有助於澄清問題將不勝感激)

+0

(編輯感謝:@knowbody) –

回答

2

檢查您的進口聲明routeReducer。我也有同樣的問題,直到我發現,我已經忘記了花括號:

import { routeReducer } from 'redux-simple-router'; 

編輯: 如何import作品上ES6一個很好的解釋:https://hacks.mozilla.org/2015/08/es6-in-depth-modules/

+0

這確實是問題。謝謝! –

1

齊諾的回答是一個很好的,最可能routeReducer不是你想象的那樣。嘗試將其記錄到控制檯並確保它是由redux-simple-router導出的reducer。

3

如果你想終極版通過使用終極版 - immutablejs immutablejs結合,您syncReduxAndRouter必須是:

syncReduxAndRouter(history, store, (state) => state.get('routing'));