11import { useState , useEffect , useCallback } from 'react' ;
22import { useTranslation } from 'react-i18next' ;
3+ import { Route , Switch , Redirect , useLocation } from 'wouter' ;
34import { Sun , Moon , Download , X } from 'lucide-react' ;
45import { AppShell , Sidebar , SidebarItem , SidebarSection } from '@mcpmux/ui' ;
56import { ThemeProvider } from '@/components/ThemeProvider' ;
@@ -19,12 +20,11 @@ import {
1920 useViewSpace ,
2021 useTheme ,
2122 useAnalyticsEnabled ,
22- useActiveNav ,
23- useNavigateTo ,
2423 useSetPendingSettingsSection ,
2524 useIsLoading ,
2625} from '@/stores' ;
27- import { NAV_ZONES , NAV_SETTINGS } from '@/lib/navigation' ;
26+ import { NAV_ZONES , NAV_SETTINGS , navItemFromPath } from '@/lib/navigation' ;
27+ import { useNavigate } from '@/hooks/use-navigate.hook' ;
2828import { spaceAccentColor } from '@/lib/spaceAccent' ;
2929import { DashboardPage } from '@/features/dashboard' ;
3030import { RegistryPage } from '@/features/registry' ;
@@ -101,8 +101,8 @@ function AppContent() {
101101
102102 useDataSync ( ) ;
103103
104- const activeNav = useActiveNav ( ) ;
105- const navigateTo = useNavigateTo ( ) ;
104+ const [ location ] = useLocation ( ) ;
105+ const navigate = useNavigate ( ) ;
106106 const setPendingSettingsSection = useSetPendingSettingsSection ( ) ;
107107 const [ availableUpdate , setAvailableUpdate ] = useState < { version : string } | null > ( null ) ;
108108
@@ -183,8 +183,8 @@ function AppContent() {
183183 useAnalytics ( ) ;
184184
185185 useEffect ( ( ) => {
186- capture ( 'page_viewed' , { page : activeNav } ) ;
187- } , [ activeNav ] ) ;
186+ capture ( 'page_viewed' , { page : navItemFromPath ( location ) } ) ;
187+ } , [ location ] ) ;
188188
189189 const [ gatewayUrl , setGatewayUrl ] = useState < string | null > ( null ) ;
190190 const loadGatewayUrl = useCallback ( async ( ) => {
@@ -234,8 +234,8 @@ function AppContent() {
234234 icon = { < NAV_SETTINGS . icon className = "h-4 w-4" /> }
235235 label = { t ( NAV_SETTINGS . labelKey ) }
236236 hint = { t ( NAV_SETTINGS . hintKey ) }
237- active = { activeNav === NAV_SETTINGS . key }
238- onClick = { ( ) => navigateTo ( NAV_SETTINGS . key ) }
237+ active = { location === NAV_SETTINGS . path }
238+ onClick = { ( ) => navigate ( NAV_SETTINGS . key ) }
239239 data-testid = { NAV_SETTINGS . testId }
240240 />
241241 }
@@ -249,8 +249,8 @@ function AppContent() {
249249 label = { t ( entry . labelKey ) }
250250 hint = { t ( entry . hintKey ) }
251251 title = { entry . labelTitleKey ? t ( entry . labelTitleKey ) : undefined }
252- active = { activeNav === entry . key }
253- onClick = { ( ) => navigateTo ( entry . key ) }
252+ active = { location === entry . path }
253+ onClick = { ( ) => navigate ( entry . key ) }
254254 data-testid = { entry . testId }
255255 />
256256 ) ) }
@@ -264,7 +264,7 @@ function AppContent() {
264264 < div className = "flex items-center gap-4" >
265265 < button
266266 type = "button"
267- onClick = { ( ) => navigateTo ( 'dashboard' ) }
267+ onClick = { ( ) => navigate ( 'dashboard' ) }
268268 className = "flex items-center gap-1.5 transition-colors hover:text-[rgb(var(--foreground))]"
269269 data-testid = "statusbar-gateway"
270270 title = { tDashboard ( 'statusbar.gatewayTitle' ) }
@@ -353,9 +353,8 @@ function AppContent() {
353353 </ span >
354354 < button
355355 onClick = { ( ) => {
356- // Land on (and flash) the Updates section, not the top of Settings.
357356 setPendingSettingsSection ( 'updates' ) ;
358- navigateTo ( 'settings' ) ;
357+ navigate ( 'settings' ) ;
359358 setAvailableUpdate ( null ) ;
360359 } }
361360 className = "font-medium text-blue-500 underline underline-offset-2 hover:text-blue-400"
@@ -374,15 +373,20 @@ function AppContent() {
374373 </ div >
375374 ) }
376375 < StaleBuildBanner />
377- { activeNav === 'dashboard' && < DashboardPage /> }
378- { activeNav === 'registry' && < RegistryPage /> }
379- { activeNav === 'servers' && < ServersPage /> }
380- { activeNav === 'spaces' && < SpacesPage /> }
381- { activeNav === 'featuresets' && < FeatureSetsPage /> }
382- { activeNav === 'workspaces' && < WorkspacesPage /> }
383- { activeNav === 'clients' && < ClientsPage /> }
384- { activeNav === 'builtin-servers' && < BuiltinServersPage /> }
385- { activeNav === 'settings' && < SettingsPage /> }
376+ < Switch >
377+ < Route path = "/" >
378+ < Redirect to = "/dashboard" />
379+ </ Route >
380+ < Route path = "/dashboard" component = { DashboardPage } />
381+ < Route path = "/registry" component = { RegistryPage } />
382+ < Route path = "/servers" component = { ServersPage } />
383+ < Route path = "/spaces" component = { SpacesPage } />
384+ < Route path = "/featuresets" component = { FeatureSetsPage } />
385+ < Route path = "/workspaces" component = { WorkspacesPage } />
386+ < Route path = "/clients" component = { ClientsPage } />
387+ < Route path = "/builtin-servers" component = { BuiltinServersPage } />
388+ < Route path = "/settings" component = { SettingsPage } />
389+ </ Switch >
386390 </ div >
387391 </ AppShell >
388392 ) ;
0 commit comments