From f64ada500df8dcb897cf52a961d6af137b147717 Mon Sep 17 00:00:00 2001 From: "alexei.dolgolyov" Date: Sun, 22 Mar 2026 01:28:16 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20nav=20active=20state=20=E2=80=94=20plain?= =?UTF-8?q?=20path=20link=20not=20highlighted=20when=20sibling=20query-par?= =?UTF-8?q?am=20link=20matches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/routes/+layout.svelte | 34 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte index f9e6c91..fd90aa8 100644 --- a/frontend/src/routes/+layout.svelte +++ b/frontend/src/routes/+layout.svelte @@ -192,16 +192,40 @@ } function isActive(href: string): boolean { - if (href.includes('?')) { - const [path, qs] = href.split('?'); - if (page.url.pathname !== path) return false; - const params = new URLSearchParams(qs); + const [hrefPath, hrefQs] = href.split('?'); + if (page.url.pathname !== hrefPath) return false; + + if (hrefQs) { + // Link has query params — all must match + const params = new URLSearchParams(hrefQs); for (const [k, v] of params) { if (page.url.searchParams.get(k) !== v) return false; } return true; } - return page.url.pathname === href; + + // Link has NO query params — only active if URL also has no + // query params that a sibling link would claim + // (e.g. /telegram-bots is not active when URL is /telegram-bots?tab=matrix) + if (page.url.searchParams.size > 0) { + // Check if any sibling nav item matches with those params + for (const entry of navEntries) { + if (isGroup(entry)) { + for (const child of entry.children) { + if (child.href !== href && child.href.startsWith(hrefPath + '?')) { + const sibQs = child.href.split('?')[1]; + const sibParams = new URLSearchParams(sibQs); + let sibMatch = true; + for (const [k, v] of sibParams) { + if (page.url.searchParams.get(k) !== v) { sibMatch = false; break; } + } + if (sibMatch) return false; // a sibling with query params matches better + } + } + } + } + } + return true; }