Search code examples
laravel-routinglaravel-livewire

How in livewire use route by its name?


In my laravel 7 /livewire 1.3 / turbolinks:5 / alpine@v2 app I have route defined

Route::livewire('/hostel/{slug}', 'hostel.hostel-view-page')->name('hostel-view-page');

When I use it :

<a href="{{ route('hostel-view-page', $hostelsIsHomepageSpotlight->slug)  }}" >
    Title
</a>

it does not work as reactive, as all page is reloaded. I prefer to name of this route, not like :

<a href="/hostel/{{ $hostelsIsHomepageSpotlight->slug }}" >
    Title
</a>

Which is a valid way ?

Thanks!


Solution

  • Try this, it works well for me:

    Route::group(['prefix' => 'admin',
            'as' => 'admin.',
            'middleware' => 'your:middleware',
    ], function () {
        Route::livewire('your-url-here', 'your-livewire-class-here')
        ->name('whatever.you.want');
    });