|
1 | 1 | <template> |
2 | | - <div class="row row--page-opener"> |
| 2 | + <div class="row row--page-opener" v-if="breadcrumbs.length != 0"> |
3 | 3 | <div class="container"> |
4 | 4 | <div class="breadcrumb"> |
5 | | - <p>U bent hier:</p> |
| 5 | + <p>{{ t('you-are-here') }}:</p> |
6 | 6 | <ol> |
7 | | - <li> |
8 | | - <a href="#">Zoeken</a> |
| 7 | + <li v-for="crumb in breadcrumbsWithLinks"> |
| 8 | + <a v-if="crumb.routeName != null" :href="`/${crumb.routeName}`">{{ |
| 9 | + crumb.label |
| 10 | + }}</a> |
| 11 | + <span v-if="crumb.routeName == null">{{ crumb.label }}</span> |
9 | 12 | </li> |
10 | | - <li> |
11 | | - <a href="#">Zoekresultaten</a> |
12 | | - </li> |
13 | | - <li>Regeling</li> |
| 13 | + <li>{{ pathTail.label }}</li> |
14 | 14 | </ol> |
15 | 15 | </div> |
16 | 16 | </div> |
17 | 17 | </div> |
18 | 18 | </template> |
| 19 | + |
| 20 | +<script setup lang="ts"> |
| 21 | +import { navigationItems } from '@/config/config' |
| 22 | +import { useI18n } from 'vue-i18n' |
| 23 | +import algoritmeService from '@/services/algoritme' |
| 24 | +import { AlgNamesOnly } from '~~/types/algoritme' |
| 25 | +const { t } = useI18n() |
| 26 | +const currentRoute = useRoute() |
| 27 | +
|
| 28 | +const { data } = await algoritmeService.getNames() |
| 29 | +let nameList = ref(data.value as AlgNamesOnly[]) |
| 30 | +
|
| 31 | +const navigationItemsTranslated = computed(() => |
| 32 | + navigationItems.map((item) => { |
| 33 | + return { label: t(item.label), routeName: item.routeName } |
| 34 | + }) |
| 35 | +) |
| 36 | +
|
| 37 | +const navigationItemsWithoutLink = ['footer'] |
| 38 | +
|
| 39 | +const breadcrumbs = computed(() => { |
| 40 | + const path = currentRoute.path |
| 41 | + const breadCrumbs = path != '/' ? path.split('/').slice(1) : [] |
| 42 | +
|
| 43 | + return breadCrumbs.map((crumb) => { |
| 44 | + return { |
| 45 | + label: |
| 46 | + // translate path parts with a name matching a navigation item |
| 47 | + navigationItemsTranslated.value.find((item) => item.routeName == crumb) |
| 48 | + ?.label || // translate path parts with a name matching an algorithm id |
| 49 | + nameList.value.find((alg: any) => alg.id == crumb)?.name || |
| 50 | + crumb, |
| 51 | + routeName: navigationItemsWithoutLink.includes(crumb) ? null : crumb, |
| 52 | + } |
| 53 | + }) |
| 54 | +}) |
| 55 | +
|
| 56 | +const breadcrumbsWithLinks = computed(() => breadcrumbs.value.slice(0, -1)) |
| 57 | +const pathTail = computed(() => breadcrumbs.value.slice(-1)[0]) |
| 58 | +</script> |
0 commit comments