import React from 'react'; import { Navigate, useNavigate } from 'react-router-dom'; import { ErrorBoundary } from '@/components/ErrorBoundary'; import { ProtectedRoute } from '@/components/auth/ProtectedRoute'; import { LazySharedPlaylistPage, LazyLogin, LazyRegister, LazyForgotPassword, LazyVerifyEmail, LazyResetPassword, LazyDashboard, LazyChat, LazyChatJoin, LazyLibrary, LazySettings, LazySessions, LazyNotFound, LazyServerError, LazyUserProfile, LazyRoles, LazyTrackDetail, LazyPlaylistRoutes, LazyMarketplace, LazySearch, LazyNotifications, LazyAnalytics, LazyWebhooks, LazyAdminDashboard, LazyAdminModeration, LazyAdminPlatform, LazyAdminTransfers, LazyDesignSystemDemo, LazySocial, LazyFeed, LazyDiscover, LazySellerDashboard, LazyWishlist, LazyPurchases, LazyProductDetail, LazyCheckoutComplete, LazyQueue, LazyDeveloper, LazyGear, LazyLive, LazyGoLive, LazyListenTogether, LazyCloud, LazySubscription, LazyDistribution, LazyEducation, LazySupport, LazyLanding, LazyDmca, } from '@/components/ui/LazyComponent'; const LazyPrototype = React.lazy(() => import('@/features/prototype/PrototypePage')); import { PublicRoute } from './PublicRoute'; import { ProtectedLayoutRoute } from './ProtectedLayoutRoute'; import { useUser } from '@/features/auth/hooks/useUser'; import type { RouteEntry } from './types'; /** Redirects /profile to /u/ */ function ProfileRedirect() { const { data: user } = useUser(); const navigate = useNavigate(); React.useEffect(() => { if (user?.username) { navigate(`/u/${user.username}`, { replace: true }); } }, [user?.username, navigate]); return null; } function wrapPublic(element: React.ReactNode): React.ReactNode { return ( {element} ); } function wrapProtected(element: React.ReactNode): React.ReactNode { return ( {element} ); } function wrapAdminProtected(element: React.ReactNode): React.ReactNode { return ( {element} ); } export function getPublicRoutes(): RouteEntry[] { return [ { path: '/login', element: wrapPublic() }, { path: '/register', element: wrapPublic() }, { path: '/forgot-password', element: wrapPublic() }, { path: '/verify-email', element: wrapPublic() }, { path: '/reset-password', element: wrapPublic() }, ]; } export function getPublicStandaloneRoutes(): RouteEntry[] { return [ { path: '/launch', element: }, { path: '/design-system', element: }, { path: '/prototype/*', element: }, { path: '/u/:username', element: }, { path: '/playlists/shared/:token', element: }, { path: '/legal/dmca', element: }, ]; } export function getProtectedRoutes(): RouteEntry[] { return [ { path: '/dashboard', element: wrapProtected() }, { path: '/marketplace', element: wrapProtected() }, { path: '/marketplace/products/:id', element: wrapProtected() }, { path: '/sell', element: wrapProtected( {}} />) }, { path: '/wishlist', element: wrapProtected() }, { path: '/purchases', element: wrapProtected() }, { path: '/checkout/complete', element: wrapProtected() }, { path: '/chat/join/:token', element: wrapProtected() }, { path: '/chat', element: wrapProtected() }, { path: '/library', element: wrapProtected() }, { path: '/profile', element: wrapProtected() }, { path: '/settings', element: wrapProtected() }, { path: '/settings/sessions', element: wrapProtected() }, { path: '/admin/roles', element: wrapAdminProtected() }, { path: '/tracks/:id', element: wrapProtected() }, { path: '/playlists/*', element: wrapProtected() }, { path: '/search', element: wrapProtected() }, { path: '/notifications', element: wrapProtected() }, { path: '/analytics', element: wrapProtected() }, { path: '/webhooks', element: wrapProtected() }, { path: '/admin', element: wrapAdminProtected() }, { path: '/admin/moderation', element: wrapAdminProtected() }, { path: '/admin/platform', element: wrapAdminProtected() }, { path: '/admin/transfers', element: wrapAdminProtected() }, { path: '/social', element: wrapProtected() }, { path: '/feed', element: wrapProtected() }, { path: '/discover', element: wrapProtected() }, { path: '/queue', element: wrapProtected() }, { path: '/developer', element: wrapProtected() }, // Gear: connected to backend inventory API { path: '/gear', element: wrapProtected() }, // Live: connected to backend live streams API { path: '/live/go-live', element: wrapProtected() }, { path: '/live', element: wrapProtected() }, // Co-listening (v0.10.7 F481) { path: '/listen-together/:sessionId', element: wrapProtected() }, // Cloud: connected to backend cloud storage API { path: '/cloud', element: wrapProtected() }, // v0.12.1: Subscription Plans & Management { path: '/subscription', element: wrapProtected() }, // v0.12.2: Distribution to External Platforms { path: '/distribution', element: wrapProtected() }, // v0.12.3: Formation & Éducation { path: '/education', element: wrapProtected() }, // v0.13.5 TASK-MKT-004: Support page { path: '/support', element: wrapProtected() }, // Redirect aliases — intuitive URLs that map to actual routes { path: '/tracks', element: }, { path: '/community', element: }, { path: '/favorites', element: }, { path: '/home', element: }, ]; } export function getErrorRoutes(): RouteEntry[] { return [ { path: '/404', element: }, { path: '/500', element: }, ]; }