put error boundary around the group page
This commit is contained in:
parent
a64f091aed
commit
d7dc1fa417
4 changed files with 35 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
import App from './App'
|
||||
|
||||
// I don't consider providing a disabled button to a Tooltip an error.
|
||||
// console.error = (message) => {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ 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";
|
||||
|
||||
interface Props {
|
||||
toggleTheme: () => void;
|
||||
|
|
@ -78,6 +79,11 @@ export default function Router(props: Props) {
|
|||
);
|
||||
};
|
||||
|
||||
|
||||
<ErrorBoundary FallbackComponent={ErrorFallback}>
|
||||
<Route path="*" element={<RelativeRoutes/>} />
|
||||
</ErrorBoundary>
|
||||
|
||||
const GroupsRoute = () => {
|
||||
return (
|
||||
<div>
|
||||
|
|
@ -88,7 +94,11 @@ export default function Router(props: Props) {
|
|||
/>
|
||||
<Route
|
||||
path="/:groupID"
|
||||
element={<GroupPage />}
|
||||
element={
|
||||
<ErrorBoundary FallbackComponent={ErrorFallback}>
|
||||
<GroupPage />
|
||||
</ErrorBoundary>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
key="Devices page route"
|
||||
|
|
@ -116,6 +126,10 @@ export default function Router(props: Props) {
|
|||
)
|
||||
}
|
||||
|
||||
function ErrorFallback({ error }: { error: Error }) {
|
||||
return <div>Something went wrong: {error.message}</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Suspense fallback={<LoadingScreen />}>
|
||||
<BrowserRouter>
|
||||
|
|
@ -135,6 +149,11 @@ export default function Router(props: Props) {
|
|||
<Route index element={<Typography>Hello!</Typography>} />
|
||||
<Route path="users" element={<Users/>} />
|
||||
<Route path="/logout" element={<Logout />} />
|
||||
{/*
|
||||
<ErrorBoundary FallbackComponent={ErrorFallback}>
|
||||
<Route path="*" element={<RelativeRoutes/>} />
|
||||
</ErrorBoundary> */}
|
||||
|
||||
<Route path="*" element={<RelativeRoutes/>} />
|
||||
|
||||
</Routes>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue