Found the answer, courtesy of GitHub Copilot:
To execute custom logic before navigation, you can wrap the next/link component with a custom component and handle the logic within that component.