2
const PATH = BASE + '/' + id;
<Route path="PATH" render={PageContainer} /> (DOESN'T WORK for the case below)
<Route path="PATH" component={PageContainer} /> (DOESN'T WORK for the case below)
<Route path="PATH" component={ () => <PageContainer /> } /> (WORKS)

Steps:
1) go to the page BASE/1
2) go back to BASE
3) go to BASE/2

PageContainer connects to the store and passes props to Page.

Why the second approach works, but the first one not?

Update:     <Route path="PATH" render={PageContainer} /> (DOESN'T WORK for the case below)
Will Graham
  • 340
  • 1
  • 3
  • 16
  • Possible duplicate of [react router difference between component and render](https://stackoverflow.com/questions/48150567/react-router-difference-between-component-and-render) – frogatto Feb 02 '19 at 15:21

2 Answers2

2

Try accessing it like this:

<Route path="PATH" component={PageContainer} /> 

There is a difference between component and render props. You can find the answer here: react router difference between component and render

Mikail Bayram
  • 349
  • 4
  • 10
2

render — A function that returns a React element. It will be called when the path matches. This is similar to component, but is useful for inline rendering and passing extra props to the element.

PageContainer is a component so should called but not like PageContainer

Change

  <Route path="PATH" render={PageContainer} /> 

To

  <Route path="PATH" render={<PageContainer />} /> 

In your case I recommend you to use component prop instead of render

  <Route path="PATH" component={<PageContainer />} /> 
Hemadri Dasari
  • 32,666
  • 37
  • 119
  • 162