Hi folks,
I have a navigation link to “/blog” where all my blog posts are listed.
When I click on that link the navigation element gets the “w–current” class and therefore looks bold for instance.
Now when I click on one specific blog post I land on a subdirectory url like “/blog/my-blog-post” but the “w–current” class is gone from the navigation blog link.
I managed to fix that now by adding a js-script to the footer:
window.addEventListener("load", (event) => {
let currentUrlPath = window.location.pathname;
Array.from(document.getElementsByClassName('navigation-item w-nav-link')).forEach((el) => {
let elUrlPath = el.getAttribute('href');
if (currentUrlPath.includes(elUrlPath)) {
el.classList.add('w--current');
} else {
el.classList.remove('w--current');
}
});
});
But since this is waiting for the document to be loaded it has a small delay.
So I’m not really happy with that solution.
Isn’t that also possible native by Webflow?