@@ -36,17 +36,26 @@ class Response implements Responsable
36
36
37
37
protected $ cacheFor = [];
38
38
39
+ protected ?Closure $ urlResolver = null ;
40
+
39
41
/**
40
42
* @param array|Arrayable $props
41
43
*/
42
- public function __construct (string $ component , array $ props , string $ rootView = 'app ' , string $ version = '' , bool $ encryptHistory = false )
43
- {
44
+ public function __construct (
45
+ string $ component ,
46
+ array $ props ,
47
+ string $ rootView = 'app ' ,
48
+ string $ version = '' ,
49
+ bool $ encryptHistory = false ,
50
+ ?Closure $ urlResolver = null
51
+ ) {
44
52
$ this ->component = $ component ;
45
53
$ this ->props = $ props instanceof Arrayable ? $ props ->toArray () : $ props ;
46
54
$ this ->rootView = $ rootView ;
47
55
$ this ->version = $ version ;
48
56
$ this ->clearHistory = session ()->pull ('inertia.clear_history ' , false );
49
57
$ this ->encryptHistory = $ encryptHistory ;
58
+ $ this ->urlResolver = $ urlResolver ;
50
59
}
51
60
52
61
/**
@@ -375,11 +384,15 @@ public function isPartial(Request $request): bool
375
384
*/
376
385
protected function getUrl (Request $ request ): string
377
386
{
378
- $ url = Str::start (Str::after ($ request ->fullUrl (), $ request ->getSchemeAndHttpHost ()), '/ ' );
387
+ $ urlResolver = $ this ->urlResolver ?? function (Request $ request ) {
388
+ $ url = Str::start (Str::after ($ request ->fullUrl (), $ request ->getSchemeAndHttpHost ()), '/ ' );
389
+
390
+ $ rawUri = Str::before ($ request ->getRequestUri (), '? ' );
379
391
380
- $ rawUri = Str::before ($ request ->getRequestUri (), '? ' );
392
+ return Str::endsWith ($ rawUri , '/ ' ) ? $ this ->finishUrlWithTrailingSlash ($ url ) : $ url ;
393
+ };
381
394
382
- return Str:: endsWith ( $ rawUri , ' / ' ) ? $ this -> finishUrlWithTrailingSlash ( $ url ) : $ url ;
395
+ return App:: call ( $ urlResolver , [ ' request ' => $ request ]) ;
383
396
}
384
397
385
398
/**
0 commit comments