NuxtN
Nuxt9mo ago
184 replies
WiFi Plug

nuxt ui pro content navigation not showing up

<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'

const route = useRoute()

// Fetch the current page content
const { data: page } = await useAsyncData(route.path, () =>
  queryCollection('content').path(route.path).first()
)
if (!page.value) {
  throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
}

// Content navigation
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')

// Fetch the surrounding pages (prev/next)
const { data: surround } = await useAsyncData(`${route.path}-surround`, () => {
  return queryCollectionItemSurroundings('content', route.path, {
    fields: ['description'],
  })
})
</script>

<template>
  <UPage v-if="page" class="p-4">
    <UPageHeader :title="page.title" :description="page.description" />

    <template #left>
      <UPageAside>
        <UContentNavigation :navigation="navigation" highlight />
      </UPageAside>
    </template>

    <UPageBody>
      <ContentRenderer v-if="page.body" :value="page" />

      <USeparator v-if="surround?.filter(Boolean).length" />

      <!-- Prev/Next navigation -->
      <UContentSurround :surround="(surround as any)" />
    </UPageBody>

    <!-- Table of Contents in the right slot -->
    <template v-if="page?.body?.toc?.links?.length" #right>
      <UContentToc
        highlight
        highlight-color="primary"
        color="primary"
        :links="page?.body?.toc?.links"
      />
    </template>
  </UPage>
</template>
hi im trying to setup a content page with navigation on the left but i don't see the content navigation. do i need to set anything up in another file for it?
import { defineContentConfig, defineCollection } from '@nuxt/content'

export default defineContentConfig({
  collections: {
    content: defineCollection({
      type: 'page',
      source: '**/*.md',
    }),
  },
})
Was this page helpful?