Hi @Phil
I was about to write a new post on this after having read this thread a few days ago, but noticed there'd been activity on here since and you'd been helping someone out with their query. Hoping this is fresh in your mind and you'll have a quick and easy answer to my question.
I'm currently trying to paginate my blog category pages located at filepath: '/categories/[uid].js'.
I found the following posts that seem to offer an indication of how it might be done:
Unfortunately, I've still not managed to get anything running successfully, despite trying a few different iterations with snippets from the above posts. My getStaticProps and getStaticPaths functions look a bit different to those in the above posts which is throwing me off.
Here is the code I have so far. It would be amazing if you could offer some guidance in how to take this from where it is now to having working pagination.
Thanks
export const getStaticProps = async ({ params }) => {
const page = await useGetStaticProps({
client: Client(),
type: 'blog-category',
apiParams({ params }) {
return {
uid: params.uid,
};
},
})({ params });
const blogPosts = await Client().query(
[
Prismic.Predicates.at('document.type', 'blog-post'),
Prismic.Predicates.at('my.blog-post.category', page.props.id),
],
{ orderings: '[my.blog-post.date desc]' },
);
return {
props: {
params: params,
blogPosts: blogPosts,
...page.props,
},
};
};
export const getStaticPaths = useGetStaticPaths({
client: Client(),
type: 'blog-category',
formatPath: (prismicDocument) => {
return {
params: {
uid: prismicDocument.uid,
},
};
},
});