2023-09-23 11:17:13 +02:00
|
|
|
<template>
|
2023-09-23 12:07:45 +02:00
|
|
|
<NuxtLink
|
|
|
|
:to="realHref"
|
2023-09-23 20:02:14 +02:00
|
|
|
:href="undefined"
|
2023-09-23 12:07:45 +02:00
|
|
|
>
|
2023-09-23 11:17:13 +02:00
|
|
|
<slot></slot>
|
2023-09-23 12:07:45 +02:00
|
|
|
</NuxtLink>
|
2023-09-23 11:17:13 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2023-09-23 12:07:45 +02:00
|
|
|
import { parseURL, cleanDoubleSlashes, withTrailingSlash } from 'ufo';
|
2023-09-23 20:02:14 +02:00
|
|
|
import { RouteLocationRaw } from '#vue-router';
|
2023-09-23 11:17:13 +02:00
|
|
|
|
2023-09-23 20:02:14 +02:00
|
|
|
const rawProps = defineProps<{
|
|
|
|
to?: RouteLocationRaw | string;
|
|
|
|
href?: RouteLocationRaw | string;
|
|
|
|
}>();
|
2023-09-23 12:07:45 +02:00
|
|
|
const realHref = ref(rawProps.to ?? rawProps.href);
|
2023-09-23 11:17:13 +02:00
|
|
|
|
2023-09-23 12:07:45 +02:00
|
|
|
if (realHref.value && typeof realHref.value === 'string') {
|
|
|
|
const runtimeConfig = useRuntimeConfig();
|
|
|
|
const rootDomain = parseURL(runtimeConfig.public.baseUrl);
|
|
|
|
const url = parseURL(realHref.value);
|
|
|
|
|
|
|
|
if (!url.host || rootDomain.host === url.host) {
|
|
|
|
realHref.value = withTrailingSlash(realHref.value, true);
|
|
|
|
}
|
2023-09-23 11:17:13 +02:00
|
|
|
|
2023-09-23 12:07:45 +02:00
|
|
|
realHref.value = cleanDoubleSlashes(realHref.value);
|
2023-09-23 11:17:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|