Is there any way to prefix a slug, ie category page for mens would be /category/mens?

2 replies
Last updated: Nov 29, 2025
Is there any way to prefix a slug, ie category page for mens would be /category/mens - it most likely me being stupid so points in the right direction would be helpful aswell
AI Update

You're not being stupid at all! This is a common question and there are several ways to handle prefixed slugs in Sanity.

The key thing to understand is that Sanity stores just the slug value (like "mens") in your content, and you handle the prefix (like "/category/") in your frontend routing code, not in Sanity itself.

Here are your main approaches:

Store just the slug value ("mens") in Sanity, then add the prefix in your frontend:

// In your schema
{
  name: 'slug',
  type: 'slug',
  options: {
    source: 'title'
  }
}

// In your Next.js/frontend code
const categoryUrl = `/category/${category.slug.current}`;

This keeps your content flexible - you can change URL patterns without updating content.

2. Store the full path in the slug field

You can actually include the prefix directly in the slug using a custom slugify function in your schema:

{
  name: 'slug',
  type: 'slug',
  options: {
    source: 'title',
    slugify: input => `/category/${input.toLowerCase().replace(/\s+/g, '-')}`
  }
}

Though this is less flexible if you want to change your URL structure later.

3. Programmatically prefix during queries

You can also construct the full path in your GROQ queries:

*[_type == "category"] {
  title,
  "fullPath": "/category/" + slug.current
}

Bottom line: Most developers go with option #1 - store clean slugs in Sanity ("mens") and handle prefixes in your routing code (/category/${slug}). This keeps your content portable and your URL structure flexible. The slug field in Sanity is really just for storing the unique identifier part, not the full URL path.

Show original thread
2 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?