I use react-router-dom
v6
label1 label2
When you click one link or another, the Route component renders as expected. However, if "/pathOne" is active and I click on it again, nothing happens.
Is there a way to force a route element to be re-rendered by clicking on an active link?
I could refresh the entire page if the reloadDocument attribute was set, but that's not a viable option.
If all you really want is for the route component to rerender each time the link to its route is clicked then just have those components call the
useLocation
hook. Each time the link is clicked a newlocation
object reference is created. The newlocation
object reference is enough to trigger the component using it to be rerendered.Example: