The anchor element to handle.
export const active = (node: HTMLAnchorElement, options: Pick<RouteOptions, "active"> = {}) => {
let url = urls.parse(node.href);
const apply = () => {
applyActiveClass(url, options, node);
};
apply();
window.addEventListener("pushState", apply);
return {
destroy() {
window.removeEventListener("pushState", apply);
}
};
};
Add the
active
class to the node if the current route matches the node's href.Add
use:active
to an anchor element to manage active state.