11import { FC , useCallback , useContext , useEffect } from 'react' ;
2- import { Redirect , Switch } from 'react-router' ;
3- import { Route , useHistory , useLocation } from 'react-router-dom' ;
2+ import { Navigate , Routes , Route , useNavigate , useLocation } from 'react-router-dom' ;
43import { AxiosError } from 'axios' ;
54
5+ import { FeaturesContext } from './contexts/features' ;
66import * as AuthenticationApi from './api/authentication' ;
77import { PROJECT_PATH } from './api/env' ;
88import { AXIOS } from './api/endpoints' ;
9- import { AdminRoute , Layout } from './components' ;
10- import { FeaturesContext } from './contexts/features' ;
9+ import { Layout , RequireAdmin } from './components' ;
1110
1211import ProjectRouting from './project/ProjectRouting' ;
12+
1313import WiFiConnection from './framework/wifi/WiFiConnection' ;
1414import AccessPoint from './framework/ap/AccessPoint' ;
1515import NetworkTime from './framework/ntp/NetworkTime' ;
1616import Mqtt from './framework/mqtt/Mqtt' ;
17- import Security from './framework/security/Security' ;
1817import System from './framework/system/System' ;
18+ import Security from './framework/security/Security' ;
1919
2020const AuthenticatedRouting : FC = ( ) => {
21-
2221 const { features } = useContext ( FeaturesContext ) ;
2322 const location = useLocation ( ) ;
24- const history = useHistory ( ) ;
23+ const navigate = useNavigate ( ) ;
2524
2625 const handleApiResponseError = useCallback ( ( error : AxiosError ) => {
2726 if ( error . response && error . response . status === 401 ) {
2827 AuthenticationApi . storeLoginRedirect ( location ) ;
29- history . push ( "/unauthorized" ) ;
28+ navigate ( "/unauthorized" ) ;
3029 }
3130 return Promise . reject ( error ) ;
32- } , [ location , history ] ) ;
31+ } , [ location , navigate ] ) ;
3332
3433 useEffect ( ( ) => {
3534 const axiosHandlerId = AXIOS . interceptors . response . use ( ( response ) => response , handleApiResponseError ) ;
@@ -38,38 +37,31 @@ const AuthenticatedRouting: FC = () => {
3837
3938 return (
4039 < Layout >
41- < Switch >
40+ < Routes >
4241 { features . project && (
43- < Route path = { `/${ PROJECT_PATH } ` } >
44- < ProjectRouting />
45- </ Route >
42+ < Route path = { `/${ PROJECT_PATH } /*` } element = { < ProjectRouting /> } />
4643 ) }
47- < Route path = "/wifi" >
48- < WiFiConnection />
49- </ Route >
50- < Route path = "/ap" >
51- < AccessPoint />
52- </ Route >
44+ < Route path = "/wifi/*" element = { < WiFiConnection /> } />
45+ < Route path = "/ap/*" element = { < AccessPoint /> } />
5346 { features . ntp && (
54- < Route path = "/ntp" >
55- < NetworkTime />
56- </ Route >
47+ < Route path = "/ntp/*" element = { < NetworkTime /> } />
5748 ) }
5849 { features . mqtt && (
59- < Route path = "/mqtt" >
60- < Mqtt />
61- </ Route >
50+ < Route path = "/mqtt/*" element = { < Mqtt /> } />
6251 ) }
6352 { features . security && (
64- < AdminRoute path = "/security" >
65- < Security />
66- </ AdminRoute >
53+ < Route
54+ path = "/security/*"
55+ element = {
56+ < RequireAdmin >
57+ < Security />
58+ </ RequireAdmin >
59+ }
60+ />
6761 ) }
68- < Route path = "/system" >
69- < System />
70- </ Route >
71- < Redirect to = { AuthenticationApi . getDefaultRoute ( features ) } />
72- </ Switch >
62+ < Route path = "/system/*" element = { < System /> } />
63+ < Route path = "/*" element = { < Navigate to = { AuthenticationApi . getDefaultRoute ( features ) } /> } />
64+ </ Routes >
7365 </ Layout >
7466 ) ;
7567} ;
0 commit comments