---
title: "useCategory"
description: "Provides the sidebar category definitions that decide how pages with a category are grouped and ordered within a section. Declare them in docs.categories in app.config; override the composable in your project only when categories must be computed at runtime."
canonical_url: "https://docs.mhaibaraai.cn/en/docs/reference/composables/use-category"
---
# useCategory

> Provides the sidebar category definitions that decide how pages with a category are grouped and ordered within a section. Declare them in docs.categories in app.config; override the composable in your project only when categories must be computed at runtime.

`useCategory()` reads `docs.categories` from `app.config` and resolves category titles for the current locale. [`useNavigation`](https://docs.mhaibaraai.cn/en/docs/reference/composables/use-navigation) uses it to group pages.

## Recommended: Declare in app.config

Keys are the slugs of top-level section directories (without the numeric prefix); values are category lists, and list order is sidebar order:

```ts [app/app.config.ts]
export default defineAppConfig({
  docs: {
    categories: {
      guide: [
        { id: 'basics', title: { 'zh-CN': '基础', 'en': 'Basics' }, icon: 'i-lucide-settings' },
        { id: 'shipping', title: { 'zh-CN': '发布', 'en': 'Shipping' }, icon: 'i-lucide-rocket' }
      ]
    }
  }
})
```

Pages join a category through the `category` frontmatter field:

```md [content/docs/2.guide/9.deployment.md]
---
title: Deployment
category: shipping
---
```

See [Navigation and Categories](https://docs.mhaibaraai.cn/en/docs/guide/navigation) for details.

## Signature

```ts
function useCategory(): {
  categories: ComputedRef<Record<string, Category[]>>
}

interface Category {
  id: string
  title: string
  icon: string
}
```

## Return Value

| Name | Type | Description |
| --- | --- | --- |
| `categories` | `ComputedRef<Record<string, Category[]>>` | Keys are section slugs, values are that section's categories with `title` resolved for the current locale |

## Overriding

Create a same-named file in your project. The return shape must stay `{ categories }`:

```ts [app/composables/useCategory.ts]
export function useCategory() {
  const { t } = useMovkI18n()

  const categories = computed(() => ({
    guide: [
      { id: 'basics', title: t('docs.overview'), icon: 'i-lucide-settings' }
    ]
  }))

  return {
    categories
  }
}
```

Once overridden, `docs.categories` no longer applies.

## Changelog

See commit history for [layer/app/composables/useCategory.ts](https://github.com/mhaibaraai/movk-nuxt-docs/commits/main/layer/app/composables/useCategory.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-nuxt-docs/blob/main/layer/app/composables/useCategory.ts)


## Sitemap

See the full [sitemap](https://docs.mhaibaraai.cn/sitemap.md) for all pages.
