From ecac227ef0563c7087c8a610ea157e229a819fe7 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Tue, 1 Aug 2023 14:07:39 +0900 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E3=81=98URL=E3=81=A7=E9=81=B7?= =?UTF-8?q?=E7=A7=BB=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=80=80=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=8C?= =?UTF-8?q?=E3=83=AA=E3=82=BB=E3=83=83=E3=83=88=E3=81=95=E3=82=8C=E3=82=8B?= =?UTF-8?q?=E3=82=A4=E3=83=A1=E3=83=BC=E3=82=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SATE_RECEIPT-27 領収証作成時 --- src/contexts/SearchConditionContext.tsx | 2 +- src/hooks/useNavigateCustom.ts | 24 +++++++++++++++++++----- src/hooks/useTable.ts | 4 +++- src/layouts/dashbord/navigator.tsx | 5 ++--- src/routes/index.tsx | 4 ++++ 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/contexts/SearchConditionContext.tsx b/src/contexts/SearchConditionContext.tsx index 98a96bb..5bd5a8c 100644 --- a/src/contexts/SearchConditionContext.tsx +++ b/src/contexts/SearchConditionContext.tsx @@ -99,7 +99,7 @@ export function SearchConditionContextProvider({ children }: Props) { const applyToURL = () => { if (!initialized) return; - navigateWhenChanged(pathname, condition, "applyToURL"); + navigateWhenChanged(pathname, condition, { context: "applyToURL" }); }; const clearCondition = () => { diff --git a/src/hooks/useNavigateCustom.ts b/src/hooks/useNavigateCustom.ts index 0d1b781..5fedc96 100644 --- a/src/hooks/useNavigateCustom.ts +++ b/src/hooks/useNavigateCustom.ts @@ -1,6 +1,7 @@ import { useLocation, useNavigate } from "react-router"; import { Dictionary } from "@types"; import { PageID } from "codes/page"; +import { getPath } from "routes/path"; export default function useNavigateCustom() { const navigate = useNavigate(); @@ -9,7 +10,10 @@ export default function useNavigateCustom() { const navigateWhenChanged = ( path: string, param?: Dictionary | URLSearchParams | string, - context?: any + option?: { + reload?: boolean; + context?: any; + } ) => { const currentUrl = pathname + search; let newPath = path; @@ -34,11 +38,21 @@ export default function useNavigateCustom() { } } - if (currentUrl !== newPath) { - if (context) { - console.log("navigate to", newPath, context); + if (currentUrl !== newPath || option?.reload) { + if (option?.context) { + console.log("navigate to", newPath, option.context); + } + + // 同じURLで遷移要求があった場合、reload設定されていれば同じページを読み込みなおす + // 一旦、空白のページを経由する必要がある + if (currentUrl === newPath && option?.reload) { + navigate(getPath(PageID.NONE)); + setTimeout(() => { + navigate(newPath); + }, 50); + } else { + navigate(newPath); } - navigate(newPath); } }; return { navigate, navigateWhenChanged }; diff --git a/src/hooks/useTable.ts b/src/hooks/useTable.ts index ee2a6c6..1478c25 100644 --- a/src/hooks/useTable.ts +++ b/src/hooks/useTable.ts @@ -134,7 +134,9 @@ export default function useTable(): UseTableReturn { if (requestPage !== newPage) { setRequestPage(newPage); } - navigateWhenChanged(paging(newPage), search, "useTable.paging"); + navigateWhenChanged(paging(newPage), search, { + context: "useTable.paging", + }); } }, [requestPage, maxPage, fetched, page]); diff --git a/src/layouts/dashbord/navigator.tsx b/src/layouts/dashbord/navigator.tsx index 74c0291..7f41496 100644 --- a/src/layouts/dashbord/navigator.tsx +++ b/src/layouts/dashbord/navigator.tsx @@ -247,7 +247,7 @@ function SubGroup({ icon, label, id, children, option }: SubGroup) { const handleClick = () => { if (id) { const path = getPath(id, option); - navigateWhenChanged(path); + navigateWhenChanged(path, undefined, { reload: true }); } }; const selected = id === pageId; @@ -280,8 +280,7 @@ function useContents(children: Child[]) { const handleClick = () => { const path = getPath(id, option); - console.log(path, id, option); - navigateWhenChanged(path); + navigateWhenChanged(path, undefined, { reload: true }); }; return ( diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 3ff435d..cc85d61 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -70,6 +70,10 @@ const DashboardRoutes = (): RouteObject => { const { canAccess } = useAuth(); const allChildren = [ + { + pageId: PageID.NONE, + element: null, + }, { pageId: PageID.DASHBOARD_OVERVIEW, element: ,