UNPKG

@smallstack/svelte-ui

Version:

Tiny library for Svelte 5 and DaisyUI, published as multi entry ESM module and as web components.

21 lines (20 loc) 766 B
import { browser } from "$app/environment"; import { afterNavigate } from "$app/navigation"; export function isActiveLink(node, options) { function checkHref(pathname) { if (node.href) { const basePathMatches = new URL(node.href).pathname === pathname; const queryParamsMatch = new URL(node.href).search === location.search; if (basePathMatches && (options.includeQueryParams ? queryParamsMatch : true)) { node.classList.add(options.activeClass); } else node.classList.remove(options.activeClass); } } afterNavigate((navigation) => { checkHref(navigation.to.url.pathname); }); if (browser) checkHref(location.pathname); }