I'm using Laravel 9 for the project. I'm having problem on active menu on current page. Menu become active only when I added the route to href. Active class added automatically on list class.
When I added
{{ route('any-route-name') }}
to my link as below sample
<li >
<a href="{{ route('any-route-name') }}"> <i ></i> Companies</a>
</li>
an active class added to list. Did an inspect element, active class added to the list as below sample
<li >
<a href="{{ route('any-route-name') }}"> <i ></i> Companies</a>
</li>
did inspection on view page source but active class not exist. The moment I remove the
{{ route('any-route-name') }}
active class no more added. Can any one explain/assist me on this. I don't have any JS to add active class after page rendered.
CodePudding user response:
is('admin/cities')) ? 'active' : '' }}"> **Approach 2. Starting with the URL** is('admin/cities*')) ? 'active' : '' }}">CodePudding user response:
Try this code
<li >
<a href="{{ route('any-route-name') }}"> <i ></i> Companies</a>
</li>
Hope this help!