Вот я написал:
Код: Выделить всё
import { useEffect } from "react"
import { useBlocker } from "react-router-dom"
const useBrowserActions = (props: TProps) =\> {
const { getBlock, onBlockedState, showWaring } = props
const { state, proceed, reset } = useBlocker(({ currentLocation, nextLocation }) =\>
getBlock(currentLocation?.pathname, nextLocation?.pathname)
)
useEffect(() => {
if (state === "blocked") onBlockedState()
}, [state])
useEffect(() => {
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
if (!showWaring) return
e.preventDefault()
e.returnValue = ""
return ""
}
window.addEventListener("beforeunload", handleBeforeUnload)
return () => window.removeEventListener("beforeunload", handleBeforeUnload)
}, [showWaring])
return { proceed, reset, state }
}
export default useBrowserActions
type TProps = {
getBlock: (currentLocation: string, nextLocation: string) =\> boolean
onBlockedState: () =\> void | Promise\
showWaring?: boolean
}
Если кто-то сталкивался с этой проблемой в Firefox и знает решение, помогите!
Подробнее здесь: https://stackoverflow.com/questions/797 ... er-refresh
Мобильная версия