Search code examples
laravel-5.4adminlte

Admin LTE theme + Laravel Mini sidebar issue


I used Admin LTE theme with Laravel and stucked at one known issue, there is no solution of that in Admin LTE theme, IF I toggle side bar its showing miniside bar, but when i navigate to another page the toggled sidebar again opened, It should not open because i already minimized it,

Please help,


Solution

    1. Your Sidebar is open. So the body doesn't have the class sidebar-collapse.
    2. Once you toggle it, the mini sidebar shows up. So the body has sidebar-collapse.
    3. Now when you navigate to other url the body will not have the class sidebar-collapse, that's why side bar is opened.

    Now you need to add the class sidebar-collapse when you navigate to another page.

    Trigger the sidebar-toggle and add a variable to localstorage which will have TRUE as its value.

    Now when you navigate to another page, fetch the localstorage variable value and add the class to body by checking localstorage variable.

    Ex :

    $('.sidebar-toggle').on('click',function(){
               var cls =  $('body').hasClass('sidebar-collapse');
               if(cls == true){
                    localStorage.setItem('collapse',0); 
               } else {
                    localStorage.setItem('collapse',1); 
               }
    
        });
    
       window.onload = function() {
           var collapse = localStorage.getItem('collapse');
           if(collapse == true){
                $('body').addClass('sidebar-collapse');
           } else if(collapse == false) {
                $('body').removeClass('sidebar-collapse');
           }
        }
    

    I hope this will help you.