UNPKG

one

Version:

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

32 lines (31 loc) 1.3 kB
import { Platform } from "react-native"; import { appendBaseUrl } from "../fork/getPathFromState-mods.native.js"; import { stripGroupSegmentsFromPath } from "../router/matchers.native.js"; import { useOneRouter } from "../router/router.native.js"; function eventShouldPreventDefault(e) { return e?.defaultPrevented ? !1 : // Only check MouseEvents !!("button" in e && // ignore clicks with modifier keys !e.metaKey && !e.altKey && !e.ctrlKey && !e.shiftKey && (e.button == null || e.button === 0) && // Only accept left clicks [void 0, null, "", "self"].includes(e.currentTarget.target)); } function useLinkTo(props) { var { linkTo } = useOneRouter(), onPress = function (e) { var event = props.replace ? "REPLACE" : "PUSH", shouldHandle = !1; Platform.OS !== "web" || !e ? shouldHandle = e ? !e.defaultPrevented : !0 : eventShouldPreventDefault(e) && (e.preventDefault(), shouldHandle = !0), shouldHandle && linkTo(props.href, event); }; return { // Ensure there's always a value for href. Manually append the baseUrl to the href prop that shows in the static HTML. href: appendBaseUrl(stripGroupSegmentsFromPath(props.href) || "/"), role: "link", onPress }; } export { useLinkTo }; //# sourceMappingURL=useLinkTo.native.js.map