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

Seydina's avatar

Custom javascript variables redeclaration with livewire wire:navigate

I installed Livewire with Breeze and developed a custom template for the backend of my app. I created a javascript file with personal code which manages light and dark mode, show / and hide search bar among others... Everything works without problem but the problem occurs with wire:navigate from Livewire. Indeed when I put the wire:navigate attribute on a link in my menu and I click on it, everything works but a second click blocks all custom javascript with this message : Uncaught SyntaxError: redeclaration of const submenu , Uncaught SyntaxError: redeclaration of const Orders etc.

That is, clicking again and again on a link with the wire:navigate attribute reloads the page only once and blocks custom javascript as if all my variables are declared twice.

My JS file in located in public/index.js and loaded before my end body tag with this : <script defer src="{{asset('index.js')}}"></script>

and an example one of my sidebar link :

<x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')" wire:navigate
                    class="rounded-t-2xl">
                    <x-gmdi-dashboard-o class="span w-6" />
                    <h3>{{ __('Dashboard') }}</h3>
 </x-nav-link>
1 like
0 replies

Please or to participate in this conversation.