I'm currently struggling using React and its library react-router-dom.
To simplify:
I've this in my App component:
const App = () => {
return (
<Router>
<Layout>
<Switch>
// <Other Routes />
<Route path='/product/:id' component={ProductScreen} />
// <Other Routes />
</Switch>
</Layout>
</Router>
)
}
The <ProductScreen /> (single product view) is wrapped like this:

The <ProductNav /> component embeds two links from react-router-dom. It also includes the required logic to reach previous or next product. Like so for instance:
<Link
className='prev'
to={`/product/${currentIndex - 1 < 0 ? ids[lastIndex] : ids[currentIndex - 1]}`}
>
Previous
</Link>
It's working but I'm not satisfied with that approach because the <ProductScreen /> unmounts each time I click 'previous' or 'next' and this leads to some unaesthetic things on the page. I would like to prevent it from unmounting in order to have this instead:
I tried many things, read the doc but I'm quite stuck right now. If anyone has any idea of how to achieve that I would be glad to read it.
