I'm a little bit uncertain as to what might be wrong here.
I have a React router switch that is nested within another React Router switch as below
Switch in homepage.js file is as below
<Switch>
<Route path={HomePageRoutes.CONTENTS}> //which is just /contents
<ContentPage initialData={fetchedData}/>
<Route>
<Route path={HomePageRoutes.ADS}>
<AdsPage/>
</Route>
</Switch>
Now, ContentPage which was referenced above is in a file called contentpage.js and that page also contains a switch as below:
export default function ContentPage(){
......
<Switch>
<Route path={`/first`}>
<FirstContentPage/>
</Route>
<Route>
<DefaultContentPage/>
</Route>
</Switch>
......
}
I was expecting that if the current location in the browser is at say /content and I click on a link that redirects to /first, the /first will be appended to the current location to become /content/first and the FirstContentPage component should render but unfortunately it is not rendering?
What am I doing wrong?
Thanks in anticipation for your input.
You will need to access the current
pathfrom thematchprop. SinceContentPageis not receiving route props you may need to wrapContentPagein the withRouter Higher Order Component.match