From 129697d3423691ede58cd62ae89392403786079a Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Sun, 29 Dec 2024 17:32:20 +0100 Subject: [PATCH] fix(chat): broken navigation highlighting --- .../chat/src/layouts/navigation/links/navigation-item.tsx | 8 +++++--- apps/chat/src/routes/use-sitemap.tsx | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/chat/src/layouts/navigation/links/navigation-item.tsx b/apps/chat/src/layouts/navigation/links/navigation-item.tsx index 1eaf2862..e27b7d47 100644 --- a/apps/chat/src/layouts/navigation/links/navigation-item.tsx +++ b/apps/chat/src/layouts/navigation/links/navigation-item.tsx @@ -3,6 +3,8 @@ import type { PropsWithChildren, ReactNode } from 'react'; import clsx from 'clsx'; import { Link, useLocation } from 'wouter'; +import { prefixWithBaseRoute } from '~/routes/use-sitemap'; + export type NavigationItemProps = PropsWithChildren & { path: string; icon: ReactNode; @@ -12,9 +14,9 @@ export type NavigationItemProps = PropsWithChildren & { export function NavigationItem({ path, icon, children, disabled }: NavigationItemProps) { const [location] = useLocation(); const isActive = ( - path !== '/' - ? location.startsWith(path) - : location === path + path === prefixWithBaseRoute('/') + ? location === path + : location.startsWith(path) ); return ( diff --git a/apps/chat/src/routes/use-sitemap.tsx b/apps/chat/src/routes/use-sitemap.tsx index 2663df5d..34d6ad52 100644 --- a/apps/chat/src/routes/use-sitemap.tsx +++ b/apps/chat/src/routes/use-sitemap.tsx @@ -36,6 +36,6 @@ export function useSitemap() { return sitemap; }; -function prefixWithBaseRoute(path: string) { - return concatUrls(import.meta.env.BASE_URL ?? '/', path); +export function prefixWithBaseRoute(path?: string) { + return concatUrls(import.meta.env.BASE_URL ?? '/', path ?? ''); }