我有一个简单的反应路由器与“/”渲染家庭组件。我在“/”中呈现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/>} />