如何使用 Svelte 从 link 中删除 `href` 属性?这应该足够了吗?

How to remove `href` attribute from link with Svelte? Should this be enough?

我错了吗?还是应该从 a 标签中删除 href 属性?

<a href={false}></a>

它没有(“svelte”:“3.44.2”)。

使用null 它将停用超链接并且不会去任何地方。 或者您可以将 on:click|preventDefault 添加到锚点。

<a href={null} on:click|preventDefault>link</a>

docs

Boolean attributes are included on the element if their value is truthy and excluded if it's falsy.
All other attributes are included unless their value is nullish (null or undefined).

href= 不是布尔属性,所以 false 不起作用,请改用 null/undefined

<a href={null}>linkText</a>
<a href={undefined} >linkText</a>