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({
1818
1919// Add a request interceptor
2020axiosInstance . 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+ }
2941) ;
3042
3143// Add a response interceptor
@@ -62,6 +74,7 @@ export const request = <T>(
6274 url : options . url ,
6375 data : options . body ,
6476 method : options . method ,
77+ params : options . path ,
6578 headers : formattedHeaders ,
6679 cancelToken : source . token ,
6780 } )
You can’t perform that action at this time.
0 commit comments