tutu/src/platform/A.tsx

22 lines
760 B
TypeScript
Raw Normal View History

2024-11-16 14:37:22 +00:00
import { splitProps, type JSX } from "solid-js";
2024-11-16 12:04:55 +00:00
import { useNavigator } from "./StackedRouter";
2024-11-16 14:37:22 +00:00
import { useResolvedPath } from "@solidjs/router";
2024-11-16 12:04:55 +00:00
function handleClick(
push: (name: string, state: unknown) => void,
event: MouseEvent & { currentTarget: HTMLAnchorElement },
) {
const target = event.currentTarget;
event.preventDefault();
push(target.href, { state: target.getAttribute("state") || undefined });
}
2024-11-16 14:37:22 +00:00
const A = (oprops: Omit<JSX.HTMLElementTags["a"], "onClick" | "onclick">) => {
const [props, rest] = splitProps(oprops, ["href"]);
const resolvedPath = useResolvedPath(() => props.href || "#");
2024-11-16 12:04:55 +00:00
const { push } = useNavigator();
2024-11-16 14:37:22 +00:00
return <a onClick={[handleClick, push]} href={resolvedPath()} {...rest}></a>;
2024-11-16 12:04:55 +00:00
};
export default A;