<!--
 * @Author: 曹捷
 * @Date: 2021-01-10 16:22:35
 * @LastEditors: 曹捷
 * @LastEditTime: 2021-01-25 10:43:36
 * @Description: fileContent
-->

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

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

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