1
1
import { Page , PageProps , PageResolver , router , setupProgress } from '@inertiajs/core'
2
2
import { ComponentType , FunctionComponent , Key , ReactElement , ReactNode , createElement } from 'react'
3
3
import { renderToString } from 'react-dom/server'
4
+ import { AxiosInstance } from 'axios'
4
5
import App from './App'
5
6
6
7
type ReactInstance = ReactElement
@@ -46,6 +47,7 @@ type InertiaAppOptionsForCSR<SharedProps extends PageProps> = BaseInertiaAppOpti
46
47
showSpinner ?: boolean
47
48
}
48
49
setup ( options : SetupOptions < HTMLElement , SharedProps > ) : CreateInertiaAppSetupReturnType
50
+ axiosInstance ?: AxiosInstance
49
51
}
50
52
51
53
type CreateInertiaAppSSRContent = { head : string [ ] ; body : string }
@@ -55,6 +57,7 @@ type InertiaAppOptionsForSSR<SharedProps extends PageProps> = BaseInertiaAppOpti
55
57
render : typeof renderToString
56
58
progress ?: undefined
57
59
setup ( options : SetupOptions < null , SharedProps > ) : ReactInstance
60
+ axiosInstance ?: undefined
58
61
}
59
62
60
63
export default async function createInertiaApp < SharedProps extends PageProps = PageProps > (
@@ -71,6 +74,7 @@ export default async function createInertiaApp<SharedProps extends PageProps = P
71
74
progress = { } ,
72
75
page,
73
76
render,
77
+ axiosInstance,
74
78
} : InertiaAppOptionsForCSR < SharedProps > | InertiaAppOptionsForSSR < SharedProps > ) : Promise <
75
79
CreateInertiaAppSetupReturnType | CreateInertiaAppSSRContent
76
80
> {
@@ -82,6 +86,10 @@ export default async function createInertiaApp<SharedProps extends PageProps = P
82
86
83
87
let head = [ ]
84
88
89
+ if ( ! isServer && axiosInstance ) {
90
+ router . setAxiosInstance ( axiosInstance )
91
+ }
92
+
85
93
const reactApp = await Promise . all ( [
86
94
resolveComponent ( initialPage . component ) ,
87
95
router . decryptHistory ( ) . catch ( ( ) => { } ) ,
0 commit comments