import React from 'react'; import { Outlet, Route, createBrowserRouter, createHashRouter, createRoutesFromElements, redirect, } from 'react-router-dom'; import { ClientConfig } from '../hooks/useClientConfig'; import { AuthLayout, Login, Register, ResetPassword } from './auth'; import { DIRECT_PATH, EXPLORE_PATH, HOME_PATH, LOGIN_PATH, INBOX_PATH, REGISTER_PATH, RESET_PASSWORD_PATH, SPACE_PATH, _CREATE_PATH, _FEATURED_PATH, _INVITES_PATH, _JOIN_PATH, _LOBBY_PATH, _NOTIFICATIONS_PATH, _ROOM_PATH, _SEARCH_PATH, _SERVER_PATH, } from './paths'; import { isAuthenticated } from '../../client/state/auth'; import { getAppPathFromHref, getExploreFeaturedPath, getHomePath, getInboxNotificationsPath, getLoginPath, getOriginBaseUrl, getSpaceLobbyPath, } from './pathUtils'; import { ClientBindAtoms, ClientLayout, ClientRoot } from './client'; import { Home, HomeRouteRoomProvider, HomeSearch } from './client/home'; import { Direct, DirectCreate, DirectRouteRoomProvider } from './client/direct'; import { RouteSpaceProvider, Space, SpaceRouteRoomProvider, SpaceSearch } from './client/space'; import { Explore, FeaturedRooms, PublicRooms } from './client/explore'; import { Notifications, Inbox, Invites } from './client/inbox'; import { setAfterLoginRedirectPath } from './afterLoginRedirectPath'; import { Room } from '../features/room'; import { Lobby } from '../features/lobby'; import { WelcomePage } from './client/WelcomePage'; import { SidebarNav } from './client/SidebarNav'; import { PageRoot } from '../components/page'; import { ScreenSize } from '../hooks/useScreenSize'; import { MobileFriendlyPageNav, MobileFriendlyClientNav } from './MobileFriendly'; import { ClientInitStorageAtom } from './client/ClientInitStorageAtom'; import { ClientNonUIFeatures } from './client/ClientNonUIFeatures'; import { AuthRouteThemeManager, UnAuthRouteThemeManager } from './ThemeManager'; import { ReceiveSelfDeviceVerification } from '../components/DeviceVerification'; import { AutoRestoreBackupOnVerification } from '../components/BackupRestore'; export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize) => { const { hashRouter } = clientConfig; const mobile = screenSize === ScreenSize.Mobile; const routes = createRoutesFromElements( { if (isAuthenticated()) return redirect(getHomePath()); const afterLoginPath = getAppPathFromHref(getOriginBaseUrl(), window.location.href); if (afterLoginPath) setAfterLoginRedirectPath(afterLoginPath); return redirect(getLoginPath()); }} /> { if (isAuthenticated()) { return redirect(getHomePath()); } return null; }} element={ <> } > } /> } /> } /> { if (!isAuthenticated()) { const afterLoginPath = getAppPathFromHref( getOriginBaseUrl(hashRouter), window.location.href ); if (afterLoginPath) setAfterLoginRedirectPath(afterLoginPath); return redirect(getLoginPath()); } return null; }} element={ <> } > } > } > } > {mobile ? null : } />} create

} /> join

} /> } /> } /> } > } > {mobile ? null : } />} } /> } /> } > } > {mobile ? null : ( { const { spaceIdOrAlias } = params; if (spaceIdOrAlias) { return redirect(getSpaceLobbyPath(spaceIdOrAlias)); } return null; }} element={} /> )} } /> } /> } /> } > } > {mobile ? null : ( redirect(getExploreFeaturedPath())} element={} /> )} } /> } /> } > } > {mobile ? null : ( redirect(getInboxNotificationsPath())} element={} /> )} } /> } /> Page not found

} />
); if (hashRouter?.enabled) { return createHashRouter(routes, { basename: hashRouter.basename }); } return createBrowserRouter(routes, { basename: import.meta.env.BASE_URL, }); };