Route Definition
In the route definition, provide the route name to allow it to be referred to.
Route::get('/home', [\App\Http\Controllers\HomeController::class, 'index']) ->name('home.index');
Checking Active Route
When checking to see the active route, pass on the "route name" to the "routeIs()" method.
<a href="{{ route('home.index') }}" class="link {{ request()->routeIs('home.index') ? 'link-active' : null }}" > Home </a>
Now anytime the route is updated for example from "/home" to "/homepage", nothing should be changed since the "route name" is used to reference the URL.
Leave a reply