我可以在这个文件中看到(https://github.com/ReactTraining/react-router/blob/v0.13.3/modules/createRouter.js https://github.com/ReactTraining/react-router/blob/v0.13.3/modules/createRouter.js)有一个刷新函数,但我不知道如何调用它。我对react-router相当陌生,我只使用它使用hashHistory在某些页面之间移动几次。
现在我正在尝试使用它,以便当安装失败时,用户可以选择“重试”,我计划通过刷新安装发生的页面(用户当前所在的页面)来执行该选项。任何帮助,将不胜感激。
这是一个在 Electron 上运行的节点应用程序,而不是 Web 应用程序。
首先,添加react-router作为依赖
yarn add react-router
or npm install react-router
然后(对于react-router v5)
import { useHistory } from 'react-router'
const history = useHistory()
// then add this to the function that is called for re-rendering
history.go(0)
这会导致您的页面自动重新呈现
对于反应路由器 v6 使用useNavigate
钩子代替:
import { useNavigate } from 'react-router'
const navigate = useNavigate()
// refresh
navigate(0)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)