Menu

Routing System

Docsta uses a flexible and intuitive routing system built on top of Next.js App Router (or Pages Router, depending on your setup). It’s designed to work seamlessly with content sourced from Sanity or MDX files, and maps slugs directly to documentation pages.

1. Dynamic Routes

Each documentation page is accessed via a dynamic route based on its slug.

If you're using the App Router, the structure typically looks like:

app/
└── docs/
└── [slug]/
└── page.tsx

If you're using the Pages Router, it might look like:

pages/
└── docs/
└── [slug].tsx

These routes dynamically render content based on the slug field from your CMS or content source.

2. Default Route

By default, the root of your documentation (/docs) loads the "Introduction" page or a page with a slug like introduction.

You can customize this behavior in your route handler or loader function.

3. Linking Between Pages

To link between documentation pages, use the Next.js <Link> component:

import Link from 'next/link'
<Link href="/docs/installation">Installation</Link>

Or dynamically, based on a slug fetched from Sanity:

<Link href={`/docs/${doc.slug.current}`}>{doc.title}</Link>
4. Sidebar Navigation (Optional)

A common pattern is to render navigation in a sidebar using your fetched content structure. For example:

const sidebarItems = await fetchSidebar()
sidebarItems.map(item => (
<Link href={`/docs/${item.slug.current}`} key={item._id}>
{item.title}
</Link>
))

This creates a dynamic and CMS-driven navigation experience for your users.

5. Catch-All Routes (Advanced)

If you want to support nested slugs like /docs/getting-started/setup, you can use a catch-all route:

  • App Router: app/docs/[...slug]/page.tsx
  • Pages Router: pages/docs/[...slug].tsx

Then, parse the segments to fetch the correct content from Sanity or filesystem.

With Docsta’s flexible routing system, your docs can grow and scale without changing how routes are handled—whether it’s 5 pages or 500.

👉 Next Up: Learn how to write content using MDX or manage pages using Sanity Studio.

What did you think of this content?

like-icon

It was helpful

dislike-icon

It was not helpful

feedback-icon

I have a feedback