-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathAppRouter.tsx
More file actions
83 lines (75 loc) · 1.89 KB
/
AppRouter.tsx
File metadata and controls
83 lines (75 loc) · 1.89 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
71
72
73
74
75
76
77
78
79
80
81
82
83
import React from 'react'
import { HashRouter, BrowserRouter, Route, Switch, RouteProps } from 'react-router-dom' //
import config from './_config'
import DashboardLayout from '_layouts/DashboardLayout'
import { Auth } from './Auth'
import { Administration } from './Administration'
import { Dashboard } from './Dashboard'
// Use different router type depending on configuration
const AppRouterComponent: React.FC = ({ children }) => {
return config.navigationType === 'history' ? (
<BrowserRouter>{children}</BrowserRouter>
) : (
<HashRouter>{children}</HashRouter>
)
}
const AppRouter: React.FC = () => {
return (
<AppRouterComponent>
<Switch>
<Route path="/auth" component={Auth} />
<RouteWithLayout
exact
path={`/`}
component={Dashboard}
layout={DashboardLayout}
/>
<RouteWithLayout
path={`/administration`}
component={Administration}
layout={DashboardLayout}
/>
<RouteWithLayout
path={`/account`}
component={() => null}
layout={DashboardLayout}
/>
<RouteWithLayout
path={`/settings`}
component={() => null}
layout={DashboardLayout}
/>
</Switch>
</AppRouterComponent>
)
}
export interface RouteWithLayoutProps extends RouteProps {
layout: React.ComponentType<any>
}
const RouteWithLayout: React.FC<RouteWithLayoutProps> = ({
component: Component,
layout: Layout,
children,
...rest
}) => {
return (
<Route
{...rest}
render={(props) => {
if (!Component) return null
if (Layout) {
return (
<Layout>
<Component {...props} />
</Layout>
)
} else {
return <Component {...props} />
}
}}
>
{children}
</Route>
)
}
export default AppRouter