|
|
|
@@ -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 }; |
|
|
|
|