I am trying to get my head around an issue of having two custom root document types (page and article) and also fetching the data correctly. I understand how to use a sub directory for a different document type and it works fine, but the following I cannot get working.
I have the following document types and routing:
{
type: "home",
path: "/",
},
{
type: "page",
path: "/:uid",
},
{
type: "article",
path: "/:uid",
},
{
type: "work",
path: "/work/:uid",
}
As I understood it from documentation my folder structure looks like this:
src
βββ app
β βββ [uid]
β β βββ page.tsx
β βββ work
β β βββ [uid]
β β βββ page.tsx
β βββ layout.tsx
β βββ page.tsx
βββ prismicio.ts
In my page.tsx I have the following code:
const client = createClient()
const page = await client.getByUID('page', params.uid).catch(() => notFound())
My question is, how do I include the article type in this fetching of data, it seems like getByUID only takes string for a single document type, so how can I include the article type in that query without hitting not found and a 404 page?
I tried the following in hope of checking if there was data and then use for the document returned, but it generates an error if the document type is not the type viewed by the user.
const page = await client.getByUID('page', params.uid).catch()
const article = await client.getByUID('article', params.uid).catch()
or:
const page = await (client.getByUID('page', params.uid).catch() || client.getByUID('article', params.uid).catch())
Plus, I've tried multiple other ideas, but nothing seems to work as soon as an article page is viewed. The reason I have two different root type documents is because of content and layout which is different, but the page always lives in the root hierarchy of the website.
Please give me some hints here on how to solve this.
Best,
F