[英]react-router-redux: Routes change but components are not displayed
我正在嘗試使用帶有Immutable.js reducers的react-router-redux來設置路由。
我已經使用syncHistoryWithStore
設置了商店,當我單擊Link
,我看到派出了正確的@@router/LOCATION_CHANGE
操作,該商店已使用位置信息正確更新到基礎的routing
鍵減速器,並且URL更改為正確的位置。
問題在於這些組件不會更新。 如果將頁面加載到特定位置,則可以看到正確的組件,但是單擊“ Link
后,不會顯示其他組件。
我已經包括了我認為是相關的文件(刪除了一些不相關的信息):
initialize.js:
import { createStore, applyMiddleware } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly'
import { browserHistory } from 'react-router'
import { routerMiddleware, syncHistoryWithStore } from 'react-router-redux'
import reducers from 'reducers'
const browserHistoryRouterMiddleware = routerMiddleware(browserHistory)
const middlewares = [browserHistoryRouterMiddleware]
/* Create store */
const store = createStore(
reducers,
undefined,
composeWithDevTools(
applyMiddleware(...middlewares),
),
)
/* Configure history */
const createSelectLocationState = () => {
let prevRoutingState, prevRoutingStateJS
return (state) => {
const routingState = state.get('routing')
if (typeof prevRoutingState === 'undefined' || prevRoutingState !== routingState) {
prevRoutingState = routingState
prevRoutingStateJS = routingState.toJS()
}
return prevRoutingState
}
}
const history = syncHistoryWithStore(browserHistory, store, {
selectLocationState: createSelectLocationState(),
})
export { store, history }
index.js:
import React from 'react'
import { render } from 'react-dom'
import { store, history } from 'initialize'
import Root from 'components/Root'
render(
<Root store={store} history={history} />,
document.getElementById('root')
)
Root.js:
import React, { PropTypes } from 'react'
import { Provider } from 'react-redux'
import { Router } from 'react-router'
import routes from 'routes'
const Root = ({ store, history }) => (
<Provider store={store}>
<Router history={history}>
{routes}
</Router>
</Provider>
)
Root.propTypes = {
store: PropTypes.object.isRequired,
}
export default Root
routes
只是Route
和IndexRoute
組件的嵌套列表,從<Route path='/' component={App} />
。 當我console.log
App的children子對象時,我可以看到它在首次渲染時已經通過了子對象,並且它正確地渲染了它們,但是在其他任何時候,我都看不到任何有關子對象變化的控制台反饋。
記錄的操作(狀態是不可變的映射,但出於記錄目的我運行toJS()
):
我缺少什么,當我在路線中移動時應該更改顯示的組件?
問題是我要從createSelectLocationHistory
返回prevRoutingState
而不是prevRoutingStateJS
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.