fluxel
Version:
An ultra-lightweight, high-performance library for efficient DOM building and dynamic web UIs
23 lines (22 loc) • 697 B
JavaScript
import Fluxel from "../baseReactive.js";
import { globalNavigate } from "./router.js";
export const Link = (props)=>{
if (!props || !props.href) {
throw new Error("Link component requires a 'href' property.");
}
const replace = props.replace || false;
const rest = Object.assign({}, props);
delete rest.replace;
const href = rest.href || "#";
const onclick = rest.onclick ? Array.isArray(rest.onclick) ? rest.onclick : [
rest.onclick
] : [];
onclick.push((event)=>{
event.preventDefault();
globalNavigate(href, {
replace: replace || false
});
});
rest.onclick = onclick;
return Fluxel.a(rest);
};