Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Fzoltan87's avatar

Livewire 3.X and Laravel 12.X - Preventing Component Reloading

How can I prevent my Livewire component from reloading every time the page refreshes? I placed the component in the resources\views\layouts\app.blade.php file. This component is responsible for loading categories, and I want it to appear on every page, which is why I placed it there.

I also have a Product Livewire component and a Product Detail Livewire component. Does anyone have any ideas on how I can prevent the component from reloading? Thanks in advance for your help.

In the config\livewire.php file, I set the layout as follows:
'layout' => 'layouts.app',

I include it in the app.blade.php file like this:
@livewire('category-navigation')

resources\views\layouts\app.blade.php

    <main>
        <div class="container mx-auto mt-8 grid grid-cols-12 gap-6">

            <div class="col-span-3">
                @livewire('category-navigation')
            </div>

            <div class="col-span-9">
                {{ $slot }}
            </div>
        </div>
    </main>

Here is how I define the Category component (app\Livewire\CategoryNavigation.php):

routes\web.php

<?php

use App\Livewire\ProductList;
use App\Livewire\ProductDetail;
use Illuminate\Support\Facades\Route;

Route::get('/product/{slug}', ProductDetail::class)->name('product.detail');
Route::get('/catalog/{slug}', ProductList::class)->where('slug', '.*')->name('products.byCategory');

app\Livewire\ProductList.php

app\Livewire\ProductDetail.php

<?php

namespace App\Livewire;

use Livewire\Component;
use App\Models\Product;

class ProductDetail extends Component
{
    public $product;

    public function mount($slug)
    {
        $this->product = Product::where('slug', $slug)->firstOrFail();
    }

    public function render()
    {
        return view('livewire.product-detail', [
            'product' => $this->product
        ]);
    }
}

resources\views\livewire\product-list.blade.php

<div class="container mx-auto mt-8">
    <h1 class="text-2xl font-bold">
        {{ $categoryName }}
    </h1>

    @if($products->isEmpty())
        <p class="mt-4 text-gray-600">None Product</p>
    @else
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mt-6">
            @foreach ($products as $product)
                <div class="border rounded-lg p-4 shadow-md">
                    <h2 class="text-lg font-semibold">
                        <a href="{{ route('product.detail', ['slug' => $product->slug]) }}" class="text-blue-500 hover:underline">
                            {{ $product->name }}
                        </a>
                    </h2>
                    <p class="text-gray-600">{{ $product->description }}</p>
                </div>
            @endforeach
        </div>
    @endif
</div>

resources\views\livewire\product-detail.blade.php

<div class="container mx-auto mt-8">
    <h1 class="text-3xl font-bold">{{ $product->name }}</h1>

    <div class="mt-4">
        <p class="text-gray-700">{{ $product->description }}</p>
    </div>

    <div class="mt-6">
        <a href="{{ url()->previous() }}" class="text-blue-500 hover:underline">← Back to list</a>
    </div>
</div>

The main point is that the category list component should not refresh when a product list is loaded or when a product detail page is displayed.

0 likes
5 replies
jj15's avatar

I'm a bit confused by your question. You mention three components but only one (CategoryNavigation) appears to be relevant as you share the code for it. What is the problem you're trying to solve? The component has to render on each page load, just like the page itself.

Looking at your component, it's not necessary to explicitly pass $categories and $currentCategory to the view, any public properties are automatically made available.

Fzoltan87's avatar

@jj15 I have updated the post and added more information. The main point is that the category list component should not refresh when a product list is loaded or when a product detail page is displayed.

jj15's avatar

@Fzoltan87 I see. So you want the CategoryNavigation component to keep the selected category across page loads/refreshes? If so, you could probably store the user's selected category in the session or as a query string, but someone else may have a different suggestion.

Please or to participate in this conversation.