forked from module-federation/module-federation-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShell.js
More file actions
56 lines (51 loc) · 1.61 KB
/
Shell.js
File metadata and controls
56 lines (51 loc) · 1.61 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
import React from "react";
import { Box } from "@material-ui/core";
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
import AppDrawer from "./AppDrawer";
import AppBar from "./AppBar";
import Viewport from "./Viewport";
import { useLocalStorageSync } from "./useLocalStorageSync";
import { ServiceProvider } from "./Service";
const DashboardService = React.lazy(() => import("dashboard/DashboardService"));
const OrderService = React.lazy(() => import("order/OrderService"));
const ProfilePage = React.lazy(() => import("profile/ProfilePage"));
function useDrawer() {
const { value, setItem } = useLocalStorageSync(
"@shared-routing/appdrawer/open"
);
return {
open: value,
closeDrawer() {
setItem(false);
},
openDrawer() {
setItem(true);
},
};
}
export default function Shell() {
const drawer = useDrawer();
return (
<ServiceProvider>
<BrowserRouter>
<Viewport>
<Box display="flex" flex={1}>
<AppBar drawer={drawer} />
<AppDrawer drawer={drawer} />
<React.Suspense fallback={"Loading"}>
<Routes>
<Route path="dashboard/*" element={<DashboardService />} />
<Route path="orders/*" element={<OrderService />} />
<Route path="profile/*" element={<ProfilePage />} />
<Route
path="*"
element={<Navigate to="/dashboard" replace />}
/>
</Routes>
</React.Suspense>
</Box>
</Viewport>
</BrowserRouter>
</ServiceProvider>
);
}