File tree 1 file changed +27
-11
lines changed
1 file changed +27
-11
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
- import { BrowserRouter as Router , Route , Routes } from 'react-router-dom' ;
2
+ import {
3
+ BrowserRouter as Router ,
4
+ Route ,
5
+ Routes ,
6
+ Navigate ,
7
+ } from 'react-router-dom' ;
8
+ import { useAppContext } from './hooks' ;
3
9
import { GuardianContextProvider } from './context/guardian/GuardianContext' ;
4
10
import { GatewayContextProvider } from './context/gateway/GatewayContext' ;
5
11
import { Guardian } from './guardian-ui/Guardian' ;
@@ -8,28 +14,38 @@ import { Wrapper } from './components/Wrapper';
8
14
import HomePage from './pages/Home' ;
9
15
10
16
export default function App ( ) {
17
+ const { service } = useAppContext ( ) ;
18
+
11
19
return (
12
20
< Router >
13
21
< Routes >
14
22
< Route path = '/' element = { < HomePage /> } />
15
23
< Route
16
24
path = '/guardians/:id'
17
25
element = {
18
- < Wrapper >
19
- < GuardianContextProvider >
20
- < Guardian />
21
- </ GuardianContextProvider >
22
- </ Wrapper >
26
+ service ? (
27
+ < Wrapper >
28
+ < GuardianContextProvider >
29
+ < Guardian />
30
+ </ GuardianContextProvider >
31
+ </ Wrapper >
32
+ ) : (
33
+ < Navigate replace to = '/' />
34
+ )
23
35
}
24
36
/>
25
37
< Route
26
38
path = '/gateways/:id'
27
39
element = {
28
- < Wrapper >
29
- < GatewayContextProvider >
30
- < Gateway />
31
- </ GatewayContextProvider >
32
- </ Wrapper >
40
+ service ? (
41
+ < Wrapper >
42
+ < GatewayContextProvider >
43
+ < Gateway />
44
+ </ GatewayContextProvider >
45
+ </ Wrapper >
46
+ ) : (
47
+ < Navigate replace to = '/' />
48
+ )
33
49
}
34
50
/>
35
51
</ Routes >
You can’t perform that action at this time.
0 commit comments