Commit c926ad17 authored by Anton's avatar Anton

Add ConditionalLink component to handle local and external links differently in cells

parent 8805558e
<template lang="pug">
span
router-link(v-if="isLocal && routerTo", :to="routerTo")
slot
a(v-else, :href="url", target="_blank")
slot
</template>
<script>
import qs from 'qs'
export default {
props: {
url: String
},
computed: {
isLocal () {
return this.url && (this.url.indexOf(process.env.UI_HOST) === 0 || this.url[0] === '/')
},
routerTo () {
let url
try {
url = new URL(this.url)
}
catch (e) {
if (this.url) {
const parts = this.url.split('?')
url = {
pathname: parts[0],
search: parts.length > 1 ? `?${parts[1]}` : ''
}
}
}
if (url) {
const query = url.search.length ? qs.parse(url.search.substr(1)) : undefined
return {
path: url.pathname,
query: query
}
}
else return {}
}
}
}
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment