Possible to preventDefault?

This issue has been tracked since 2021-06-19.

Hello, I'm having a large form and want users to confirm when they navigate away without saving.

Is it possible? I tried something like this without success:

function handleClick(e) {
    const choice = window.confirm('Leave?');
    if (choice) navigate('/');
}

<a use:link href="/" on:click|preventDefault={handleClick}>Home</a>
timohausmann wrote this answer on 2021-06-19

Ah, figured out a solution:

<a use:link href="/" on:click|capture|preventDefault={handleClick}>Home</a>

This is also working:

function handleClick(e) {
    const choice = window.confirm('Leave?');
    if (!choice) e.preventDefault();
}

<a use:link class="navbar-item" href="/" on:click|capture={handleClick}>Home</a>
More Details About Repo
Owner Name EmilTholin
Repo Name svelte-routing
Full Name EmilTholin/svelte-routing
Language JavaScript
Created Date 2017-11-28
Updated Date 2022-12-03
Star Count 1711
Watcher Count 21
Fork Count 151
Issue Count 59

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date