Adding Pagination
A page displaying a list of content gets longer as the amount of content grows. Pagination is the technique of spreading that content across multiple pages.
The goal of pagination is to create multiple pages (from a single template) that show a limited number of items.
Each page will query GraphQL for those specific items.
The information needed to query for those specific items (i.e. values for limit
and skip
) will come from the context
that is added when creating pages in gatsby-node
.
Example
The code above will create a number of pages based on the total number of posts. Each page will list postsPerPage
(6) posts, until there are less than postsPerPage
(6) posts left.
The path for the first page is /blog
, following pages will have a path of the form: /blog/2
, /blog/3
, etc.
Other resources
Follow this step-by-step tutorial to add links to the previous/next page and the traditional page-navigation at the bottom of the page
See gatsby-paginated-blog (demo) for an extension of the official gatsby-starter-blog with pagination in place