From bb8f0647a6b33dc2805f58dcb85a4c4abd0b0336 Mon Sep 17 00:00:00 2001 From: "haitao(lj)" Date: Wed, 28 Sep 2022 15:52:42 +0800 Subject: [PATCH] fix: #943 --- ui/src/components/Pagination/index.tsx | 12 ++++++++---- ui/src/components/Questions/index.tsx | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ui/src/components/Pagination/index.tsx b/ui/src/components/Pagination/index.tsx index 7e4169d0..2ae10b35 100644 --- a/ui/src/components/Pagination/index.tsx +++ b/ui/src/components/Pagination/index.tsx @@ -1,12 +1,13 @@ import { FC, memo } from 'react'; import { Pagination } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; -import { useSearchParams, useNavigate } from 'react-router-dom'; +import { useSearchParams, useNavigate, useLocation } from 'react-router-dom'; interface Props { currentPage: number; pageSize: number; totalSize: number; + pathname?: string; } interface PageItemProps { @@ -58,9 +59,13 @@ const Index: FC = ({ currentPage = 1, pageSize = 15, totalSize = 0, + pathname = '', }) => { const { t } = useTranslation('translation', { keyPrefix: 'pagination' }); - + const location = useLocation(); + if (!pathname) { + pathname = location.pathname; + } const [searchParams] = useSearchParams(); const navigate = useNavigate(); const totalPage = Math.ceil(totalSize / pageSize); @@ -73,10 +78,9 @@ const Index: FC = ({ } const handleParams = (pageNum): string => { - const basePath = window.location.pathname; searchParams.set('page', String(pageNum)); const searchStr = searchParams.toString(); - return `${basePath}?${searchStr}`; + return `${pathname}?${searchStr}`; }; return ( diff --git a/ui/src/components/Questions/index.tsx b/ui/src/components/Questions/index.tsx index 07853768..200ede4c 100644 --- a/ui/src/components/Questions/index.tsx +++ b/ui/src/components/Questions/index.tsx @@ -187,6 +187,7 @@ const QuestionList: FC = ({ source }) => { currentPage={curPage} totalSize={count} pageSize={pageSize} + pathname="/questions" />