简体   繁体   English

从react-redux connect()内部连接到反应路由器push()时,位置没有变化

[英]No location change upon connected-react-router push() from within the react-redux connect()

Dispatching the push action which was defined in mergeProps parameter of the react-redux connect() dispatches redux action but does not trigger url page change. 分派react-redux connect()的mergeProps参数中定义的push操作会分派redux操作,但不会触发url页面更改。 I also wrapped the withRouter around the redux container but no seems to help. 我也将withRouter包装在redux容器周围,但似乎无济于事。

//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 ));

What can I do to also trigger actual page update along with the LOCATION_CNANGE redux action using the create-react-router package? 如何使用create-react-router包触发实际的页面更新以及LOCATION_CNANGE redux操作? At this point, only the connected-react-router middleware and the redux store are being updated but no actual page change. 此时,仅更新了连接的反应路由器中间件和redux存储,但没有实际的页面更改。

Fixed it by modifying a redirect 'from' prop. 通过修改重定向“来自”道具修复了该问题。

Root cause: a redirect was placed at the end of the switch child routes list as a catchall rerouting to the main page. 根本原因:重定向位于交换子路由列表的末尾,作为重新路由到主页的综合包。 However, all requests (including valid ones except '/') went to the catchall redirect and were rerouted to main page. 但是,所有请求(包括“ /”以外的有效请求)都转到了catchall重定向并重新路由到了主页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 安装了react-redux和redux模块的连接反应路由器无法解析模块'react-redux' - Can't resolve module 'react-redux' in connected-react-router with react-redux and redux modules installed redux 工具包 +connected-react-router - redux toolkit +connected-react-router Redux Sagas 未使用 redux persist 和 connected-react-router 进入 - Redux Sagas not entered with redux persist and connected-react-router 使用已连接反应路由器在React + Redux中使用pushState - pushState in React + Redux using connected-react-router Redux-Persist和Connected-React-Router:TypeError:无法读取undefined的属性'location' - Redux-Persist and Connected-React-Router: TypeError: Cannot read property 'location' of undefined 如何使用 connected-react-router 重置 Redux 存储的状态? - How to reset the state of a Redux store using connected-react-router? Redux-loop和Connected-React-Router是否兼容? - Are `redux-loop` and `connected-react-router` compatible? 正确配置 connected-react-router 和 Redux Toolkit Query 的 reducers - Configure reducers of connected-react-router and Redux Toolkit Query properly 如何在单元测试中使用 connected-react-router 的推送 - How to use connected-react-router's push within unit tests 连接反应路由器推送被称为什么也没发生 - connected-react-router push is called nothing happens
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM