-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppLink.vue
More file actions
39 lines (32 loc) · 988 Bytes
/
AppLink.vue
File metadata and controls
39 lines (32 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<template>
<a :href="href" v-bind="attrs" @click="go">
<slot v-bind="{ isActive, isExactActive, isLoading }" />
</a>
</template>
<script setup>
import { RouterLink, useLink } from 'vue-router'
import { computed, defineProps, ref, useAttrs } from 'vue'
import { useRouter } from '../core/router'
const props = defineProps({
...RouterLink.props,
modal: { type: Boolean, default: false },
})
const attrs = useAttrs()
const { href, isActive, isExactActive, navigate } = useLink(props)
const route = computed(() => {
const route = useRouter().resolve(props.to)
if (props.modal) route.params = { ...route.params, _isDialog: true }
return route
})
const router = useRouter()
const loadingRoute = ref('')
const startLoading = () => (loadingRoute.value = route.value.fullpath)
router.afterEach(() => {
loadingRoute.value = ''
})
const isLoading = computed(() => route.value.fullpath === loadingRoute.value)
const go = (e) => {
startLoading()
navigate(e)
}
</script>