在 react-redux connect() 中的 connected-react-router push() 上没有



调度在 react-redux connect(( 的 mergeProps 参数中定义的推送操作会调度 redux 操作,但不触发 url 页面更改。我还在 redux 容器周围包裹了 withRouter,但似乎没有帮助。

//connect.js
import { Component } from './Component';
import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import { push } from 'connected-react-router';
import { onFetch, onUpdate } from '../action-creators';
export default withRouter(connect(state => state, 
{ 
onFetch, 
onUpdate,
push
},
( state, actions ) => ({
...state,
onFetch: actions.onFetch,
onUpdate: index => {
actions.onUpdate( index );
actions.push( `/${ index }` );
}
})
)( Component ));

我该怎么做才能使用创建-反应-路由器包触发实际的页面更新以及LOCATION_CNANGE redux 操作?此时,仅更新连接的路由器中间件和 redux 存储,但没有实际的页面更改。

通过修改重定向"from"道具来修复它。

根本原因:重定向被放置在交换机子路由列表的末尾,作为到主页的包罗万象的重新路由。但是,所有请求(包括除"/"之外的有效请求(都转到了 catchall 重定向并重新路由到主页。

最新更新