Next.js Discord

Discord Forum

Pagination in server components in app directory

Unanswered
Pembroke Welsh Corgi posted this in #help-forum
Open in Discord
Pembroke Welsh CorgiOP
i'm building a blog with the app directory and contentful. i want to add pagination to it and also filter the bloglist by tag/category.
i.e. I would have routes like blog/[category] or blog/[pageNumber] or blog/[category]/[pageNumber] and ofcourse blog/[this-slug].

How do i implement the folder structure and pagination for something like this.
This is what my current project structure look like but I feel it can be better
blog/page/1/tag/tag-name
/blog
 page.tsx
  /[slug]
    page.tsx
  /page
    page.tsx
   /[page]
     page.tsx
     /tag
       [tag]
         page.tsx


Thanks

11 Replies

Well
If you already know all the pageNumber and Category i suppose you can
But you might want to boil it down to just

blog/[[slug]]
Asian black bear
quick easy idea: you could have a different path for blog posts and blog lists
blog/[slug]
posts/[category]/[page]
@alfon But you might want to boil it down to just blog/[[slug]]
Pembroke Welsh CorgiOP
okay, I wonder how i'll be able to differentiate a blog/[slug] or blog/[category] here
@Asian black bear blog/[slug] posts/[category]/[page]
Pembroke Welsh CorgiOP
oh cool,I'll try this. Thanks
You can try what minabot said

blog/[pagenumber]
blog/category/[categoryname]/[pagemumber]
blog/other/[slug]