import { lazy, Suspense } from "react"; import LoadingScreen from "../app/LoadingScreen"; import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom"; import { Typography } from "@mui/material"; import { useAuth0 } from "@auth0/auth0-react"; import Teams from "pages/Teams"; import Users from "pages/Users"; import TeamPage from "pages/Team"; import Header from "app/Header"; import Logout from "pages/Logout"; import Devices from "pages/Devices"; import DevicePage from "pages/Device"; import GroupsPage from "pages/Groups"; import GroupPage from "pages/Group"; import { ErrorBoundary } from "react-error-boundary"; import DeviceComponent from "pages/DeviceComponent"; const DeviceHistory = lazy(() => import("pages/DeviceHistory")); interface Props { toggleTheme: () => void; } export const appendToUrl = (appendage: number | string) => { const basePath = location.pathname.replace(/\/$/, ""); return(`${basePath}/${appendage}`); }; export default function Router(props: Props) { const { toggleTheme } = props; const { isAuthenticated, loginWithRedirect, isLoading } = useAuth0(); const RelativeRoutes = () => { return ( } /> } /> } /> ) } const TeamsRoute = () => { return ( } /> } /> } /> ); }; const DevicesRoute = () => { return (
} /> } /> } /> } /> } />
); }; const GroupsRoute = () => { return (
} /> } /> } /> } /> } />
); }; if (isLoading) return null; if (!isAuthenticated) { loginWithRedirect() return ( null ) } function ErrorFallback({ error }: { error: Error }) { return
Something went wrong: {error.stack}
; } return ( }>
{/* Redirects */} } /> {/* } /> */} {/* } /> */} {/* Page routes */} Hello!} /> } /> } /> {/* } /> */} } /> ) }