From 5764f6022fa87d090f5c5b1f8268df776b528bbb Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Mon, 13 Oct 2025 23:35:42 +0000 Subject: [PATCH] Add routing-derived activeTab logic cgen-0f9520b9fb2144a38517062cc599cbf0 --- client/pages/Community.tsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/client/pages/Community.tsx b/client/pages/Community.tsx index f733d734..9f5675e9 100644 --- a/client/pages/Community.tsx +++ b/client/pages/Community.tsx @@ -1192,6 +1192,30 @@ export default function Community() { { id: "cta", label: "Join Us" }, ]; + const navigate = useNavigate(); + const location = useLocation(); + const pathSegments = location.pathname.split("/").filter(Boolean); + const candidateTab = pathSegments[1]; + const defaultTab = communityTabItems[0]?.id ?? "new-members"; + + const isValidTab = (value: string | undefined): value is string => + communityTabItems.some((tab) => tab.id === value); + + const activeTab = isValidTab(candidateTab) ? candidateTab : defaultTab; + + useEffect(() => { + if (!isValidTab(candidateTab)) { + navigate(`/community/${defaultTab}`, { replace: true }); + } + }, [candidateTab, defaultTab, navigate]); + + const handleTabChange = (value: string) => { + const nextTab = isValidTab(value) ? value : defaultTab; + if (nextTab !== candidateTab) { + navigate(`/community/${nextTab}`); + } + }; + const devConnectHighlights = [ { title: "Unified Developer Profiles",