Breadcrumbs.vue 983 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <v-breadcrumbs
  3. :items="items"
  4. />
  5. </template>
  6. <script setup lang="ts">
  7. import {computed, ComputedRef} from "@vue/reactivity";
  8. import {AnyJson} from "~/types/data";
  9. import {useI18n} from "vue-i18n";
  10. import UrlUtils from "~/services/utils/urlUtils";
  11. const runtimeConfig = useRuntimeConfig()
  12. const i18n = useI18n()
  13. const router = useRouter()
  14. const items: ComputedRef<Array<AnyJson>> = computed(() => {
  15. const crumbs:Array<AnyJson> = []
  16. crumbs.push({
  17. title: i18n.t('welcome'),
  18. href: runtimeConfig.baseUrlAdminLegacy
  19. })
  20. const pathPart: Array<string> = UrlUtils.split(router.currentRoute.value.path)
  21. let path: string = ''
  22. pathPart.forEach((part) => {
  23. path = `${path}/${part}`
  24. const match = router.resolve(path)
  25. if (match.name !== null) {
  26. crumbs.push({
  27. title: !parseInt(part, 10) ? i18n.t(part + '_breadcrumbs') : i18n.t('item'),
  28. exact: true,
  29. to: path
  30. })
  31. }
  32. })
  33. return crumbs
  34. })
  35. </script>