<template>
    <a v-if="isExternal(to)" :href="to" rel="noreferrer" target="_blank">
        <slot></slot>
    </a>
    <router-link v-else :replace="replace" :to="to">
        <slot></slot>
    </router-link>
</template>
<script lang="ts">
    import { defineComponent } from 'vue';
    import { isExternal } from '@/utils/validate';

    export default defineComponent({
        name: 'ALink',
        props: {
            to: {
                type: String,
                required: true
            },
            replace: {
                type: Boolean,
                default: false
            }
        },
        setup() {
            return {
                isExternal
            };
        }
    });
</script>
