If this is something you find yourself doing often, you could make a ConditionalLink
component out of it using slots.
<!-- ConditionalLink.svelte -->
<script>
export let isWrapped = false;
export let href;
</script>
{#if isWrapped}
<a {href}>
<slot/>
</a>
{:else}
<slot/>
{/if}
It can be used like so:
<script>
import ConditionalLink from './ConditionalLink.svelte';
let wrapLink = false;
</script>
<ConditionalLink isWrapped={wrapLink} href="#">
I'm a link
</ConditionalLink>
<label><input type="checkbox" bind:checked={wrapLink}> wrap link</label>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…