router
router copied to clipboard
Link onClick preventDefault doesn't work
Describe the bug
The usage of event.preventDefault() inside an onClick handler on the Link component will not prevent the navigation. This works with HTML anchors and react-location Link component.
Your Example Website or App
https://stackblitz.com/edit/tanstack-router-kqww9m?file=src/main.tsx
Steps to Reproduce the Bug or Issue
- Add onClick handler with preventDefault() to Link component
- Click link
Expected behavior
As a user I expected, that the page navigation will be prevented but it got triggered anyway.
Screenshots or Videos
No response
Platform
- OS: Linux
- Browser: Chromium
- Version: 104.0.5112.79
Additional context
No response
On <Link />
elements try to use onClickCapture to prevent the event.
onClickCapture={(e) => {
e.preventDefault();
}}
This should be fixed on the latest version 👍