Laravel 11 Livewire 3 wire:current - Active Link

Websolutionstuff | Apr-11-2025 | Categories : Laravel

In this quick guide, I’ll show you how to highlight the active link in your menu using wire:current in Laravel 11 with Livewire 3. It’s super useful for navigation and doesn’t require custom logic or JavaScript. Just add one directive, and Livewire handles the rest.

What is wire:current?

wire:current is a Livewire 3 directive that checks if a link’s destination matches the current Livewire route. If it does, you can apply a style, class, or condition to show the user which page they’re on.

Setup Example: Livewire SPA-Style Navigation

Laravel 11 Livewire 3 wire:current - Active Link

 

Create Routes in web.php

use App\Livewire\Home;
use App\Livewire\Contact;

Route::get('/', Home::class)->name('home');
Route::get('/contact', Contact::class)->name('contact');

 

Create the Livewire Pages

php artisan make:livewire Home
php artisan make:livewire Contact

 

Shared Navigation Component

Let’s say we have a navigation menu in a shared Blade partial or component:

<!-- resources/views/components/nav.blade.php -->
<nav class="flex gap-4">
    <a 
        href="{{ route('home') }}" 
        wire:navigate 
        wire:current.class="text-blue-600 font-bold"
    >
        Home
    </a>
    <a 
        href="{{ route('contact') }}" 
        wire:navigate 
        wire:current.class="text-blue-600 font-bold"
    >
        Contact
    </a>
</nav>

 

More wire:current Options

You can also use other modifiers:

wire:current.attr

Add an HTML attribute conditionally if the link is current.

<a 
    href="{{ route('home') }}" 
    wire:navigate 
    wire:current.attr="aria-current"
>
    Home
</a>

If current, it renders:

<a href="/" aria-current>Home</a>

 

wire:current.remove

Remove a class if the route is not active.

<a 
    href="{{ route('home') }}" 
    wire:navigate 
    class="text-gray-500"
    wire:current.remove.class="text-gray-500"
>
    Home
</a>

This keeps the default gray, but removes it when the link is active.

 


You might also like:

Recommended Post
Featured Post
How To Remove Column From Table In Laravel 10 Migration
How To Remove Column From Tabl...

In this article, we will see how to remove columns from a table in laravel 10 migration. Here, we will learn about...

Read More

Apr-26-2023

Laravel 9 REST API With Passport Authentication
Laravel 9 REST API With Passpo...

In this article, we will see an example of laravel 9 REST API with passport authentication. Also, perform CRUD...

Read More

Mar-13-2022

Autocomplete Search from Database in Laravel 11
Autocomplete Search from Datab...

Hello, laravel web developers! In this article, we'll see how to autocomplete a search from a database in larav...

Read More

Jun-24-2024

Integrating Laravel 11 with Blockchain for Decentralized Applications
Integrating Laravel 11 with Bl...

Hello, laravel web developers! In this guide, I’ll show you how to integrate Laravel 11 with blockchain technology...

Read More

Oct-02-2024