<!--
Sitemap:
- [What is Vocs](/guide/what-is-vocs): Learn what Vocs provides for documentation sites
- [Getting Started](/guide/getting-started): Install Vocs and create your first documentation site
- [Writing Docs with AI](/guide/writing-docs-with-ai): Use an AI agent to create and maintain Vocs documentation
- [Project Structure](/guide/structure): Overview of the structure of a Vocs project
- [Markdown Extensions](/guide/markdown-extensions): Features and syntax of Markdown in Vocs
- [Code & Syntax Highlighting](/guide/syntax-highlighting): Rich markup and annotations for code
- [Code Snippets](/guide/code-snippets): Include and reuse code in Markdown
- [Markdown Snippets](/guide/markdown-snippets): Include other Markdown files in MDX
- [Asset Handling](/guide/asset-handling): Manage images, fonts, icons, and other docs assets
- [Frontmatter](/guide/frontmatter): Configure page metadata, layouts, search, and UI visibility
- [Using React in Markdown](/guide/react): Compose MDX pages with React components
- [Twoslash](/guide/twoslash): Add type-aware annotations to code examples
- [Sidebar & Top Navigation](/guide/navigation): Keep docs navigation synced with routes
- [Theming](/guide/theming): Customize colors, typography, spacing, logos, and code themes
- [Tailwind CSS](/guide/tailwind): Use Tailwind utilities in Vocs pages and components
- [Layouts](/guide/layouts): Choose and customize page shells for your docs
- [Dynamic OG Images](/guide/dynamic-og-images): Generate social preview images from page metadata
- [Feedback](/guide/feedback): Collect page-level feedback from readers
- [Changelog Generation](/guide/changelog-generation): Fetch release notes and render a changelog page
- [MCP Server](/guide/mcp-server): Expose your docs and source code to AI assistants
- [AI Support](/guide/ai-support): Make your documentation easier for AI assistants to read
- [Site Configuration](/reference/site-config): Reference for options accepted by defineConfig
- [Components](/reference/components): Reference for the public React components exported from Vocs
- [Hooks](/reference/hooks): Reference for the React hooks exported from Vocs
- [Changelog](/guide/changelog): Release history for Vocs
-->

# Sidebar & Top Navigation \[Keep docs navigation synced with routes]

Vocs reads pages from `src/pages`, but your visible navigation lives in `vocs.config.ts`. When you add, move, or rename pages, update navigation in the same change.

## Quick Prompt

Ask your AI agent to read this guide before changing navigation:

```txt
Read https://vocs.dev/guide/navigation and update the sidebar/top navigation for the docs pages in this project.
```

## Overview

Configure both navigation surfaces in `vocs.config.ts`:

* `sidebar` controls the docs navigation.
* `topNav` controls links and menus in the top bar.

The `pages/` directory defines your routes. The `vocs.config.ts` file defines what readers and agents can discover.

## Recipes

### Adding Pages

When you create `src/pages/guide/install.mdx`, add the matching route to `sidebar`.

```ts [vocs.config.ts]
import { defineConfig } from 'vocs/config'

export default defineConfig({
  sidebar: [
    { text: 'Getting Started', link: '/guide/getting-started' },
    { text: 'Installation', link: '/guide/install' },
  ],
})
```

### Adding Sections

Group related pages with an item that has `items`.

```ts [vocs.config.ts]
import { defineConfig } from 'vocs/config'

export default defineConfig({
  sidebar: [
    { text: 'Getting Started', link: '/guide/getting-started' },
    {
      text: 'Writing',
      collapsed: false,
      items: [
        { text: 'Code & Syntax Highlighting', link: '/guide/syntax-highlighting' },
        { text: 'Code Snippets', link: '/guide/code-snippets' },
        { text: 'Markdown Snippets', link: '/guide/markdown-snippets' },
        { text: 'Markdown Extensions', link: '/guide/markdown-extensions' },
        { text: 'Using React', link: '/guide/react' },
      ],
    },
  ],
})
```

### Moving Pages

When you move a page file, update the old sidebar link to the new route and add a redirect from the old URL.

```diff [vocs.config.ts]
export default defineConfig({
+  redirects: [
+    { source: '/guide/install', destination: '/guide/getting-started/install' },
+  ],
  sidebar: [
-   { text: 'Installation', link: '/guide/install' },
+   { text: 'Installation', link: '/guide/getting-started/install' },
  ],
})
```

:::tip
Use [`redirects`](/reference/site-config#redirects) to preserve old links when pages move.
:::

### Scoping Sidebars

Use the object form when different route sections need different sidebars.

```ts [vocs.config.ts]
import { defineConfig } from 'vocs/config'

export default defineConfig({
  sidebar: {
    '/guide': [
      { text: 'Getting Started', link: '/guide/getting-started' },
      { text: 'Theming', link: '/guide/theming' },
    ],
    '/reference': {
      backLink: true,
      items: [
        { text: 'Site Config', link: '/reference/site-config' },
        { text: 'Components', link: '/reference/components' },
      ],
    },
  },
})
```

Vocs picks the deepest matching path prefix for the current page.

### Highlighting Top Nav

Use `match` when one top nav item should stay active across a broader section.

```ts [vocs.config.ts]
import { defineConfig } from 'vocs/config'

export default defineConfig({
  topNav: [
    {
      text: 'Guide & API',
      link: '/guide/getting-started',
      match: (path) => Boolean(path?.startsWith('/guide') || path?.startsWith('/reference')),
    },
  ],
})
```

`match` can be either:

* a string prefix like `'/guide'`
* a function like `(path) => path?.startsWith('/guide')`

### Adding External Links

Absolute URLs are treated as external automatically. Set `external: true` when you want to be explicit.

```ts [vocs.config.ts]
import { defineConfig } from 'vocs/config'

export default defineConfig({
  sidebar: [
    {
      text: 'GitHub',
      link: 'https://github.com/wevm/vocs',
      external: true,
    },
  ],
  topNav: [
    {
      text: 'Resources',
      items: [
        { text: 'Changelog', link: '/guide/changelog' },
        { text: 'GitHub', link: 'https://github.com/wevm/vocs' },
      ],
    },
  ],
})
```

## Reference

:::note
See the [Site Config reference](/reference/site-config#sidebar) for the full `sidebar` API.
:::

### Sidebar Fields

Each sidebar item can use these fields:

* `text`
* `link`
* `items`
* `collapsed`
* `disabled`
* `external`

### `backLink`

Set `backLink: true` to show a `Back` link at the top of a path-scoped sidebar section.

```ts [vocs.config.ts]
import { defineConfig } from 'vocs/config'

export default defineConfig({
  sidebar: {
    '/reference': {
      backLink: true,
      items: [{ text: 'Site Config', link: '/reference/site-config' }],
    },
  },
})
```
