Merge pull request #64 from dikstub-rssa/fix/header-panel
nav(header): add breadcrumb
This commit is contained in:
@@ -2,14 +2,16 @@
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
function setLinks() {
|
function setLinks() {
|
||||||
if (route.fullPath === '/') {
|
if (route.path === '/') {
|
||||||
return [{ title: 'Home', href: '/' }]
|
return [{ title: 'Home', href: '/' }]
|
||||||
}
|
}
|
||||||
|
|
||||||
const segments = route.fullPath.split('/').filter((item) => item !== '')
|
const segments = route.path.split('/').filter((item) => item !== '')
|
||||||
|
|
||||||
const breadcrumbs = segments.map((item, index) => {
|
const breadcrumbs = segments.map((item, index) => {
|
||||||
const str = item.replace(/-/g, ' ')
|
// Bersihkan query parameters dari segment jika ada
|
||||||
|
const cleanItem = item.split('?')[0] || item
|
||||||
|
const str = cleanItem.replace(/-/g, ' ')
|
||||||
const title = str
|
const title = str
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
||||||
@@ -17,7 +19,7 @@ function setLinks() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
href: `/${segments.slice(0, index + 1).join('/')}`,
|
href: `/${segments.slice(0, index + 1).map(seg => seg.split('?')[0] || seg).join('/')}`,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -32,7 +34,7 @@ const links = ref<
|
|||||||
>(setLinks())
|
>(setLinks())
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => route.fullPath,
|
() => route.path,
|
||||||
(val) => {
|
(val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
links.value = setLinks()
|
links.value = setLinks()
|
||||||
@@ -46,7 +48,7 @@ watch(
|
|||||||
<div class="flex w-full items-center gap-4">
|
<div class="flex w-full items-center gap-4">
|
||||||
<SidebarTrigger />
|
<SidebarTrigger />
|
||||||
<Separator orientation="vertical" class="h-4" />
|
<Separator orientation="vertical" class="h-4" />
|
||||||
<!-- <BaseBreadcrumbCustom :links="links" /> -->
|
<PubBaseBreadcrumb :links="links" />
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-auto">
|
<div class="ml-auto">
|
||||||
<slot />
|
<slot />
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import {
|
||||||
|
Breadcrumb,
|
||||||
|
BreadcrumbItem,
|
||||||
|
BreadcrumbLink,
|
||||||
|
BreadcrumbList,
|
||||||
|
BreadcrumbSeparator,
|
||||||
|
} from '~/components/pub/ui/breadcrumb'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
links: {
|
||||||
|
title: string
|
||||||
|
href: string
|
||||||
|
}[]
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Breadcrumb>
|
||||||
|
<BreadcrumbList>
|
||||||
|
<BreadcrumbItem v-for="(link, index) in props.links" :key="link.href">
|
||||||
|
<BreadcrumbLink as-child>
|
||||||
|
<NuxtLink :to="link.href">
|
||||||
|
{{ link.title }}
|
||||||
|
</NuxtLink>
|
||||||
|
</BreadcrumbLink>
|
||||||
|
|
||||||
|
<BreadcrumbSeparator v-if="index < props.links.length - 1" />
|
||||||
|
</BreadcrumbItem>
|
||||||
|
</BreadcrumbList>
|
||||||
|
|
||||||
|
</Breadcrumb>
|
||||||
|
</template>
|
||||||
@@ -8,6 +8,28 @@ export default defineNuxtConfig({
|
|||||||
},
|
},
|
||||||
ssr: false,
|
ssr: false,
|
||||||
|
|
||||||
|
// SPA optimizations
|
||||||
|
router: {
|
||||||
|
options: {
|
||||||
|
hashMode: false, // Use history mode for cleaner URLs
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// Enable client-side rendering optimizations
|
||||||
|
nitro: {
|
||||||
|
prerender: {
|
||||||
|
crawlLinks: false, // Disable crawling for SPA
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// Optimize app loading
|
||||||
|
app: {
|
||||||
|
head: {
|
||||||
|
viewport: 'width=device-width,initial-scale=1',
|
||||||
|
charset: 'utf-8',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
modules: [
|
modules: [
|
||||||
'@unocss/nuxt',
|
'@unocss/nuxt',
|
||||||
'@vueuse/nuxt',
|
'@vueuse/nuxt',
|
||||||
|
|||||||
Reference in New Issue
Block a user