I am using "react-scripts": "4.0.2" and all my components are React Hooks. My logic involves nested routing but the end result is not rendered.
Body.js:
<Switch>
<Route path="/form" exact component={Forms}></Route>
<Route path="/" exact component={ShopCards}></Route>
</Switch>
Forms.js:
const expandFormHandler = (pid) => {
console.log("PID:" + pid); //It is printing correcly
props.history.push({ pathname: "/form/" + pid }); //URL is also changing accordingly
}
return (
<div>
{prodCards.map((card, index) => (
<ProductCard
key={index}
expand={expandFormHandler.bind(this, card.pid)}
/>
))}
<Route path={props.match.url + "/:id"} exact component={Modal} />
//<Route path="/form/:id" exact component={Modal} /> //Tried this too
</div>
);
Modal.js:
<h1>{props.match.params.id}Hello</h1>
The modal is not rendering even it's useEffect() is not executed.
Now if I place Modals Route in Body.js like following the Modal is rendered but not in the same page below ProductCard
<Switch>
<Route path="/form" exact component={Forms}></Route>
<Route path="/form/:id" exact component={Modal} />
<Route path="/" exact component={ShopCards}></Route>
</Switch>