r/learnreactjs • u/Justincy901 • Aug 29 '22
Question How to reload page when clicked on react router dom Link element.
<Link to={currentUser.uid === "" ? null : `/profile/${currentUser.uid}/`} replace={true}>Profile</Link>
So, when I click on this link it works as it supposed to. However, if I click on this link and I'm already on another profile page it doesn't reload the page and stay on the original page with all previous profile elements loaded but doesn't refresh to get rid of previous elements that exists under another uid. So it populates the profile page with previous profile elements and current profile elements. If that makes sense. So, I just want to know a way to refresh a page totally when clicked on react-router-dom's Link element. Please help if you can.
1
u/marko_knoebl Aug 29 '22
Can you share how you're fetching and storing your data? I think you'd want to update the logic there.
1
u/hinsxd Aug 29 '22
https://xyproblem.info
You probably need to refetch on mount using useEffect, depending on what you use to fetch data
1
u/jcksnps4 Aug 29 '22
If the profile page has a user Id in the route, then when the route changes, everything should rerender