如何使用 react-route 链接刷新页面 [英] How to refresh a Page using react-route Link
本文介绍了如何使用 react-route 链接刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 react-route 链接刷新页面.但是我实现它的方式是后退一步到 URL.(例如,如果 URL 是 ../client/home/register,当我按下重新加载时,它会转到 ../client/home)
下面是我的代码
const AppErrorPage = () =>(<div><div style={styles.container }><h2>错误</h2><p>出了点问题,请重新加载页面 </p><div><链接到=""refresh="true"><span>重新加载</span></链接>
);
解决方案
刷新页面不需要react-router,简单的js:
window.location.reload();
要在 React 组件中重新渲染视图,您只需使用 props/state 触发更新即可.
I am trying to refresh a page using react-route Link. But the way I have implemented it goes to the URL one step back.(as an example if the URL was ../client/home/register and when I press the reload is goes to ../client/home)
below is my code
const AppErrorPage = () => (
<div>
<div style={ styles.container }>
<h2>Error</h2>
<p> Something went wrong, please reload the page </p>
<div>
<Link to="" refresh="true">
<span>Reload</span>
</Link>
</div>
</div>
</div>
);
解决方案
To refresh page you don't need react-router, simple js:
window.location.reload();
To re-render view in React component, you can just fire update with props/state.
这篇关于如何使用 react-route 链接刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!