File tree Expand file tree Collapse file tree 1 file changed +21
-8
lines changed Expand file tree Collapse file tree 1 file changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -18,14 +18,26 @@ const axiosInstance = axios.create({
18
18
19
19
// Add a request interceptor
20
20
axiosInstance . interceptors . request . use (
21
- function ( config ) {
22
- // Do something before request is sent
23
- return config ;
24
- } ,
25
- function ( error ) {
26
- // Do something with request error
27
- return Promise . reject ( error ) ;
28
- }
21
+ function ( config ) {
22
+ // Do something before request is sent
23
+ if ( ! config . url || ! config . params ) {
24
+ return config ;
25
+ }
26
+
27
+ Object . entries < any > ( config . params ) . forEach ( ( [ key , value ] ) => {
28
+ const stringToSearch = `{${ key } }` ;
29
+ if ( config . url !== undefined && config . url . search ( stringToSearch ) !== - 1 ) {
30
+ config . url = config . url . replace ( `{${ key } }` , encodeURIComponent ( value ) ) ;
31
+ delete config . params [ key ] ;
32
+ }
33
+ } ) ;
34
+
35
+ return config ;
36
+ } ,
37
+ function ( error ) {
38
+ // Do something with request error
39
+ return Promise . reject ( error ) ;
40
+ }
29
41
) ;
30
42
31
43
// Add a response interceptor
@@ -62,6 +74,7 @@ export const request = <T>(
62
74
url : options . url ,
63
75
data : options . body ,
64
76
method : options . method ,
77
+ params : options . path ,
65
78
headers : formattedHeaders ,
66
79
cancelToken : source . token ,
67
80
} )
You can’t perform that action at this time.
0 commit comments