From 0618b364fc132f528b2fed6cabda1dff4a718d78 Mon Sep 17 00:00:00 2001 From: ryan-crabbe-berri Date: Thu, 23 Jul 2026 13:53:55 -0700 Subject: [PATCH] fix(ui): resolve nested tab routes to their sidebar item legacyKeyForPathname matched the full relative path against a single route segment, so a nested tab route like /router-settings/fallbacks resolved to no key and the shell fell back to the default page, leaving the Router Settings nav item unhighlighted. Match on the first path segment instead, which fixes every migrated page with nested tab routes. --- ui/litellm-dashboard/src/utils/migratedPages.test.ts | 9 +++++++++ ui/litellm-dashboard/src/utils/migratedPages.ts | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ui/litellm-dashboard/src/utils/migratedPages.test.ts b/ui/litellm-dashboard/src/utils/migratedPages.test.ts index 5812c1eec40..99a69cc29bc 100644 --- a/ui/litellm-dashboard/src/utils/migratedPages.test.ts +++ b/ui/litellm-dashboard/src/utils/migratedPages.test.ts @@ -236,4 +236,13 @@ describe("legacyKeyForPathname", () => { expect(legacyKeyForPathname("/team-x/ui/api-reference")).toBe("api_ref"); expect(legacyKeyForPathname("/ui/api-reference")).toBeNull(); }); + + it("resolves a nested tab route to its sidebar key via the first path segment", async () => { + vi.doMock("@/components/networking", () => ({ serverRootPath: "/" })); + const { legacyKeyForPathname } = await import("./migratedPages"); + + expect(legacyKeyForPathname("/ui/router-settings/fallbacks")).toBe("router-settings"); + expect(legacyKeyForPathname("/ui/router-settings/prompt-caching/")).toBe("router-settings"); + expect(legacyKeyForPathname("/ui/some-legacy-page/nested")).toBeNull(); + }); }); diff --git a/ui/litellm-dashboard/src/utils/migratedPages.ts b/ui/litellm-dashboard/src/utils/migratedPages.ts index 73ab71ce4ac..34908a31f65 100644 --- a/ui/litellm-dashboard/src/utils/migratedPages.ts +++ b/ui/litellm-dashboard/src/utils/migratedPages.ts @@ -76,8 +76,10 @@ export function legacyPageHref(pageKey: string): string { export function legacyKeyForPathname(pathname: string): string | null { const base = uiBase(); const rel = (pathname.startsWith(base) ? pathname.slice(base.length) : pathname).replace(/^\/+|\/+$/g, ""); + const firstSegment = rel.split("/")[0] ?? ""; + if (!firstSegment) return null; for (const [key, segment] of Object.entries(MIGRATED_PAGES)) { - if (rel === segment) return key; + if (firstSegment === segment) return key; } return null; }