one
Version:
One is a new React Framework that makes Vite serve both native and web.
40 lines (39 loc) • 1.49 kB
JavaScript
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;
if (Platform.OS !== "web" || !e ? shouldHandle = e ? !e.defaultPrevented : !0 : eventShouldPreventDefault(e) && (e.preventDefault(), shouldHandle = !0), shouldHandle) {
var options = props.mask ? {
mask: {
href: props.mask
}
} : void 0;
linkTo(props.href, event, options);
}
},
displayHref = props.mask || props.href;
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(displayHref) || "/"),
role: "link",
onPress
};
}
export { useLinkTo };
//# sourceMappingURL=useLinkTo.native.js.map