This repository was archived by the owner on Apr 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change
1
+ import { useHistory , useLocation } from "react-router-dom" ;
2
+
3
+ export default function BackendRedirect ( ) {
4
+ const location = useLocation ( ) ;
5
+ const history = useHistory ( ) ;
6
+ const urlSearchParams = new URLSearchParams ( location . search ) ;
7
+ const redirected = urlSearchParams . get ( "redirected" ) ;
8
+
9
+ // this param will be visible for the user, even though it is only needed if the fe is not accessed via nginx, but it prevents endless loops
10
+ if ( redirected === "" ) {
11
+ history . push ( "/error404" ) ;
12
+ return null ;
13
+ }
14
+ urlSearchParams . set ( "redirected" , "" ) ;
15
+ history . push ( location . pathname + "?" + urlSearchParams . toString ( ) ) ;
16
+ window . location . reload ( ) ; // leave the spa, to access the apis.
17
+ return null ;
18
+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import Registration from "../pages/User/Registration";
7
7
import FileSystem , { filesBaseUrl } from "../pages/filesytem/Filesystem" ;
8
8
import Profile from "../pages/User/Profile" ;
9
9
import Error400 from "../pages/errors/Error400" ;
10
+ import BackendRedirect from "./BackendRedirect" ;
10
11
11
12
export default function Router ( ) : ReactElement {
12
13
return (
@@ -24,13 +25,7 @@ export default function Router(): ReactElement {
24
25
< Route path = { "/profile" } component = { Profile } />
25
26
< Route path = { "/profile" } component = { Profile } />
26
27
< Route path = { "/error" } component = { Error400 } />
27
- < Route
28
- path = { [ "/data" , "/api" ] }
29
- component = { ( ) => {
30
- window . location . reload ( ) ; // leave the spa, to access the apis. This could cause a endless loop if the nginx is not present
31
- return null ;
32
- } }
33
- />
28
+ < Route path = { [ "/data" , "/api" ] } component = { BackendRedirect } />
34
29
< Route path = { "*" } component = { Error404 } />
35
30
</ Switch >
36
31
) ;
You can’t perform that action at this time.
0 commit comments