-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: Improve redirects #79
Comments
Also, I have not found a function for the relative path. It would be great to simplify $responseHTMX = single_service('redirectresponse')->hxLocation((string) previous_url(true));
public function hxLocation(...): RedirectResponse {
// $path = 'http://example.local/admin/users?searchQuery=John&sort=ASC';
/**
* @var URI $uri
*/
$uri = single_service('uri', $path)->withScheme('')->setHost('');
$data = ['path' => '/' . ltrim((string) $uri, '/')];
// to '/admin/users?searchQuery=John&sort=ASC'
} |
The If we send I want to keep the current methods intact as they are the equivalent of the pure function hxRedirect()
{
// it htmx then this
// and if normal request then that
} |
Yes, I mentioned the headers. This is the reason for the change. Example, from the list of users with the "user-list" fragment, click the Ban/Unban button. With HTMX, you need Therefore, duplicate conditions arise. if ($this->request->isHtmx()) {
return $responseHTMX->with(...$flashError);
}
return redirect()->back()->with(...$flashError); Changing the function would be a good solution to use a single code. PS: Sorry for the machine translation, if not everything is clearly described |
You can name this helper function Unfortunately, I will not approve any changes to the existing methods, because we need to be able to decide whether we use |
I heard you. Maybe someday there will be users with a similar problem and we will come back to this. It's easier for me to modify my project |
#79 (comment) |
Yes, but I would implement it a bit differently: public function hxLocation(...): RedirectResponse {
if (str_starts_with($path, 'http')) {
$path = (string) service('uri', $path, false)->withScheme('')->setHost('');
}
$data = ['path' => '/' . ltrim($path, '/')];
// ...
} Plus this would need a mention in the docs. |
There may be a problem with http verification if the URL is "http/users/123" |
Good point, you can change it to |
I won't be able to create a PR for the next few weeks. I would not use a shared service, but get a new. There may be a conflict when the URI is used outside the redirect |
I continue to work with HTMX.
Should I redefine
RedirectResponse
(back(), route(), to()
) and updateredirect()
?When the request came as HTMX, the redirect will have the initial headers. By making a regular redirect, the response will remain as for HTMX. Therefore, the second entry does not make sense.
Now we need to duplicate the code for different cases (HTMX or a regular request). Would it be better to combine these conditions inside the new functions?
The text was updated successfully, but these errors were encountered: