-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When link is clicked, default browser event isn't prevented #340
Comments
This took me forever to debug, glad I'm not going crazy |
I created this simple workaround for now. Put this in the component where you use the useEffect(() => {
function callback(event) {
const target = event.target;
if (
target &&
target.nodeName.toLowerCase() === 'a' &&
!target.href.startsWith('mailto:')
) {
if (event.stopImmediatePropagation) {
event.stopImmediatePropagation();
}
if (event.stopPropagation) {
event.stopPropagation();
}
event.preventDefault();
}
}
window.addEventListener('click', callback);
return () => {
window.removeEventListener('click', callback);
};
}, []); I didn't complicate it too much because my website isn't that complex anyways. Any suggestions are appreciated. |
I just figured out what's causing this. In preact 10, Lines 177 to 178 in f7dbe6d
|
aaand we have a fix! #342 |
Explanation:
When clicking a link, the page correctly changes to the matching route. However, immediately after that, I get a new page saying
Cannot GET /foo
This issue occurs only when using the
a
tag instead ofLink
.The text was updated successfully, but these errors were encountered: