I'm using the wire:click.prevent
attribute to navigate inside the app by dynamically loading components using $emit
inside the click
attribute. For example:
<a href="{{ route('inventory.show') }}" wire:click.prevent="$emit('navigate', {'page':'inventory.show', 'route':'{{ route('inventory.show') }}'})" class="nav-link">Link</a>
Everything works well, and the navigate
function replaces the current content with the content of the page passed in the parameters.
Now, I want to open the link in a new tab if the user keeps pressing the CMD (or Ctrl) button on the keyboard, which can be easily achieved via JavaScript in a normal scenario.
The main challenges are:
- By using
wire:click.prevent
, I can't directly control the wayevent.preventDefault()
is injected into the code, so setting a custom rule to prevent or allow it becomes tricky. - Even if I remove the
prevent
attribute and use custom JavaScript to detect CMD or Ctrl presses, how do I avoid executing the function in thewire:click
while still opening the link in a new tab?
Any help or suggestions on how to achieve this behavior would be greatly appreciated. Thank you!