Search code examples
laravellaravel-livewirealpine.js

x-data value resets after clicking wire:click.prevent action


In a Blade component I have:

@if(Request::segment(1) === 'admin')
    <div x-data="{ admin: true }">
@else
    <div x-data="{ admin: false }">
@endif

    <div x-show="admin">
    ...
    </div>

</div>

So, when I visit example.com/admin, the admin <div> is visible.

Outside this component I have another component:

<a wire:click.prevent="create()" href="#">
    Add
</a>

With create() opening a modal on the page.

The problem is.. Once I click the link, admin is set to false in my first component. This while the url didn't change.

How can I keep admin set to true?


Solution

  • Fixed by adding wire:ignore to a parent div

    https://laravel-livewire.com/screencasts/s4-wire-ignore