When I want to perform a programmatic navigation or a return navigation on button click, React useNavigate() causes all state, redux and context to revert to initial. eg
<IconButton
onClick={()=>{
navigate(-1)
}}>Go back
</IconButton>
on clicking to return to previous page, all states on the page are reverted to initial state. Please is there any solution?
And yes I have tried the following
<IconButton
onClick={()=>{
navigate(-1, { replace: true })
}}>Go Back
</IconButton>
and...
<IconButton
onClick={()=>{
navigate(-1, { replace: false })
}}>Go back
</IconButton>
And none works. How do I keep the previous state when I perform a programmatic navigation?