Vue Utils
queryCollectionNavigation
The queryCollectionNavigation composable generates the navigation tree of given collection.
Type
function queryCollectionNavigation<T extends keyof PageCollections>(collection: T, fields?: Array<keyof PageCollections[T]>): Promise<ContentNavigationItem[]>
Usage
Use the auto-imported queryCollectionNavigation
to generate a navigation tree for a specific collection. This is particularly useful for creating dynamic navigation menus or sidebars based on your content structure.
pages/[...slug].vue
<script setup lang="ts">
const { data } = await useAsyncData('navigation', () => {
return queryCollectionNavigation('docs')
})
</script>
API
queryCollectionNavigation(collection: CollectionName, extraField: keyof Collection)
Generate a navigation tree for the specified collection.
- Parameters:
collection
: The key of the defined collection incontent.config.ts
.extraFields
: (Optional) An array of additional fields to include in the navigation items. (By defaulttitle
andpath
are included in the navigation items.)
- Returns: A Promise that resolves to a navigation tree structure.
The navigation tree is generated based on the directory structure and ordering happens based on files ordering