Skip to content
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

Not possible to prevent events when navigating #185

Closed
johnyvelho opened this issue Jan 11, 2021 · 3 comments
Closed

Not possible to prevent events when navigating #185

johnyvelho opened this issue Jan 11, 2021 · 3 comments
Labels
question Further information is requested

Comments

@johnyvelho
Copy link

johnyvelho commented Jan 11, 2021

<a href="/my-url" use:link>
    <div>My other elements</div>
    <div>My other elements</div>
    <button on:click|preventDefault={() => console.log('button')}>Button</button>
</a>

When clicking on the button, the page will be redirected to the /my-url, even preventing this (event.preventDefault()).

@ItalyPaleAle
Copy link
Owner

Not sure why this happens. Try using <a href="#/my-url"> rather than the use:link, and try adding return false to the callback. See if they make a difference.

@ItalyPaleAle ItalyPaleAle added the question Further information is requested label Jan 12, 2021
@johnyvelho
Copy link
Author

hey @ItalyPaleAle,

Yeah, I did it to work around the problem for now. I will try to investigate it later and if possible send a PR to fix it.

Thanks for the awesome package!

@ItalyPaleAle
Copy link
Owner

Interesting. use:link binds a callback to the link. Which means that when you click on the button, the callbacks on both the a and button are called. Maybe you can try with the stopPropagation modifier too: on:click|preventDefault|stopPropagation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants