# 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.

## 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: '/introduction/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: '/introduction/getting-started' },
    {
      text: 'Writing',
      collapsed: false,
      items: [
        { text: 'Code & Syntax Highlighting', link: '/writing/syntax-highlighting' },
        { text: 'Code Snippets', link: '/writing/code-snippets' },
        { text: 'Markdown Snippets', link: '/writing/markdown-snippets' },
        { text: 'Markdown Extensions', link: '/writing/markdown-extensions' },
        { text: 'Using React', link: '/writing/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: '/introduction/getting-started/install' },
+  ],
  sidebar: [
-   { text: 'Installation', link: '/guide/install' },
+   { text: 'Installation', link: '/introduction/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: '/introduction/getting-started' },
      { text: 'Theming', link: '/features/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: '/introduction/getting-started',
      match: (path) => Boolean(path?.startsWith('/guide') || path?.startsWith('/reference')) // [!code focus]
    }
  ]
})
```

`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 // [!code focus]
    }
  ],
  topNav: [
    {
      text: 'Resources',
      items: [
        { text: 'Changelog', link: '/changelog' },
        { text: 'GitHub', link: 'https://github.com/wevm/vocs' }
      ]
    }
  ]
})
```

## See More

<Cards>
  <Card title="sidebar" description="Items, path scoping, backLink, collapsing, and external links." icon="panel-left" to="/reference/site-config#sidebar" />

  <Card title="topNav" description="Top navigation items, dropdown menus, and match logic." icon="navigation" to="/reference/site-config#topnav" />
</Cards>
