myapp
├── index.php
├── apps.php
├── contact.php
└── sidebar.php
in sidebar.php
<nav class="side-bar">
<ul>
<li>
<a href="index.php" class="category" >
<i class="fi fi-bs-home"></i>
<span>Home</span>
</a>
</li>
<li>
<a href="room.php" class="category">
<i class="fi fi-bs-apps"></i>
<span>Room</span>
</a>
</li>
<li>
<a href="contact.php" class="category">
<i class="fi fi-br-comment-alt"></i>
<span>Contact</span>
</a>
</li>
</ul>
</nav>
in index.php apps.php contact.php
#more code here
<php include('sidebar.php');
#more code here
and I use some of JavaScript to add active class on the link of my current page
Note I use active class to highlight on the link of my current page
const category = document.querySelectorAll('.category');
const activePage =windows.location.href;
category.forEach(link =>{
if(link.href === activePage){
link.classList.add('active');
}
})
Problem
Active class work normally when I link to any page like ..\myapp\index.php , But when i open ..\myapp\ It will auto open index.php that make my link tag index.php page doesn't have active class
What I want?
I want to make it active class on home Page (index.php) when I open ../myapp/ in the url