Breadcrumbs.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <v-breadcrumbs
  3. :items="items"
  4. />
  5. </template>
  6. <script lang="ts">
  7. import { defineComponent, computed, useContext, useRouter, ComputedRef } from '@nuxtjs/composition-api'
  8. import { AnyJson } from '~/types/interfaces'
  9. export default defineComponent({
  10. setup () {
  11. const { route, $config, app: { i18n } } = useContext()
  12. const $router = useRouter()
  13. const homeUrl:string = $config.baseURL_adminLegacy
  14. const items:ComputedRef<Array<AnyJson>> = computed(() => {
  15. const crumbs:Array<AnyJson> = []
  16. crumbs.push({
  17. text: i18n.t('welcome'),
  18. href: homeUrl
  19. })
  20. const fullPath:string = route.value.path
  21. const params:Array<string> = fullPath.startsWith('/') ? fullPath.substring(1).split('/') : fullPath.split('/')
  22. let path:string = ''
  23. params.forEach((param) => {
  24. path = `${path}/${param}`
  25. const match = $router.match(path)
  26. if (match.name !== null) {
  27. crumbs.push({
  28. text: !parseInt(param, 10) ? i18n.t(param + '_breadcrumbs') : i18n.t('item'),
  29. nuxt: true,
  30. 'exact-path': true,
  31. to: path
  32. })
  33. }
  34. })
  35. return crumbs
  36. })
  37. return {
  38. items
  39. }
  40. }
  41. })
  42. </script>