我可以在这个文件 ( https://github.com/ReactTraining/react-router/blob/v0.13.3/modules/createRouter.js ) 中看到有一个刷新函数,但我不知道如何调用它。我对 react-router 还很陌生,我只用它在一些页面之间移动过几次,使用 hashHistory。
现在我正在尝试使用它,这样当安装失败时,用户可以选择“重试”,我计划通过刷新安装发生的页面(用户当前所在的页面)来执行).任何帮助将不胜感激。
这是一个在 Electron 上运行的节点应用程序,而不是网络应用程序。
最佳答案
首先,添加react-router作为依赖
`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)
这会导致您的页面自动重新呈现
对于 react-router V6,请改用 useNavigate 钩子(Hook)
从'react-router'导入{useNavigate}
const navigate = useNavigate()
导航(0)
关于javascript - 如何使用 react-router 重新加载页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46820682/