<template>
  <!-- eslint-disable vue/require-component-is -->
  <component v-bind="linkProps(to,this)">
    <slot />
  </component>
</template>

<script>
import { isExternal } from '@/utils/validate'

export default {
  props: {
    to: {
      type: String,
      required: true
    }
  },
  methods: {
    linkProps(url, o) {
      if (o.$parent.$attrs.parameters) {
        url = url + o.$parent.$attrs.parameters
      }
      if (isExternal(url)) {
        return {
          is: 'a',
          href: url,
          target: '_blank',
          rel: 'noopener'
        }
      }
      return {
        is: 'router-link',
        to: url
      }
    }
  }
}
</script>
