Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  166] [ 5]  / answers: 1 / hits: 24228  / 6 Years ago, mon, march 5, 2018, 12:00:00

I used same component for different routes. When route changes, I want the component to be rendered.



<Switch>
<Route exact path=/ component={HomePage} />
<Route path=/hotels component={HotelsPage} />
<Route path=/apartments component={HotelsPage} />
</Switch>


When I change the route path from /hotels to /apartments, the component HotelsPage doesn't refresh.



What is the cool approach for this?


More From » reactjs

 Answers
152

One of the ways you can get this sorted is by passing the props explicitly like :



<Route path=/hotels component={props => <HotelsPage {...props} />} />


[#55011] Thursday, March 1, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kamronr

Total Points: 749
Total Questions: 110
Total Answers: 122

Location: Dominica
Member since Sat, Nov 5, 2022
2 Years ago
kamronr questions
Mon, Dec 21, 20, 00:00, 4 Years ago
Fri, Oct 16, 20, 00:00, 4 Years ago
Sat, Oct 3, 20, 00:00, 4 Years ago
Sun, Jul 28, 19, 00:00, 5 Years ago
;