
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYour approach of adding a slug field with a fixed default value to singletons is actually a solid pattern! This is a common and practical solution that many Sanity developers use. Let me break down a few approaches:
Add a slug field to your singleton documents with a fixed, read-only value:
// homepage.js (singleton)
{
name: 'homepage',
type: 'document',
fields: [
{
name: 'slug',
type: 'slug',
initialValue: {
current: '/'
},
readOnly: true,
hidden: true // Optional: hide it from editors since it never changes
},
// ... other fields
]
}
// blogOverview.js (singleton)
{
name: 'blogOverview',
type: 'document',
fields: [
{
name: 'slug',
type: 'slug',
initialValue: {
current: '/blog'
},
readOnly: true,
hidden: true
},
// ... other fields
]
}This way, when you create navigation arrays using references, all documents (singletons and regular pages) have a consistent slug field you can query.
Instead of storing slugs on singletons, handle them in your GROQ query:
*[_type == "navigation"][0] {
items[] {
title,
"slug": select(
reference->_type == "homepage" => "/",
reference->_type == "blogOverview" => "/blog",
reference->slug.current
),
reference-> {
_type,
title
}
}
}This keeps your schema cleaner but puts the logic in your queries.
Create a dedicated navigation schema where you can set custom paths for singletons:
{
name: 'navigation',
type: 'document',
fields: [
{
name: 'items',
type: 'array',
of: [{
type: 'object',
fields: [
{name: 'title', type: 'string'},
{name: 'reference', type: 'reference', to: [{type: 'homepage'}, {type: 'page'}, {type: 'blogOverview'}]},
{
name: 'customPath',
type: 'string',
description: 'Override path for singletons (e.g., "/" for homepage)'
}
]
}]
}
]
}Then in your frontend, use customPath if it exists, otherwise fall back to reference.slug.current.
Go with Approach 1 (fixed slugs on singletons). It's the most straightforward and keeps your data consistent. The slug field type supports this perfectly with initialValue and readOnly options. This pattern allows you to:
The slight "weirdness" of having a slug on a singleton is worth the consistency it brings to your navigation system. Many Sanity projects use this exact pattern successfully!
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store