-
-
Notifications
You must be signed in to change notification settings - Fork 513
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
Laravel Livewire - wrong redirect when using Livewire right before switching the language #773
Comments
What version of livewire are you on? Livewire released an update which broke integration with this library (anything above 2.3.8). |
I'm on ^2.0 right now which resolves to an installed version of 2.3.6 on my project. So this might not be the problem. If you click a save button for example, an AJAX request is made by livewire. This request (POST URL) will be used by mcamara/laravel-localization for the redirect and not the current page URL I'm on. |
This has been fixed and tagged in v2.3.12 of Livewire. |
I don't know if I'm wrong, but I've solved the issue changing public function boot()
{
LaravelLocalization::setLocale();
} So, I changed Route::get('/', fn () => redirect('/'. LaravelLocalization::getCurrentLocale()));
Route::group(['prefix' => LaravelLocalization::getCurrentLocale(), 'middleware' => ['localize', 'localeSessionRedirect']], function() {
// Your routes...
}); |
Thanks @masterix21. It's working for login. Like this : <?php
namespace App\Http\Responses;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Laravel\Fortify\Contracts\LogoutResponse as LogoutResponseContract;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class LogoutResponse implements LogoutResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 204)
: redirect(LaravelLocalization::localizeUrl('/'));
}
} And inside FortifyServiceProvider.php : public function boot()
{
$this->app->singleton(
\Laravel\Fortify\Contracts\LogoutResponse::class,
\App\Http\Responses\LogoutResponse::class
); |
Hello, I'm preseting the same issue, I tried with @masterix21 solution but same result the url of menu is http://local.com/en/livewire/message/navigation-menu any other idea how to solve it? Regards |
Describe the bug
I use Laravel Jetstream with Livewire and integrated a language Selector in the top bar.
To Reproduce
Steps to reproduce the behavior:
http://127.0.0.1:8000/en/user/profile
http://127.0.0.1:8000/de/livewire/message/navigation-menu
Expected behavior
An AJAX call/request to the application should not updated the last visited route. If I stay on
http://127.0.0.1:8000/en/user/profile
and want to switch the language tode
, then I expect to land athttp://127.0.0.1:8000/de/user/profile
More info:
Additional context
Have a nice day <3
The text was updated successfully, but these errors were encountered: