A: fix missolved path

This commit is contained in:
thislight 2024-11-16 22:37:22 +08:00
parent e3d9d0c4ba
commit 5be56bb80e
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E

View file

@ -1,5 +1,6 @@
import { type JSX } from "solid-js"; import { splitProps, type JSX } from "solid-js";
import { useNavigator } from "./StackedRouter"; import { useNavigator } from "./StackedRouter";
import { useResolvedPath } from "@solidjs/router";
function handleClick( function handleClick(
push: (name: string, state: unknown) => void, push: (name: string, state: unknown) => void,
@ -7,13 +8,14 @@ function handleClick(
) { ) {
const target = event.currentTarget; const target = event.currentTarget;
event.preventDefault(); event.preventDefault();
event.stopPropagation();
push(target.href, { state: target.getAttribute("state") || undefined }); push(target.href, { state: target.getAttribute("state") || undefined });
} }
const A = (oprops: JSX.HTMLElementTags["a"]) => { const A = (oprops: Omit<JSX.HTMLElementTags["a"], "onClick" | "onclick">) => {
const [props, rest] = splitProps(oprops, ["href"]);
const resolvedPath = useResolvedPath(() => props.href || "#");
const { push } = useNavigator(); const { push } = useNavigator();
return <a onClick={[handleClick, push]} {...oprops}></a>; return <a onClick={[handleClick, push]} href={resolvedPath()} {...rest}></a>;
}; };
export default A; export default A;