-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.tsx
More file actions
70 lines (65 loc) · 1.55 KB
/
main.tsx
File metadata and controls
70 lines (65 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { ReportDialog } from '@highlight-run/react'
import * as React from 'react'
import * as ReactDOM from 'react-dom/client'
import {
createBrowserRouter,
createRoutesFromElements,
Route,
RouterProvider,
useRouteError,
} from 'react-router-dom'
import Root from './routes/root'
import Welcome from './routes/welcome'
import PrivacyDemo from './routes/privacy-demo'
import HttpTest from './routes/http-test'
function rootAction() {
const contact = { name: 'hello' }
if (Math.random() < 0.5) {
throw new Response('', {
status: 404,
statusText: 'Not Found',
})
}
return { contact }
}
function rootLoader() {
const contact = { name: 'hello' }
if (Math.random() < 0.5) {
throw new Response('', {
status: 404,
statusText: 'Not Found',
})
}
return { contact }
}
export function ErrorPage() {
const error = useRouteError() as { statusText: string; data: string }
return (
<ReportDialog error={new Error(`${error.statusText}: ${error.data}`)} />
)
}
const router = createBrowserRouter(
createRoutesFromElements(
<>
<Route
path="/"
element={<Root />}
loader={rootLoader}
action={rootAction}
ErrorBoundary={ErrorPage}
>
<Route>
<Route index element={<Root />} />
</Route>
</Route>
<Route path={'/welcome'} element={<Welcome />} />
<Route path={'/privacy'} element={<PrivacyDemo />} />
<Route path={'/http-test'} element={<HttpTest />} />
</>,
),
)
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<RouterProvider router={router} />
</React.StrictMode>,
)