Add the active class to the node if the current route matches the node's href.
active
Similar to route
Add use:active to an anchor element to manage active state.
use:active
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); } };}; Copy
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); } };};
The anchor element to handle.
Add the
active
class to the node if the current route matches the node's href.Similar to route
Add
use:active
to an anchor element to manage active state.Source