jointrashposs/components/g/NuxtLink.vue
かっこかり 1f2b1aa58b
(Add) Tools: MFM Preview (#2)
* wip

* (add) mfm preview

* (fix) iroiro

* (Fix) build error

* (fix) something
2023-09-26 21:57:26 +09:00

44 lines
1.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<NuxtLink
:to="realHref"
:href="undefined"
>
<slot></slot>
</NuxtLink>
</template>
<script setup lang="ts">
import { cleanDoubleSlashes, withTrailingSlash } from 'ufo';
import { isLocalPath } from '@/assets/js/misc';
import { RouteLocationRaw } from '#vue-router';
/**
* TrailingSlashをつけているpnpm generate時の出力ディレクトリ構造の関係ので、
* 二重にスラッシュが入って無限ループに陥らないようにするための
* NuxtLinkのラッパーコンポーネント
*/
const rawProps = defineProps<{
to?: RouteLocationRaw | string;
href?: RouteLocationRaw | string;
}>();
const realHref = computed(() => {
const rhf = rawProps.to ?? rawProps.href;
if (rhf && typeof rhf === 'string') {
if (isLocalPath(rhf)) {
return withTrailingSlash(cleanDoubleSlashes(rhf), true);
}
return rhf;
}
// TODO: ルート定義をオブジェクトで渡された時のバリデーション
return rhf;
});
</script>