mirror of https://gitee.com/answerdev/answer.git
fix: #943
This commit is contained in:
parent
b5f923a79f
commit
bb8f0647a6
|
@ -1,12 +1,13 @@
|
||||||
import { FC, memo } from 'react';
|
import { FC, memo } from 'react';
|
||||||
import { Pagination } from 'react-bootstrap';
|
import { Pagination } from 'react-bootstrap';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useSearchParams, useNavigate } from 'react-router-dom';
|
import { useSearchParams, useNavigate, useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
totalSize: number;
|
totalSize: number;
|
||||||
|
pathname?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PageItemProps {
|
interface PageItemProps {
|
||||||
|
@ -58,9 +59,13 @@ const Index: FC<Props> = ({
|
||||||
currentPage = 1,
|
currentPage = 1,
|
||||||
pageSize = 15,
|
pageSize = 15,
|
||||||
totalSize = 0,
|
totalSize = 0,
|
||||||
|
pathname = '',
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation('translation', { keyPrefix: 'pagination' });
|
const { t } = useTranslation('translation', { keyPrefix: 'pagination' });
|
||||||
|
const location = useLocation();
|
||||||
|
if (!pathname) {
|
||||||
|
pathname = location.pathname;
|
||||||
|
}
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const totalPage = Math.ceil(totalSize / pageSize);
|
const totalPage = Math.ceil(totalSize / pageSize);
|
||||||
|
@ -73,10 +78,9 @@ const Index: FC<Props> = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleParams = (pageNum): string => {
|
const handleParams = (pageNum): string => {
|
||||||
const basePath = window.location.pathname;
|
|
||||||
searchParams.set('page', String(pageNum));
|
searchParams.set('page', String(pageNum));
|
||||||
const searchStr = searchParams.toString();
|
const searchStr = searchParams.toString();
|
||||||
return `${basePath}?${searchStr}`;
|
return `${pathname}?${searchStr}`;
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Pagination size="sm" className="d-inline-flex mb-0">
|
<Pagination size="sm" className="d-inline-flex mb-0">
|
||||||
|
|
|
@ -187,6 +187,7 @@ const QuestionList: FC<Props> = ({ source }) => {
|
||||||
currentPage={curPage}
|
currentPage={curPage}
|
||||||
totalSize={count}
|
totalSize={count}
|
||||||
pageSize={pageSize}
|
pageSize={pageSize}
|
||||||
|
pathname="/questions"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue