|
| 1 | +--- |
| 2 | +title: SiteHeader with Breadcrumbs |
| 3 | +description: Guide for implementing dynamic breadcrumb navigation in the dashboard header. |
| 4 | +--- |
| 5 | + |
| 6 | + |
| 7 | +The SiteHeader component displays a sidebar toggle and breadcrumb navigation at the top of each dashboard page. Views set their breadcrumbs using the `useBreadcrumbs` composable. |
| 8 | + |
| 9 | +## Component Locations |
| 10 | + |
| 11 | +``` |
| 12 | +services/frontend/src/ |
| 13 | + ├─ composables/ |
| 14 | + └─ useBreadcrumbs.ts # Shared breadcrumb state management |
| 15 | + ├─ components/ |
| 16 | + ├─ SiteHeader.vue # Header with sidebar trigger + breadcrumbs |
| 17 | + └─ DashboardLayout.vue # Layout wrapper that includes SiteHeader |
| 18 | +``` |
| 19 | + |
| 20 | +## Composable API |
| 21 | + |
| 22 | +The `useBreadcrumbs` composable manages breadcrumb state across all views. |
| 23 | + |
| 24 | +### BreadcrumbItem Interface |
| 25 | + |
| 26 | +```typescript |
| 27 | +interface BreadcrumbItem { |
| 28 | + label: string // Display text |
| 29 | + href?: string // Optional link - omit for current page |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +### Returned Values |
| 34 | + |
| 35 | +| Property | Type | Description | |
| 36 | +|----------|------|-------------| |
| 37 | +| `breadcrumbs` | `Readonly<Ref<BreadcrumbItem[]>>` | Current breadcrumb items | |
| 38 | +| `setBreadcrumbs` | `(items: BreadcrumbItem[]) => void` | Set the breadcrumb trail | |
| 39 | +| `clearBreadcrumbs` | `() => void` | Clear all breadcrumbs | |
| 40 | + |
| 41 | +## Usage Patterns |
| 42 | + |
| 43 | +### Static Pages |
| 44 | + |
| 45 | +For pages with fixed titles like Dashboard or Settings: |
| 46 | + |
| 47 | +```vue |
| 48 | +<script setup lang="ts"> |
| 49 | +import { onMounted } from 'vue' |
| 50 | +import { useBreadcrumbs } from '@/composables/useBreadcrumbs' |
| 51 | +
|
| 52 | +const { setBreadcrumbs } = useBreadcrumbs() |
| 53 | +
|
| 54 | +onMounted(() => { |
| 55 | + setBreadcrumbs([{ label: 'Dashboard' }]) |
| 56 | +}) |
| 57 | +</script> |
| 58 | +``` |
| 59 | + |
| 60 | +### Detail Pages with Dynamic Data |
| 61 | + |
| 62 | +For pages that load data (team detail, server view), set breadcrumbs twice: |
| 63 | + |
| 64 | +```vue |
| 65 | +<script setup lang="ts"> |
| 66 | +import { onMounted, ref } from 'vue' |
| 67 | +import { useRoute } from 'vue-router' |
| 68 | +import { useBreadcrumbs } from '@/composables/useBreadcrumbs' |
| 69 | +import { TeamService } from '@/services/teamService' |
| 70 | +
|
| 71 | +const route = useRoute() |
| 72 | +const { setBreadcrumbs } = useBreadcrumbs() |
| 73 | +const team = ref(null) |
| 74 | +
|
| 75 | +onMounted(async () => { |
| 76 | + // Initial loading state |
| 77 | + setBreadcrumbs([ |
| 78 | + { label: 'Teams', href: '/teams' }, |
| 79 | + { label: 'Loading...' } |
| 80 | + ]) |
| 81 | +
|
| 82 | + // Fetch and update with actual name |
| 83 | + team.value = await TeamService.getTeam(route.params.id) |
| 84 | + setBreadcrumbs([ |
| 85 | + { label: 'Teams', href: '/teams' }, |
| 86 | + { label: team.value.name } |
| 87 | + ]) |
| 88 | +}) |
| 89 | +</script> |
| 90 | +``` |
| 91 | + |
| 92 | +### Nested Pages |
| 93 | + |
| 94 | +For deeply nested pages, include the full path: |
| 95 | + |
| 96 | +```vue |
| 97 | +setBreadcrumbs([ |
| 98 | + { label: 'MCP Catalog', href: '/admin/mcp-server-catalog' }, |
| 99 | + { label: server.name, href: `/admin/mcp-server-catalog/view/${serverId}` }, |
| 100 | + { label: 'Edit' } |
| 101 | +]) |
| 102 | +``` |
| 103 | + |
| 104 | +## Header Layout |
| 105 | + |
| 106 | +The SiteHeader renders in this order: |
| 107 | +1. **SidebarTrigger** - Toggle button for collapsing/expanding sidebar |
| 108 | +2. **Separator** - Vertical divider |
| 109 | +3. **Breadcrumbs** - Navigation trail with responsive visibility |
| 110 | + |
| 111 | +On mobile, intermediate breadcrumb items are hidden, showing only the current page. |
| 112 | + |
| 113 | +## View Template |
| 114 | + |
| 115 | +Views no longer pass a `:title` prop to DashboardLayout: |
| 116 | + |
| 117 | +```vue |
| 118 | +<template> |
| 119 | + <DashboardLayout> |
| 120 | + <!-- Page content --> |
| 121 | + </DashboardLayout> |
| 122 | +</template> |
| 123 | +``` |
| 124 | + |
| 125 | +## Related Documentation |
| 126 | + |
| 127 | +- [UI Design System](/development/frontend/ui/) - Component design patterns |
| 128 | +- [Frontend Architecture](/development/frontend/architecture) - View and composable guidelines |
0 commit comments