Hi Prismic,
I am experiencing difficulty in displaying article pagination on the homepage.
I want display only three articles and incorporate a pagination feature at the bottom of the page that allows the user to navigate to the next set of three articles by clicking on the corresponding page number.
I created my app using blog starter nextjs-starter-prismic-blog
I have pages/index.js page with following page which allows display only three aritcles
export async function getStaticProps({ previewData }) {
const client = createClient({ previewData });
const articles = await client.getByType("article", {
orderings: [
{ field: "my.article.publishDate", direction: "desc" },
{ field: "document.first_publication_date", direction: "desc" },
],
pageSize: 3,
});
const navigation = await client.getSingle("navigation");
const settings = await client.getSingle("settings");
console.log(articles);
return {
props: {
articles,
navigation,
settings,
// params,
},
};
}
Also I have pages/articles/[uid].js file
export async function getStaticProps({ params, previewData }) {
const client = createClient({ previewData });
// console.log(params);
const article = await client.getByUID("article", params.uid);
const page = params;
const latestArticles = await client.getAllByType("article", {
limit: 3,
orderings: [
{ field: "my.article.publishDate", direction: "desc" },
{ field: "document.first_publication_date", direction: "desc" },
],
});
const navigation = await client.getSingle("navigation");
const settings = await client.getSingle("settings");
return {
props: {
article,
latestArticles,
navigation,
settings,
page,
},
};
}
export async function getStaticPaths() {
const client = createClient();
const articles = await client.getAllByType("article");
const path = articles.map((article) => prismicH.asLink(article));
console.log(path);
return {
paths: articles.map((article) => prismicH.asLink(article)),
fallback: false,
};
}
How can I use page
parameter to my URL? so I can do something like myblog.com/articles/page-2 and pass this information to my pagination ?
Thanks