Dealing with Duplicate UIDs within the Same Custom Type

So I'm trying to figure out the best way to handle dynamic "page" paths and was hoping someone could advise me.

Let's say I have a "page" custom type with a basic setup:

Page

  • Title
  • UID
  • Page_Group
  • Content

Now my understanding is the UID acts as the slug as well as a unique ID for the custom type--meaning you can't have 2 different page documents with the same UID. But what happens if you need to have two pages that have the same slug?

For example (assuming a "/:page_group?/:uid" routeResolver path)
/help
/product-name/help

Both would be from the same "page" custom type in Prismic. Since the end slug on each would need to be from "UID" we have a conflict.

I thought about making a separate "slug" field that I use in place of UID but 1) it could confuse a content author on why there are two fields that are so similar; and, 2) the only field Prismic requires and does the "slugify" formatting/validation on is UID.

I'm sure I'm not the first one to have this issue so any advice is appreciated.

Hello @dhayes

Thanks for reaching out to us.

You can not have the same UID in the same Custom Types documents.

You can try the following approach :

Create a document with UIDs named like product-name-help and help in prismic with the same Custom Type and while sending a query from /:page_group/:uid, concatenate the params with "-," and use the UID in query request like :page_group-:help for getting the content. This way, you can have the page URL like /product-name/help while you will be querying the content of product-name-help from prismic.

Let me know if you have any further questions.

Thanks,
Priyanka

@Priyanka Sorry, I'm not sure if I completely understand.

I understand that I can get around the UID duplication validation by adding to the name (e.g. "product-name-help") but I don't know how I resolve the URL to end in that UID/slug.

If the UID is "product-name-help" wouldn't the path for that page render as "domain.com/product-name-help" vs what I'll need it to be ("domain.com/product-name/help")?

Hello @dhayes

  1. In Prismic, create a document with UID as "product-name-help" and "help."
  2. On FE, create folder structure as per your need, like in the example you shared, it would be ``"/:page_group/:uid," so when someone hits the page like "/product-name/help," it comes at the right jsx.
  3. Under the jsx from the folder from Step 2, get all the params from the URL, which will be ["product-name," "help"].
  4. Now concatenate the params from Step 3 with a dash "-," and send it as UID in the query, which will be "product-name-help" in your case.

I hope it answers your questions. Let me know if you have any further questions.

Thanks,
Priyanka

1 Like