gpt4 book ai didi

reactjs - react : HashRouter Not Reloading Page on Electron

转载 作者:行者123 更新时间:2023-12-03 12:22:03 30 4
gpt4 key购买 nike

我在Electron项目中使用了HashRouter,但是由于某些原因,HashRouter不会刷新导航页面,这是我需要执行的操作。
关于我单击路线时如何刷新页面的任何想法?

import { HashRouter } from "react-router-dom";
  <HashRouter>
<div>
<main>
<Route exact path="/" component={Home} />
<Route path="/StatusHub" component={StatusHub} />
<Route path="/PagerDuty" component={PagerDuty} />
<Route path="/QuickLinks" component={QuickLinks} />
</main>
</div>
</HashRouter>
navBar.js
import { Link } from "react-router-dom";
return(
<div>
<Link to="/">
<FontAwesomeIcon icon={faHome} />
<span className="label-center">Home</span>
</Link>

<Link to="/StatusHub">
<FontAwesomeIcon icon={faFire} />
<span className="label-center">StatusHub</span>
</Link>
</div>
)

最佳答案

根据@Ajeet Shah的帮助,我只需要在路线周围包裹Switch:

  <Router>
<div>
<main>
<Switch>
<Route exact path="/" component={Home} />
<Route path="/StatusHub" component={StatusHub} />
<Route path="/PagerDuty" component={PagerDuty} />
<Route path="/QuickLinks" component={QuickLinks} />
</Switch>
</main>
</div>
</Router>

关于reactjs - react : HashRouter Not Reloading Page on Electron,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66505361/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com