useDocsNavigation
Read the docs navigation tree that the shell has already loaded. The header section bar, sidebar and docs pages all take their navigation from here, so custom components reuse the same data without querying the collection again.
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
useFetchComponentExample
Read the source code, file path and name of example components under components/content/examples. ComponentExample uses it to show example code; call it directly to display example source in your own components. Available only with component docs enabled.
useNavigation
Shape the docs navigation tree for the sidebar - top-level sections, the current section's pages grouped by docs.categories, and breadcrumbs for any path. Use it in a custom sidebar or table of contents to keep the default grouping rules.