这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@shelton-xiaoteng-ma
Copy link
Contributor

Implement pagination for tag pages using searchParams instead of dynamic router to minimize changes

  • Added pagination support to tag pages.
  • Replaced dynamic router with searchParams for pagination, reducing the number of changes to existing routing logic.
  • Updated navigation links to include pagination parameters via searchParams.
  • Ensured backwards compatibility with previous URL structures while introducing pagination.

@vercel
Copy link

vercel bot commented Dec 29, 2024

@shelton-xiaoteng-ma is attempting to deploy a commit to the timlrx's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jan 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tailwind-nextjs-starter-blog ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 6, 2025 2:08pm

@timlrx
Copy link
Owner

timlrx commented Jan 5, 2025

Thanks, this closes #869

There's a small bug introduced with the change - could you help to resolve it? The main tags page still shows the "Next" button as active despite it being the last page: https://tailwind-nextjs-starter-blog-git-fork-s-a5ce5a-timlrxs-projects.vercel.app/blog?page=2

@shelton-xiaoteng-ma
Copy link
Contributor Author

Ok, I have solved it.
This bug is caused by using the same ListLayout from @/layouts/ListLayoutWithTags, now I have refactored /blog, deleted /blog/[page]/page.tsx, and made sure /blog and /tags/next-js uses the same pagination logic

@timlrx
Copy link
Owner

timlrx commented Jan 6, 2025

Thanks, the not found logic seems to be different. For e.g. https://tailwind-nextjs-starter-blog-cxns6sbn4-timlrxs-projects.vercel.app/blog?page=3 directs to page 1 despite there not being a valid page 3. It displays a 404 error for the tag routes.

@shelton-xiaoteng-ma
Copy link
Contributor Author

The URL you are using is outdated, I saw the new deployment URL: https://tailwind-nextjs-starter-blog-nvzeomgx1-timlrxs-projects.vercel.app/, so https://tailwind-nextjs-starter-blog-nvzeomgx1-timlrxs-projects.vercel.app/blog?page=3 shows Not Found as expected
Screenshot 2025-01-07 at 15 07 27

@timlrx
Copy link
Owner

timlrx commented Jan 9, 2025

Opps sorry, was looking at the old one. In that case the changes looks good to me and thanks for the contribution!

@timlrx timlrx merged commit 9862697 into timlrx:main Jan 9, 2025
2 checks passed
@timlrx
Copy link
Owner

timlrx commented Jan 9, 2025

I get a bunch of build errors for the static version of the site:

Error occurred prerendering page "/tags/markdown". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Route /tags/[tag] with `dynamic = "error"` couldn't be rendered statically because it used `await searchParams`, `searchParams.then`, or similar. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering
Export encountered an error on /tags/[tag]/page: /tags/markdown, exiting the build.
Error occurred prerendering page "/tags/images". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Route /tags/[tag] with `dynamic = "error"` couldn't be rendered statically because it used `await searchParams`, `searchParams.then`, or similar. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering
Export encountered an error on /tags/[tag]/page: /tags/images, exiting the build.

I think the inclusion of searchParams changes it from statically rendered to dynamic rendering. Do you have any work arounds that would still allow it to be statically rendered?

@shelton-xiaoteng-ma
Copy link
Contributor Author

Sorry for the new error. I am not familiar with this.
ChatGPT says that you can use "precompute all possible values", I think it works for tags, but for pages, Maybe Use useSearchParams and handle logic on the client.
I will try other options later.

bhiwagade-rahul pushed a commit to bhiwagade-rahul/tailwind-nextjs-starter-blog that referenced this pull request Sep 22, 2025
…n-to-tags

feat(pagination): Implement pagination for tag pages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants