back and breadcrumbs

This commit is contained in:
vadim committed 2026-10-01 09:35:17 +03:00
1 parent c405507603
commit 9b70fb774f
9 files changed
+130 -4

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
export interface Breadcrumb {
title: string
to?: string
disabled?: boolean
}
/**
* Builds a breadcrumb trail from `meta.breadcrumb` on the matched route chain,
* so pages don't need to know their own position in the hierarchy.
*/
export function useBreadcrumbs() {
const route = useRoute()
const router = useRouter()
const breadcrumbs = computed<Breadcrumb[]>(() => {
const matched = route.matched.filter((record) => record.meta.breadcrumb)
return matched.map((record, index) => {
const { breadcrumb } = record.meta
const title = typeof breadcrumb === 'function' ? breadcrumb(route) : (breadcrumb as string)
const isLast = index === matched.length - 1
const to =
!isLast && record.name
? router.resolve({ name: record.name, params: route.params }).path
: undefined
return { title, to, disabled: isLast }
})
})
return { breadcrumbs }
}