-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAppRoutes.js
83 lines (79 loc) · 2.42 KB
/
AppRoutes.js
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
// Copyright (c) Cosmo Tech.
// Licensed under the MIT license.
import React from 'react';
import { Navigate, Route, createBrowserRouter, RouterProvider, createRoutesFromElements } from 'react-router-dom';
import { getAllTabs } from './AppLayout';
import { UserStatusGate } from './components/UserStatusGate';
import { TabLayout } from './layouts';
import { RouterUtils } from './utils';
import Workspaces from './views/Workspaces';
const AppRoutes = () => {
const providedUrl = sessionStorage.getItem('providedUrl');
const providedUrlBeforeSignIn = sessionStorage.getItem('providedUrlBeforeSignIn');
const redirectPath = RouterUtils.getLocationRelativePath(providedUrlBeforeSignIn ?? providedUrl ?? '/workspaces');
const tabs = getAllTabs();
const router = createBrowserRouter(
createRoutesFromElements(
<>
<Route path="/" element={<Navigate to={redirectPath} replace />} />
<Route
path="/workspaces"
element={
<UserStatusGate>
<Workspaces />
</UserStatusGate>
}
/>
<Route
path=":workspaceId"
element={
<UserStatusGate>
<Navigate to="scenario" replace />
</UserStatusGate>
}
/>
<Route
element={
<UserStatusGate>
<TabLayout tabs={tabs} />
</UserStatusGate>
}
>
{tabs?.map((tab) => (
<Route
key={tab.key}
path={`:workspaceId/${tab.to}`}
element={<UserStatusGate>{tab.render}</UserStatusGate>}
>
{['scenario', 'instance'].includes(tab.to) && (
<Route path=":scenarioId" element={<UserStatusGate>{tab.render}</UserStatusGate>} />
)}
</Route>
))}
</Route>
<Route
path="/sign-in"
element={
<UserStatusGate>
<Navigate to={redirectPath} />
</UserStatusGate>
}
/>
<Route
path="/accessDenied"
element={
<UserStatusGate>
<Navigate to="/workspaces" />
</UserStatusGate>
}
/>
<Route path="*" element={<Navigate to={'/workspaces'} />} />
</>
),
{
basename: process.env.PUBLIC_URL ?? '',
}
);
return <RouterProvider router={router} />;
};
export default AppRoutes;