diff options
| author | copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> | 2026-04-25 12:31:54 +0000 |
|---|---|---|
| committer | Bertrand Yuan <189593334+bertyuan@users.noreply.github.com> | 2026-04-27 14:50:52 +0800 |
| commit | c8b9d38d55fdb48423e4fe663f9ccfb756ab603f (patch) | |
| tree | 8b7a24773975c3e41fb3bc765cab04c79839dec0 /src/app/(main)/(home) | |
| parent | a5e4155a752fa090c7bc3751a803b4359453e56c (diff) | |
fix: check NaN before page subtraction for clarity
Agent-Logs-Url: https://github.com/bertyuan/next-blog/sessions/f86da32b-3af7-4393-8077-ce3435137221
Co-authored-by: bertyuan <189593334+bertyuan@users.noreply.github.com>
Diffstat (limited to 'src/app/(main)/(home)')
| -rw-r--r-- | src/app/(main)/(home)/posts/page.tsx | 10 | ||||
| -rw-r--r-- | src/app/(main)/(home)/tags/[...slug]/page.tsx | 10 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/app/(main)/(home)/posts/page.tsx b/src/app/(main)/(home)/posts/page.tsx index daced35..376f5c1 100644 --- a/src/app/(main)/(home)/posts/page.tsx +++ b/src/app/(main)/(home)/posts/page.tsx @@ -55,16 +55,18 @@ export default async function Page(props: { }) { const searchParams = await props.searchParams; - const pageIndex = searchParams.page + const rawPage = searchParams.page ? Number.parseInt( Array.isArray(searchParams.page) ? (searchParams.page[0] ?? '') : searchParams.page, 10, - ) - 1 - : 0; + ) + : 1; + + if (Number.isNaN(rawPage)) notFound(); - if (Number.isNaN(pageIndex)) notFound(); + const pageIndex = rawPage - 1; // 获取文章(带分页) const { posts, totalDocs, totalPages } = await getPublishedPosts({ diff --git a/src/app/(main)/(home)/tags/[...slug]/page.tsx b/src/app/(main)/(home)/tags/[...slug]/page.tsx index 45fa52f..30c6464 100644 --- a/src/app/(main)/(home)/tags/[...slug]/page.tsx +++ b/src/app/(main)/(home)/tags/[...slug]/page.tsx @@ -89,16 +89,18 @@ export default async function Page(props: { const tag = params.slug[0]; if (!tag) return notFound(); - const pageIndex = searchParams.page + const rawPage = searchParams.page ? Number.parseInt( Array.isArray(searchParams.page) ? (searchParams.page[0] ?? '') : searchParams.page, 10, - ) - 1 - : 0; + ) + : 1; + + if (Number.isNaN(rawPage)) notFound(); - if (Number.isNaN(pageIndex)) notFound(); + const pageIndex = rawPage - 1; const { posts, totalDocs, totalPages } = await getPostsByTag(tag, { limit: postsPerPage, |
