如何使用 react-router 重新加载页面? [英] How do I reload a page with react-router?
问题描述
我可以在这个文件中看到(https://github.com/ReactTraining/react-router/blob/v0.13.3/modules/createRouter.js)有一个刷新功能,但我不知道如何调用它.我对反应路由器相当陌生,我只使用它使用 hashHistory 在某些页面之间移动几次.
I can see in this file (https://github.com/ReactTraining/react-router/blob/v0.13.3/modules/createRouter.js) that there is a refresh function but I have no idea how to call it. I'm fairly new to react-router, I've only used it to move between some pages a couple times using hashHistory.
现在我正在尝试使用它,以便当安装失败时,用户可以选择重试",我计划通过刷新发生安装的页面(用户当前所在的页面)来执行该选项).任何帮助将不胜感激.
Right now I am trying to use it so that when an install fails, the user is given the option to 'retry' which I plan to execute by refreshing the page where the install happens (the page the user would be currently on). Any help would be appreciated.
这是一个在电子上运行的节点应用程序,而不是一个网络应用程序.
This is a node app that runs on electron, not a web app.
推荐答案
首先添加react-router作为依赖
firstly, add react-router as a dependency
`yarn add react-router` or `npm install react-router`
import { useHistory } from 'react-router'
const history = useHistory()
/////then add this to the function that is called for re-rendering
history.go(0)
这会导致您的页面自动重新呈现
This causes your page to re-render automatically
这篇关于如何使用 react-router 重新加载页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!