Dynamic Path Handling in Next: Overcoming URL Constraints for Unlimited Page and Category Creation

Hello!

I have a question regarding defining page paths.
Suppose a client wants to create an unlimited number of pages with paths like:

/catalog/product1
/catalog/product2
/blog/product1
/blog/product2

In the "Catch-all paths" section of the documentation, it says:

params.uid contains an array of each part of the URL separated by a /.
In this example, the last part is the document's UID. /

const uid = params.pagePath[params.pagePath.length - 1] const page = await client.getByUID('page', uid)

Does this mean there is a strict requirement for the last part of the URL to be unique?
How can I bypass this limitation?
I want the client (without changing the code) to be able to add an unlimited number of categories ('catalog', 'blog', etc.) and an unlimited number of pages within categories.

I'm using Next 14 and App Router.

Thank you.

Hi @vagmen27,

Yes, if you use this setup (using the same "page" type for all your pages), then the last part of the URL will need to be unique for every page, even with different categories. Unfortunately, there isn't a way to bypass this.

The way around this would be to have different types for each category: a 'catalog' type, a 'blog' type, etc. But this obviously would require that a new type be created for each category and the code updated with any new category.

Maybe there are others in the community that have been in a similar situation who can discuss here what they did for this.