fix[Sidebar]: link bug (#1134)

Fixed #1125
This commit is contained in:
花裤衩
2018-09-26 17:10:22 +08:00
committed by GitHub
parent dd5646ffbc
commit 63ff44f8e5
2 changed files with 48 additions and 12 deletions

View File

@@ -0,0 +1,39 @@
<template>
<!-- eslint-disable vue/require-component-is-->
<component v-bind="linkProps(to)">
<slot/>
</component>
</template>
<script>
import { validateURL } from '@/utils/validate'
export default {
props: {
to: {
type: String,
required: true
}
},
methods: {
isExternalLink(routePath) {
return validateURL(routePath)
},
linkProps(url) {
if (this.isExternalLink(url)) {
return {
is: 'a',
href: url,
target: '_blank',
rel: 'noopener'
}
}
return {
is: 'router-link',
to: url
}
}
}
}
</script>