StackedRouter: new router simulates app behaviour #45

Merged
Rubicon merged 18 commits from stacky into master 2024-11-18 10:35:30 +00:00
Showing only changes of commit 5be56bb80e - Show all commits

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;