UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

27 lines (26 loc) 811 B
import { useRef } from "react"; import { useRouter } from "../hooks.mjs"; import { useFocusEffect } from "../useFocusEffect.mjs"; const redirectsInFlight = /* @__PURE__ */new Set(); function Redirect({ href }) { const router = useRouter(); const hasRedirected = useRef(false); useFocusEffect(() => { if (hasRedirected.current) return; const key = typeof href === "string" ? href : JSON.stringify(href); if (redirectsInFlight.has(key)) return; hasRedirected.current = true; redirectsInFlight.add(key); Promise.resolve(router.replace(href)).catch(error => { hasRedirected.current = false; console.error(error); }).finally(() => { redirectsInFlight.delete(key); }); }, [href]); return null; } export { Redirect }; //# sourceMappingURL=Redirect.mjs.map