👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

How to set the homepage of Sanity when using Next.js catch all route.

8 replies
Last updated: Feb 28, 2022
How do I set the homepage of sanity when using Next js catch all route? I have followed this tutorial from Simeon which works great. For prefixes and different types. But How do I specify a unique ID name to the page -> home from Sanity studio? From this example he has a ID but I am getting a unique generated ID

const docQuery = {
    home: groq`*[_id == "homePage"][0]`,
    article: groq`*[_type == "article" && slug.current == $slug][0]`,
    case: groq`*[_type == "case" && slug.current == $slug][0]`,
    page: groq`*[_type == "page" && slug.current == $slug][0]`,
  };
Feb 28, 2022, 4:52 PM
A document with a custom ID would be created either through the API/CLI (e.g.,
sanity documents create --id 'homePage'
) or by appending
;desiredId
in your Studio URL (e.g.,
<http://localhost:3333/desk/post;homePage>
).
Feb 28, 2022, 4:59 PM
Nice one Geoff! So, it doesn't matter if I change the slug for that page ID is staying unique?
Feb 28, 2022, 5:00 PM
Appending desired ID it's page “home” or by Title Home. So What would be the right command?
Feb 28, 2022, 5:02 PM
So, it doesn’t matter if I change the slug for that page ID is staying unique?
Correct. The
_id
will never change.

Appending desired ID it’s page “home” or by Title Home. So What would be the right command?
I’m not understanding what you’re asking here. Both of the above approaches will only work to create a new document. If you want to change the existing one, you’ll need to script copying over the data or export to get the NDJSON and then import the new document.
Feb 28, 2022, 5:16 PM
I have removed my dummy page “Home” from my “Page” / Pages type. Now, I want to create that same page. This new page should have a ID homePage instead of the unique ID.
Feb 28, 2022, 5:20 PM
Ah, thank you. You’ll navigate to the page in your studio using the URL format
<http://localhost:3333/desk/><documentType>;<desiredId>
. (replace
<http://localhost:3333>
with
<https://deployedName.sanity.studio>
if you’re doing this on your deployed studio) to create the document, which you then proceed to populate with your content (title, etc.). If I understand you correctly, you’d use
<http://localhost:3333/desk/page;homePage>
.
Feb 28, 2022, 5:33 PM
Thank you Geoff!
Feb 28, 2022, 5:34 PM
appreciated
Feb 28, 2022, 5:34 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?