inertia-laravel: Error in view data / url prop

Currently if the project has the base url localhost/test and we navigate to some/sub/page the result is a url change to localhost/test/test/some/sub/page in the brower by inertiajs. This url no longer matches the route we are currently at.

The issue seems to be that a path as part of the base url is not handled correctly.

This line in \Inertia\Response causes the issue.

'url' => $request->getBaseUrl().$request->getRequestUri(),

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (2 by maintainers)

Most upvoted comments

It should in my opinion be Inertia’s job to handle different server configurations. The problem as far as I can see is that #333 is the wrong fix for the problem. At least in my case where I’m setting RewriteBase /to/project in .htaccess

The combination of $request->getBaseUrl() + $request->getRequestUri() generates a invalid url with that server config. Looking at how fullUrl() / getUri() builds the url $request->getBaseUrl() + $request->getPathInfo() + $queryString (or fullUrl()) seems to be the right approach and should handle more server configurations.

It seems to me that $request->getBaseUrl() + $request->getRequestUri() are not intended to be combined together in that way.

Holy sh**! I lost one week of my life because of this bug! I tested 3 different web server (apache, nginx, IIS) to finally find this bug!

Awaiting the merge, almost a year, gosh

I am also interested in this fix! Currently unable to update a site to Laravel 9 because of this issue.

I can’t wait to see this merged!!!

I noticed this issue after submitting issue #421 and proposing PR #422

I spent 4 hours this afternoon before finding this bug!

also interested in a fix, at the moment I have to mess with the toResponse function in /vendor/inertiajs/inertia-laravel/src/Response.php

This is how I’ve dealt with it too in the meantime.