【问题标题】:React Router - Home component does not reload when click home link in homeReact Router - 单击主页中的主页链接时主页组件不会重新加载
【发布时间】:2019-04-26 05:27:49
【问题描述】:

我有一个带有“/”渲染主页组件的简单反应路由器。我在“/”中,它呈现 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>
)

【问题讨论】:

标签: reactjs react-router components refresh history


【解决方案1】:

你可以使用中间函数来实现,

<Route path='/' component={()=><Home/>} />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 2021-06-14
    • 2016-05-17
    • 2012-11-30
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多