-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.jsx
107 lines (102 loc) · 2.53 KB
/
App.jsx
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import {
About,
Cart,
Checkout,
Error,
HomeLayout,
Landing,
Login,
Orders,
Products,
Register,
SingleProduct,
} from './pages';
import { ErrorElement } from './components';
// loaders
import { loader as landingLoader } from './pages/Landing';
import { loader as singleProductLoader } from './pages/SingleProduct';
import { loader as productsLoader } from './pages/Products';
import { loader as checkoutLoader } from './pages/Checkout';
import { loader as ordersLoader } from './pages/Orders';
// actions
import { action as registerAction } from './pages/Register';
import { action as loginAction } from './pages/Login';
import { action as checkoutAction } from './components/CheckoutForm';
import { store } from './store';
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 1000 * 60 * 5,
},
},
});
const router = createBrowserRouter([
{
path: '/',
element: <HomeLayout />,
errorElement: <Error />,
children: [
{
index: true,
element: <Landing />,
errorElement: <ErrorElement />,
loader: landingLoader(queryClient),
},
{
path: 'products',
element: <Products />,
errorElement: <ErrorElement />,
loader: productsLoader(queryClient),
},
{
path: 'products/:id',
element: <SingleProduct />,
errorElement: <ErrorElement />,
loader: singleProductLoader(queryClient),
},
{
path: 'cart',
element: <Cart />,
},
{
path: 'about',
element: <About />,
},
{
path: 'checkout',
element: <Checkout />,
loader: checkoutLoader(store),
action: checkoutAction(store, queryClient),
},
{
path: 'orders',
element: <Orders />,
loader: ordersLoader(store, queryClient),
},
],
},
{
path: '/login',
element: <Login />,
errorElement: <Error />,
action: loginAction(store),
},
{
path: '/register',
element: <Register />,
errorElement: <Error />,
action: registerAction,
},
]);
const App = () => {
return (
<QueryClientProvider client={queryClient}>
<RouterProvider router={router} />
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
);
};
export default App;