异步操作失败后推送到历史记录

时间:2019-01-21 22:21:45

标签: reactjs typescript react-router-v4

使用fetch进行异步调用后,我一直在导航应用程序。此功能由onClick

触发
const output = await fetch(`${process.env.REACT_APP_API_URL}/Endpoint`, {
                method: 'POST',
                headers: {
                    'Authorization': `Bearer ${this.props.login.login.bearerToken}`
                },
                body: JSON.stringify(this.state.thing1)
            });
console.log(output);
toast.success("Lawyer added");
await this.props.history.push("/home");

使用此代码,URL被更新为/home,但屏幕未更新为包含该路线上的home组件。如果我删除调用以获取所有内容,则一切都会如我所愿。该行为看起来与https://github.com/ReactTraining/react-router/issues/4924非常相似,但是我无法使用withRouter来解决问题,也无法使用任何纯组件或实现shouldComponentUpdate的组件。在以异步方式使用抓取后,如何更新页面位置?

这是使用connected-react-router,打字稿和redux。在示例中,我使用了从道具直接传入的历史对象,但是如果我使用商店中的对象,同样无法使用。

更新:我看到@@router/LOCATION_CHANGE击中了我的减速器。

0 个答案:

没有答案
相关问题