Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double base path in url #360

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

Expand Down
15 changes: 15 additions & 0 deletions tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}