Issue:
I've been trying to find a way to refresh a page with React Router Dom. I am wondering if my code below is correct and usable.
Expected Results:
I am trying to get the same results as when you click on an Anchor <a href='/'> tag with React.
Current Code:
Below you can find the current code I use. You will find 3 things.
- A Reusable Link component
- A refresh page function that refreshes at the current location.pathname
- A Link component from React Router Dom
function ReusableLink({ label, address }) {
function refreshPage() {
window.location.pathname.reload(false);
}
return (
<li className={path === address ? 'active' : ''}>
<Link className='link' to={address} onClick={refreshPage}>
{label}
</Link>
</li>
)
}