Question about unique UIDs and hierarchical URLs

Hi there –

I found this page about creating hierarchical relationships between documents (e.g., parent and child pages).

I also gather that you're supposed to use the UID field type for URL slugs.

However, I've run into a limitation.

Since a document's UID must be unique within its content type, it isn't possible to have two URLs which contain the same segment – e.g.:

/capabilities/web-development
/tutorials/web-development

Prismic won't allow me to create the second page, because there's already a document with the UID "web-development".

I guess I could use a Key Text field (instead of a UID field) to represent a page's URL slug – but then I can't make the field required, and I can't prevent content authors from creating duplicate URLs.

Is there a workaround?

Thanks.

Hi @tmiller ,

As you noted, UIDs are unique among Custom Types. For your use case — having the same UID for two different paths — we would recommend creating two different Custom Types. In this case, a "Capabilities" Custom Type and a "Tutorials" Custom Type. That way you can avoid name-spacing issues, and make use of all of the benefits of the UID field (truly unique, required, getByUID() helper functions, etc).

Otherwise, it is certainly possible to use the Key Text field to construct your URL path, but we wouldn't recommend it for the reasons you described — it isn't necessarily unique, or required, and it's also not encoded for a URL.

I hope that helps! Let me know if you have other questions.

Sam

1 Like

This issue has been closed due to inactivity. Flag to reopen.