<script context="module">
    import { page } from '$app/stores';

    function host(url) {
        try {
            let u = new URL(url);
            return u.host;
        }
        catch {
            return null;
        }
    }
</script>

<script>
    export let href; // we don't care about other attributes
</script>


{#if href.startsWith('/') || host(href) === $page.host}
    <a sveltekit:prefetch {href}>
        <slot></slot>
    </a>
{:else}
    <a {href}>
        <slot></slot>
    </a>
{/if}
