diff --git a/src/Response.php b/src/Response.php index 8a17076e..5f6f7054 100644 --- a/src/Response.php +++ b/src/Response.php @@ -96,10 +96,16 @@ public function toResponse($request) $props = $this->resolvePropertyInstances($props, $request); + $queryString = $request->getQueryString(); + + if (null !== $queryString) { + $queryString = '?'.$queryString; + } + $page = [ 'component' => $this->component, 'props' => $props, - 'url' => $request->getBaseUrl().$request->getRequestUri(), + 'url' => $request->getBaseUrl().$request->getPathInfo().$queryString, 'version' => $this->version, ]; diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 220e2396..7b2a0144 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -362,4 +362,19 @@ public function test_responsable_with_invalid_key(): void $page['props']['resource'] ); } + + public function test_response_url_in_laravel_subpath_install(): void + { + $request = Request::create('/subpath/product/123', 'GET', [], [], [], [ + 'SCRIPT_FILENAME' => '/project/public/index.php', + 'SCRIPT_NAME' => '/subpath/index.php', + ]); + $request->headers->add(['X-Inertia' => 'true']); + + $response = new Response('Product/Show', []); + $response = $response->toResponse($request); + $page = $response->getData(); + + $this->assertSame('/subpath/product/123', $page->url); + } }