-
Notifications
You must be signed in to change notification settings - Fork 264
[2.x] Support for a custom URL resolver #739
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
Conversation
In my original PR I also allowed overriding the URL resolver from the middleware. Could we have that added as well? use Inertia\Middleware;
class HandleInertiaRequests extends Middleware
{
public function urlResolver(Request $request): ?callable
{
return fn (Request $request) => 'https://inertiajs.com/'.$request->getRequestUri();
}
} |
Yes, I'll work on that! And I'll add you as co-author as well :) |
@pascalbaljet there is actually an issue when setting a custom resolver. If the url does not match exactly the url in a , anchor tags will not work. For example in the react playground, if you force leading slash:
Than go to the home and click article link, it will not redirect to the bottom, unless you change the link adding the trailing slash |
The custom resolver was not introduced to add query params to URL (or similar changes). Its main goal is to prevent query params from being encoded, like brackets. I'm still playing around with some additional comparisons in the frontend library to improve on this further. Here's an example from the original PR that uses Inertia::resolveUrlUsing(function (Request $request) {
return Str::start(Str::after(rawurldecode($request->fullUrl()), $request->getSchemeAndHttpHost()), '/');
}); |
@pascalbaljet the code I posted was not correct, I wanted to only add a leading slash not adding a query param, I updated it. |
@pascalbaljet Why was nothing added to the documentation about this ? |
It's been released less than an hour ago 😅 I'm working on documenting this and some other new features and doc improvements in general. I'll probably open a PR for that next week. |
@pascalbaljet Yeah, I just noticed the doc was a seperate repo. |
It looks like the js core package changes the format of // In HandleInertiaRequests.php
public function urlResolver()
{
return fn (Request $request) => $request->fullUrl();
} Expected Behavior: Actual Behavior:
|
Credit goes to @RobertBoes for bringing this idea to the table. I'll add you as an author when this is merged.
With this callback, you can customize the URL that gets sent to the frontend. There are many edge cases and preferences to have one unified way to do this (trailing slashes, encoded query params, etc.). This way, developers can customize the URL to their needs and setup.
Here are some of the issues/PRs about it: