File tree Expand file tree Collapse file tree 2 files changed +38
-13
lines changed Expand file tree Collapse file tree 2 files changed +38
-13
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,14 @@ declare global {
21
21
22
22
const buildAPIUrl = ( env : Environment ) : string => {
23
23
if ( ! env . isDev ) {
24
- return `${ document . location . origin } /api/` ;
24
+ const fallbackAPIUrl = `${ document . location . origin } /api/` ;
25
+ try {
26
+ const base = document . querySelector ( 'base' ) ?. href ;
27
+ if ( base != null ) return new URL ( 'api/' , base ) . href ;
28
+ } catch ( e ) {
29
+ console . error ( 'Failed to determine API path' , e ) ;
30
+ }
31
+ return fallbackAPIUrl ;
25
32
}
26
33
27
34
// NOTE: Do not edit those `process.env.VAR_NAME` variable accesses
Original file line number Diff line number Diff line change @@ -10,21 +10,39 @@ export type Props = {
10
10
RootComponent : JSX . Element ;
11
11
} ;
12
12
13
+ const pathname = ( href : string | undefined ) => {
14
+ if ( href == null ) return undefined ;
15
+ try {
16
+ return new URL ( href ) . pathname ;
17
+ } catch ( e ) {
18
+ console . error ( 'Failed to determine base path' , e ) ;
19
+ return undefined ;
20
+ }
21
+ } ;
22
+
13
23
export const Routes = function Routes ( props : Props ) {
14
24
const createRouter = props . router . isInMemory ? createMemoryRouter : createBrowserRouter ;
25
+ const opts = props . router . isInMemory
26
+ ? undefined
27
+ : {
28
+ basename : pathname ( document . querySelector ( 'base' ) ?. href ) ,
29
+ } ;
15
30
16
- const router = createRouter ( [
17
- {
18
- path : '/' ,
19
- element : props . RootComponent ,
20
- children : [
21
- {
22
- path : ApplicationPath . ServiceMap ,
23
- element : < ServiceMapApp /> ,
24
- } ,
25
- ] ,
26
- } ,
27
- ] ) ;
31
+ const router = createRouter (
32
+ [
33
+ {
34
+ path : '/' ,
35
+ element : props . RootComponent ,
36
+ children : [
37
+ {
38
+ path : ApplicationPath . ServiceMap ,
39
+ element : < ServiceMapApp /> ,
40
+ } ,
41
+ ] ,
42
+ } ,
43
+ ] ,
44
+ opts ,
45
+ ) ;
28
46
29
47
return < RouterProvider router = { router } /> ;
30
48
} ;
You can’t perform that action at this time.
0 commit comments