PronounsPage/components/LocaleLink.vue

29 lines
655 B
Vue

<script setup lang="ts">
import { getUrlForLocale } from '~/src/domain.ts';
const props = defineProps<{
link: string;
locale?: string;
}>();
const config = useConfig();
const isExternal = computed(() => !props.link.startsWith('/'));
const to = computed(() => {
if (isExternal.value) {
return props.link;
}
if (props.locale !== undefined && props.locale !== config.locale) {
return getUrlForLocale(props.locale) + props.link;
}
return props.link;
});
</script>
<template>
<NuxtLink :to :no-rel="!isExternal" :target="isExternal ? '_blank' : undefined">
<slot></slot>
</NuxtLink>
</template>