I just started to fetch data from prismic cms nus it gives me Error: No documents were returned error.
Could you please help me to fix this?
It says that no documents are returned as I think you are passing not the right thing as ID param:
const page = await client.getByUID("career", params.career)
If you can console.log uid as params.career.id
why are you passing params.career
?
I would say try to get the document first by passing the actual hardcoded ID, for example:
const page = await client.getByUID("career", "my-career-page-id")
and see if you can receive the document.
You should name your dynamic route:
[uid]
So the path to this page in your project is like:
app/[uid]/page.tsx
And then you can simply get the uid param:
type Params = {
uid: string;
};
export default async function CareerPage({params}: { params: Params }) {
const client = createClient();
const page = await client.getByUID('career', params.uid)
console.log(page)
// ... rest of the code
}
To get UID as param you also need to tell Next to generate params:
export async function generateStaticParams() {
const client = createClient();
const pages = await client.getAllByType('career')
return pages.map(page => ({uid: page.uid});
}
If that's a single page type (unique page) you don't need UID and params, if it's a repeated page type, you will have to do as above. For single pages you can simply do
await client.getSingle('home_page')
To receive the document.
Everything is well described in the docs Fetch Data in Next.js - Documentation - Prismic Just read them through and everything will become clear!
Thank you so much