reactjs - React Router - 单击主页中的主页链接时主页组件不会重新加载
问题描述
我有一个带有“/”渲染主页组件的简单反应路由器。我在“/”中,它呈现 home 组件。当我点击主页链接时,即使它已经在“/”中,如何让它刷新?
在上下文中,想想 YouTube,如果我单击左上角的 YouTube 徽标,它会刷新页面。目前在我的反应项目中,如果我在家里点击主页链接,它什么也不做。
const MainRoutes = () => (
<Router>
<div>
<NavBar />
<Route exact path="/" component={Home}/>
<Route exact path="/login" component={Login}/>
<Route exact path="/post" component={Post}/>
<Route exact path="/about" component={AboutRoutes}/>
<Route exact path="/listing/:handle" component={Listing}/>
<Route exact path="/mylistings" component={MyListings}/>
</div>
</Router>
)
解决方案
您可以使用中间函数来实现这一点,
<Route path='/' component={()=><Home/>} />
推荐阅读
- jupyter-notebook - 在 RISE 演示文稿中按键时一一显示项目符号
- conv-neural-network - 从 ImageNet 直接推断我的数据集(没有训练或微调)?
- sql - SQL中平均计数的高效查询
- python - 以秒格式绘制时间序列
- sql-server - 如何将 SSIS 查找转换中的代码页修复为 65001?
- matlab - 使用 psychtoolbox 构建实验
- curl - 如何避免在 Jenkins 控制台输出上打印 curl 命令?
- python - 风筝已安装但无法打开
- plugins - 看来我必须在 Xcode 上安装 XcodeHacking 才能使用 clang 插件。有什么影响?它会影响我的代码的安全性吗?
- python - matplotlib.use('Agg')power BI集成python中的属性错误