React Link 不会刷新页面 [英] React Link doesn't refresh the page

查看:347
本文介绍了React Link 不会刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

<Link to="/dashboard" style={{ color: '#A4A4A4' }}>Dashboard</Link>

作为我的应用程序的一部分,但如果我当前正在查看 /dashboard 路由,页面不会刷新.

As part of my app, but if i'm currently viewing the /dashboard route, the page doesn't refresh.

为什么?我怎样才能让它刷新?

Why? And how can i make it refresh?

推荐答案

您可以尝试强制刷新,方法之一是:

You can try forcing a refresh, either with:

<Link to="/dashboard" onClick={this.forceUpdate} style={{ color: '#A4A4A4'}}>Dashboard</Link>

<Link to="/dashboard" onClick={() => window.location.reload()} style={{ color: '#A4A4A4' }}>Dashboard</Link>

您还可以向 onClick 方法添加逻辑以检查您当前所在的页面,并且仅在您在仪表板上时才刷新.

You can also add logic to the onClick method to check which page you are currently on, and to only refresh if you are on the dashboard.

这篇关于React Link 不会刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆