I am doing React programming with JavaScript.
I use the history.push function from react-router-dom (v5.2.0) to open a new page. Here is part of the code:
{activeRequests?.map((item, index) => {
return (
<tr
className={styles.tr}
key={index}
onClick={() => {
history.push(`AssetManagement/Default/Edit/${item.assetId}`);
window.location.reload();
}}
>
It opens the new page (which happens to be in Knockout) as expected in the same browser tab.
Something odd happens, however, when I use the Back button to return to the page on which I originally clicked the above link. I see the original page. But then, if I scroll down, I see the page on which I clicked the Back button appended to the bottom.
Call them, let’s say, Page One (where I clicked the link) and Page Two (where I clicked the Back button). Is there anything I can do on Page One to prevent this behavior? (Meaning, of course, I don’t want to see Page Two at the bottom of Page One.) Or do I need to add some sort of unmounting function to Page Two? I would prefer to modify Page One, since I am more familiar with React than Knockout.