I have a parent element of Booking
its children have a route of booking/…
If I have booking itself selected it makes all booking/… links active.
How can I change this?
I’ve tried to use if statements but it wouldn’t want to work.
I have a parent element of Booking
its children have a route of booking/…
If I have booking itself selected it makes all booking/… links active.
How can I change this?
I’ve tried to use if statements but it wouldn’t want to work.
2
Answers
try like this maybe this can help..
To handle the navigation in Laravel with Bootstrap 5, where you have a parent element (
Booking
) with children routes(booking/...)
, and you want to ensure that only the relevant child link is active, you can use Laravel’s route-related helpers to check the current route or URL segment.Ensure that your route names are correctly defined and that the
Route::is()
andRequest::is()
helpers are applied appropriately in your navigation. This approach should solve the issue where all child routes are being marked active when only the parent route is selected.I hope It can help you
Assuming your navigation looks something like this:
If you want a parent item to be active when any of its child routes are active, you can use
Request::is()
to check if the current URL matches any of the child routes: