How to set the homepage of Sanity when using Next.js catch all route.
Based on the official Sanity documentation on document IDs, the short answer is: you can't easily set a custom document ID like "homePage" in Sanity Studio, and the official recommendation is to use a different approach.
The Reality About Custom IDs
The Sanity documentation explicitly states: "There is no way to override the default ID logic" in the Studio. While it's technically possible to create documents with custom IDs via the API or CLI, this isn't the recommended approach and comes with important caveats:
- Any document ID containing a
.(dot) is considered private and requires authentication - Custom IDs can cause unexpected interactions with platform functionality
- Once set, document IDs cannot be changed
The Recommended Approach: Use a Singleton Pattern
Instead of trying to force a custom ID, here are better patterns for handling your homepage:
Option 1: Create a custom field for identification
Add a field to your page schema that you can query by:
// In your schema
{
name: 'page',
type: 'document',
fields: [
{
name: 'pageId',
type: 'string',
validation: Rule => Rule.required(),
// Could use an enum for specific pages
options: {
list: [
{title: 'Home', value: 'home'},
{title: 'About', value: 'about'}
]
}
}
// ... other fields
]
}Then query it like:
const docQuery = {
home: groq`*[_type == "page" && pageId == "home"][0]`,
article: groq`*[_type == "article" && slug.current == $slug][0]`,
// ...
}Option 2: Use a dedicated singleton document type
Create a separate document type specifically for the homepage:
// homePage.js schema
export default {
name: 'homePage',
type: 'document',
title: 'Home Page',
fields: [
// your fields
]
}Then in your Structure tool configuration, ensure only one instance can be created:
S.listItem()
.title('Home Page')
.child(
S.document()
.schemaType('homePage')
.documentId('homePage') // This sets the ID in the structure
)Query it by type (since there's only one):
const homeQuery = groq`*[_type == "homePage"][0]`Option 3: If you absolutely must use the API approach
If you're creating the document programmatically and need a specific ID, you can use the client:
import {createClient} from '@sanity/client'
const client = createClient({...})
await client.createIfNotExists({
_id: 'homePage',
_type: 'page',
title: 'Home',
// ... other fields
})But remember: this bypasses Studio's default behavior and isn't officially supported for manual document creation.
Why Simeon's Example Works
In the tutorial you're following, Simeon likely either:
- Created that document with a custom ID via the API/CLI before the tutorial
- Used a singleton pattern with a predictable query
- Configured the Structure tool to use a specific document ID
The key takeaway: focus on querying patterns rather than forcing custom IDs. Using a custom field or a singleton document type is more maintainable and aligns with Sanity's recommended practices.
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.