import { createBrowserRouter, Navigate, useParams } from 'react-router';
import { ProtectedRoute } from './auth/ProtectedRoute';
import { LoginPage } from './auth/LoginPage';
import { OidcCallback } from './auth/OidcCallback';
import { LayoutShell } from './components/LayoutShell';
import { lazy, Suspense } from 'react';
import { Spinner } from '@cameleer/design-system';
const ExchangesPage = lazy(() => import('./pages/Exchanges/ExchangesPage'));
const DashboardPage = lazy(() => import('./pages/DashboardTab/DashboardPage'));
const RuntimePage = lazy(() => import('./pages/RuntimeTab/RuntimePage'));
const AdminLayout = lazy(() => import('./pages/Admin/AdminLayout'));
const RbacPage = lazy(() => import('./pages/Admin/RbacPage'));
const AuditLogPage = lazy(() => import('./pages/Admin/AuditLogPage'));
const OidcConfigPage = lazy(() => import('./pages/Admin/OidcConfigPage'));
const DatabaseAdminPage = lazy(() => import('./pages/Admin/DatabaseAdminPage'));
const ClickHouseAdminPage = lazy(() => import('./pages/Admin/ClickHouseAdminPage'));
const AppConfigPage = lazy(() => import('./pages/Admin/AppConfigPage'));
const LogsPage = lazy(() => import('./pages/LogsTab/LogsPage'));
const SwaggerPage = lazy(() => import('./pages/Swagger/SwaggerPage'));
function SuspenseWrapper({ children }: { children: React.ReactNode }) {
return (
}>
{children}
);
}
/** Redirect legacy /apps/:appId/:routeId paths to /exchanges/:appId/:routeId */
function LegacyAppRedirect() {
const { appId, routeId } = useParams<{ appId: string; routeId?: string }>();
const path = routeId ? `/exchanges/${appId}/${routeId}` : `/exchanges/${appId}`;
return ;
}
/** Redirect legacy /agents/:appId/:instanceId paths to /runtime/:appId/:instanceId */
function LegacyAgentRedirect() {
const { appId, instanceId } = useParams<{ appId: string; instanceId?: string }>();
const path = instanceId ? `/runtime/${appId}/${instanceId}` : `/runtime/${appId}`;
return ;
}
export const router = createBrowserRouter([
{ path: '/login', element: },
{ path: '/oidc/callback', element: },
{
element: ,
children: [
{
element: ,
children: [
// Default redirect
{ index: true, element: },
// Exchanges tab
{ path: 'exchanges', element: },
{ path: 'exchanges/:appId', element: },
{ path: 'exchanges/:appId/:routeId', element: },
{ path: 'exchanges/:appId/:routeId/:exchangeId', element: },
// Dashboard tab
{ path: 'dashboard', element: },
{ path: 'dashboard/:appId', element: },
{ path: 'dashboard/:appId/:routeId', element: },
// Runtime tab
{ path: 'runtime', element: },
{ path: 'runtime/:appId', element: },
{ path: 'runtime/:appId/:instanceId', element: },
// Logs tab
{ path: 'logs', element: },
{ path: 'logs/:appId', element: },
{ path: 'logs/:appId/:routeId', element: },
// Legacy redirects — Sidebar uses hardcoded /apps/... and /agents/... paths
{ path: 'apps', element: },
{ path: 'apps/:appId', element: },
{ path: 'apps/:appId/:routeId', element: },
{ path: 'agents', element: },
{ path: 'agents/:appId', element: },
{ path: 'agents/:appId/:instanceId', element: },
// Admin (unchanged)
{
path: 'admin',
element: ,
children: [
{ index: true, element: },
{ path: 'rbac', element: },
{ path: 'audit', element: },
{ path: 'oidc', element: },
{ path: 'appconfig', element: },
{ path: 'database', element: },
{ path: 'clickhouse', element: },
],
},
{ path: 'api-docs', element: },
],
},
],
},
]);