one
Version:
One is a new React Framework that makes Vite serve both native and web.
33 lines (32 loc) • 1.4 kB
JavaScript
import { Platform } from "react-native-web";
import { appendBaseUrl } from "../fork/getPathFromState-mods";
import { stripGroupSegmentsFromPath } from "../router/matchers";
import { useOneRouter } from "../router/router";
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) {
const { linkTo } = useOneRouter(), onPress = (e) => {
const event = props.replace ? "REPLACE" : "PUSH";
let shouldHandle = !1;
if (Platform.OS !== "web" || !e ? shouldHandle = e ? !e.defaultPrevented : !0 : eventShouldPreventDefault(e) && (e.preventDefault(), shouldHandle = !0), shouldHandle) {
const 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.js.map