useDocsNavigation
Reuse the docs navigation tree loaded by the site shell in your own navigation components.
useDocsNavigation() returns the navigation tree that useDocsShell provides in app.vue, already loaded and transformed for the current locale.
Usage
app/components/SectionList.vue
<script setup lang="ts">
const navigation = useDocsNavigation()
</script>
<template>
<ul>
<li v-for="section in navigation" :key="section.path">
<NuxtLink :to="section.path">
{{ section.title }}
</NuxtLink>
</li>
</ul>
</template>
Signature
function useDocsNavigation(): Ref<ContentNavigationItem[] | undefined>
Return Value
| Name | Type | Description |
|---|---|---|
| (return value) | Ref<ContentNavigationItem[] | undefined> | Top-level sections under the docs root; each children holds the section's pages, and the category and description frontmatter fields are kept on each node |
Notes
- Call it inside the component tree of
app.vueorerror.vue. Outside the shell (for example a customapp.vuethat does not calluseDocsShell) you get a ref whose value isundefined. - The injection key is the string
'navigation'. v2 code that callsinject('navigation')directly still works; new code should use this function. - To group by category or build breadcrumbs, pass the result to
useNavigation.
Changelog
No recent changes