Merge pull request #1034 from tangly1024/fix/pagination-simple-for-matery-next

修复分页组件bug
This commit is contained in:
tangly1024
2023-05-06 12:51:59 +08:00
committed by GitHub
5 changed files with 12 additions and 11 deletions

View File

@@ -47,7 +47,7 @@ const PaginationSimple = ({ page, showNext }) => {
{locale.PAGINATION.NEXT}
</Link>
</div>
);
)
}
export default PaginationSimple

View File

@@ -47,7 +47,7 @@ const PaginationNumber = ({ page, totalPage }) => {
</Link>
</div>
);
)
}
function getPageElement(page, currentPage, pagePrefix) {
@@ -66,7 +66,7 @@ function getPageElement(page, currentPage, pagePrefix) {
{page}
</Link>)
);
)
}
function generatePages(pagePrefix, page, currentPage, totalPage) {

View File

@@ -1,4 +1,3 @@
import BLOG from '@/blog.config'
import Link from 'next/link'
import { useRouter } from 'next/router'
@@ -13,6 +12,7 @@ const PaginationSimple = ({ page, totalPage }) => {
const router = useRouter()
const currentPage = +page
const showNext = currentPage < totalPage
const pagePrefix = router.asPath.replace(/\/page\/[1-9]\d*/, '').replace(/\/$/, '')
return (
<div className="my-10 mx-6 flex justify-between font-medium text-black dark:text-gray-100 space-x-2">
@@ -20,8 +20,8 @@ const PaginationSimple = ({ page, totalPage }) => {
href={{
pathname:
currentPage - 1 === 1
? `${BLOG.SUB_PATH || '/'}`
: `/page/${currentPage - 1}`,
? `${pagePrefix}/`
: `${pagePrefix}/page/${currentPage - 1}`,
query: router.query.s ? { s: router.query.s } : {}
}}
passHref
@@ -36,7 +36,7 @@ const PaginationSimple = ({ page, totalPage }) => {
</Link>
<Link
href={{
pathname: `/page/${currentPage + 1}`,
pathname: `${pagePrefix}/page/${currentPage + 1}`,
query: router.query.s ? { s: router.query.s } : {}
}}
passHref

View File

@@ -48,7 +48,7 @@ const PaginationSimple = ({ page, totalPage }) => {
{locale.PAGINATION.NEXT}
</Link>
</div>
);
)
}
export default PaginationSimple

View File

@@ -1,4 +1,3 @@
import BLOG from '@/blog.config'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useGlobal } from '@/lib/global'
@@ -14,6 +13,8 @@ const PaginationSimple = ({ page, showNext }) => {
const { locale } = useGlobal()
const router = useRouter()
const currentPage = +page
const pagePrefix = router.asPath.replace(/\/page\/[1-9]\d*/, '').replace(/\/$/, '')
return (
<div
data-aos="fade-down"
@@ -25,8 +26,8 @@ const PaginationSimple = ({ page, showNext }) => {
href={{
pathname:
currentPage - 1 === 1
? `${BLOG.SUB_PATH || '/'}`
: `/page/${currentPage - 1}`,
? `${pagePrefix}/`
: `${pagePrefix}/page/${currentPage - 1}`,
query: router.query.s ? { s: router.query.s } : {}
}}
passHref