4 years ago

Adding class .active to current link in Laravel 5.2

Posted 4 years ago by labanino

This is my html:

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">My Blog Site</a>

    <div class="collapse navbar-collapse navbarCollapse">
        <ul class="nav navbar-nav">
            <li class="active"><a href="{{ route('blogs.index') }}">Blogs</a></li>
            <li><a href="{{ route('blogs.create') }}">Create</a></li>

I have the bootstrap.min.js but the active link it is not working. Then I tried to do the trick with jquery:

$(document).ready(function() {
      $(".nav a").on("click", function(){

but when I click the link the class .active is added but then it goes away. The jquery works, I'm not sure if in Laravel is done different. Thanks.

Please sign in or create an account to participate in this conversation.