#using params in paginate

3 messages · Page 1 of 1 (latest)

solemn currentBOT
#

Hi @indigo reef. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the knowledge sources, I can explain why console.log(Astro.params) is showing {page: undefined} in your code.

The issue is related to how you're using the paginate() function and the naming of your route file. Let's break it down:

  1. Your file is named [...page], which uses a rest parameter in the filename. This is correct for pagination.

  2. However, in your paginate() function, you're passing params: { locale } instead of params: { page }.

According to the Pagination documentation, the paginate() function assumes a file name of [page].astro or [...page].astro. The page param becomes the page number in your URL.

To fix this issue, you should modify your paginate() call to include the page parameter:

return paginate(posts, {
  pageSize: 3,
  params: { page: 1, locale },
});

By including page: 1 in the params object, you're explicitly setting the initial page number. This should populate Astro.params.page correctly.

Additionally, for an i18n project, you might want to consider using nested pagination as described in the Nested Pagination documentation. This would allow you to group your paginated content by language.

If you're still experiencing issues after making these changes, it's possible that there might be other factors at play that aren't covered in the provided knowledge sources. In that case, you might need to consult the full Astro documentation or seek help from the Astro community.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@indigo reef Kapa.ai is still learning and improving, please let me know how I did by reacting below.