From e61815a64a8a739a0b644b36e552c78de8a8467d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kiner-tang=28=E6=96=87=E8=BE=89=29?= <1127031143@qq.com> Date: Sat, 16 Sep 2023 08:02:37 +0800 Subject: [PATCH] fix: solve search-list tab route work unexpected issue. --- src/pages/list/search/index.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/list/search/index.tsx b/src/pages/list/search/index.tsx index 3d2e04a1..a7adec8a 100644 --- a/src/pages/list/search/index.tsx +++ b/src/pages/list/search/index.tsx @@ -26,7 +26,7 @@ const Search: FC = () => { const location = useLocation(); let match = useMatch(location.pathname); const handleTabChange = (key: string) => { - const url = match?.pathname === '/' ? '' : match?.pathname; + const url = match?.pathname === '/' ? '' : match?.pathname.substring(0, match.pathname.lastIndexOf('/')); switch (key) { case 'articles': history.push(`${url}/articles`); @@ -48,8 +48,7 @@ const Search: FC = () => { }; const getTabKey = () => { - const url = match?.pathname === '/' ? '' : match?.pathname; - const tabKey = location.pathname.replace(`${url}/`, ''); + const tabKey = location.pathname.substring(location.pathname.lastIndexOf('/') + 1); if (tabKey && tabKey !== '/') { return tabKey; }