jointrashposs/components/g/NuxtLink.vue
2023-09-24 12:35:58 +09:00

36 lines
842 B
Vue

<template>
<NuxtLink
:to="realHref"
:href="undefined"
>
<slot></slot>
</NuxtLink>
</template>
<script setup lang="ts">
import { parseURL, cleanDoubleSlashes, withTrailingSlash } from 'ufo';
import { RouteLocationRaw } from '#vue-router';
const rawProps = defineProps<{
to?: RouteLocationRaw | string;
href?: RouteLocationRaw | string;
}>();
const realHref = computed(() => {
const rhf = rawProps.to ?? rawProps.href;
if (rhf && typeof rhf === 'string') {
const runtimeConfig = useRuntimeConfig();
const rootDomain = parseURL(runtimeConfig.public.baseUrl);
const url = parseURL(rhf);
if (!url.host || rootDomain.host === url.host) {
return withTrailingSlash(rhf, true);
}
return cleanDoubleSlashes(rhf);
}
});
</script>