Issue:
I’m building a full stack Laravel 11 application with Livewire. In development, everything works fine, but in production, when I make the first component update, it redirects me to GET /livewire/update
after making the POST request.
Configuration and Code
Livewire Configuration
<?php
return [
'class_namespace' => 'App\Livewire',
'view_path' => resource_path('views/livewire'),
'layout' => 'components.layouts.app',
'lazy_placeholder' => null,
'temporary_file_upload' => [
'disk' => null,
'rules' => null,
'directory' => null,
'middleware' => null,
'preview_mimes' => [
'png', 'gif', 'bmp', 'svg', 'wav', 'mp4',
'mov', 'avi', 'wmv', 'mp3', 'm4a',
'jpg', 'jpeg', 'mpga', 'webp', 'wma',
],
'max_upload_time' => 5,
'cleanup' => true,
],
'render_on_redirect' => false,
'legacy_model_binding' => false,
'inject_assets' => true,
'navigate' => [
'show_progress_bar' => true,
'progress_bar_color' => '#2299dd',
],
'inject_morph_markers' => true,
'pagination_theme' => 'tailwind',
];
Routes
Route::middleware(Lang::class)->group(function () {
Route::get("/", HomePage::class)->name("home");
Route::get('route1', Route1::class)->name("who");
Route::fallback(Error404::class)->name('fallback');
});
app.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<!-- Meta tags, fonts, and styles -->
@vite('resources/css/app.css')
@vite('resources/js/app.js')
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/aos.css" rel="stylesheet">
<!-- Favicons -->
</head>
<body class="antialiased bg-third font-cairo">
{{ $slot }}
<div class="fixed bottom-10 right-10">
<a href="https://wa.me/+905528721369" target="_blank">
<i class="fab fa-whatsapp"></i>
</a>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/aos.js"></script>
<script>
AOS.init();
</script>
</body>
</html>
app.js
import './bootstrap';
import 'alpinejs';
What I’ve Tried
-
Alpine.js Initialization:
- Ensured Alpine.js is imported correctly.
- Tried re-initializing, which showed a warning.
-
Vite Build:
- Verified that Vite built the frontend correctly.
-
Existing Solutions:
- Followed suggestions from this Stack Overflow thread and similar ones to change the update route for Livewire.
-
Temporary Solution:
- Added a GET route for
/livewire/update
to redirect back, but this reloads the page:
Route::get('livewire/update', function () { return redirect()->back(); })->name('update-livewire');
- Added a GET route for
Additional Information
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
public/index.php
<?php
use IlluminateHttpRequest;
define('LARAVEL_START', microtime(true));
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
require $maintenance;
}
require __DIR__.'/../vendor/autoload.php';
(require_once __DIR__.'/../bootstrap/app.php')->handleRequest(Request::capture());
Network Tab
- Checked that Livewire injected the
livewire.min.js
and it exists.
Question
Why does the first component update in production redirect to GET /livewire/update
after making a POST request, and how can I fix this issue without reloading the page?