0

I have a simple react router with "/" rendering home component. I am in "/" which renders the home component. How do I get it to refresh when I click home link even though it is already in "/" ?

In context, think of YouTube, if I click the YouTube logo on the top left, it refreshes the page. Currently in my react project if I click the home link while at home, it does nothing.

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>
)
  • refer this link -> https://stackoverflow.com/questions/47602091/how-to-use-react-router-4-0-to-refresh-current-route-not-reload-the-whole-page?rq=1 – sathish kumar Apr 26 '19 at 05:52

1 Answers1

0

You can use an intermediate function to achieve this,

<Route path='/' component={()=><Home/>} />
ShreyasG
  • 25
  • 1
  • 7