-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.tsx
47 lines (42 loc) · 1.17 KB
/
index.tsx
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
import React from 'react'
import ReactDOM from 'react-dom/client'
import {
createHashRouter,
RouterProvider
} from 'react-router-dom'
import { AppProvider, LocalizationProvider } from './Components/index'
import { ErrorPage, Root, Swap } from './routes/index'
import './index.css'
// Create a router instance with defined routes
const router = createHashRouter([
{
path: '/',
element: <Root />,
errorElement: <ErrorPage />,
},
{
path: '/ccy/:instId',
element: <Swap />,
errorElement: <ErrorPage />,
}
])
// Configure the BackButton behavior
const BackButton = (window as any).Telegram.WebApp.BackButton
BackButton.onClick(() => window.history.length > 1
? router.navigate(-1)
: router.navigate('/')
)
router.subscribe((state) => {
const isRoot = state.matches.at(0)?.pathname === '/'
isRoot ? BackButton.hide() : BackButton.show()
})
// Render the router within the application's root element
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<AppProvider>
<LocalizationProvider>
<RouterProvider router={router} />
</LocalizationProvider>
</AppProvider>
</React.StrictMode>
)