-
Hi there, I've been testing vitepress for a time, and I decided to add a custom breadcrumbs component to my doc pages: <template>
<div class="bread-crumbs">
<span v-for="(crumb, index) in breadCrumbs" :key="crumb.path">
<a
class="bread-crumb"
:href="crumb.path"
:class="{ 'bread-crumb-nolink': crumb.path === '' }">{{ crumb.text }}</a>
<span v-if="index !== breadCrumbs.length - 1" class="bread-crumb-separator"> > </span>
</span>
</div>
</template>
<script setup>
const props = defineProps(['breadCrumbs'])
</script> Then I added the component to the layout slot as documented: Layout() {
return h(Theme.Layout, null, {
'doc-before': () => h(BreadCrumbs),
})
}, But I need to send the prop to the slotted component, so I tried <script setup>
import { toRaw } from 'vue'
import { useData } from 'vitepress'
import BreadCrumbs from '../.vitepress/components/BreadCrumbs.vue'
const { frontmatter } = useData()
const breadCrumbs = toRaw(frontmatter.value).breadcrumbs
</script>
<BreadCrumbs :breadCrumbs="breadCrumbs"></BreadCrumbs> I wanted to send the Regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Create a <script setup lang="ts">
import DefaultTheme from 'vitepress/theme';
import BreadCrumbs from './BreadCrumbs.vue';
</script>
<template>
<DefaultTheme.Layout>
<template #doc-before>
<BreadCrumbs :breadCrumbs="$frontmatter.breadcrumbs" />
</template>
</DefaultTheme.Layout>
</template> Then use it your theme: // .vitepress/theme/index.ts
import DefaultTheme from 'vitepress/theme';
import Layout from '../components/Layout.vue';
export default {
...DefaultTheme,
Layout,
}; |
Beta Was this translation helpful? Give feedback.
-
@brc-dd will this work on pages with Dynamic Routes? I get empty frontmatter.value |
Beta Was this translation helpful? Give feedback.
Create a
Layout.vue
file:Then use it your theme: