fix: c-link to vs href

Fix #569
This commit is contained in:
ShareVB committed 2026-09-06 09:59:14 +02:00
1 parent a049d1c519
commit 62ab0bf92f
1 file changed
+9 -12
+9 -12
View File
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { type RouteLocationRaw, RouterLink } from 'vue-router';
import { type RouteLocationRaw } from 'vue-router';
import { useTheme } from './c-link.theme';
const props = defineProps<{
@@ -11,21 +11,18 @@ const props = defineProps<{
const { href, to, target } = toRefs(props);
const theme = useTheme();
const tag = computed(() => {
if (href?.value) {
return 'a';
}
if (to?.value) {
return RouterLink;
}
return 'span';
});
</script>
<template>
<component :is="tag" :href="href ?? to" class="c-link" :to="to" :target="target">
<a v-if="href" :href="href" class="c-link" :target="target">
<slot />
</component>
</a>
<router-link v-else-if="to" :to="to" class="c-link" :target="target">
<slot />
</router-link>
<span v-else class="c-link">
<slot />
</span>
</template>
<style lang="less" scoped>