我有一个简单的反应路由器,带有"/"渲染主组件。我在渲染主组件的"/"中。当我单击主页链接时,即使它已经在"/"中,我如何让它刷新?
在上下文中,想想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/>} />