Check the rendered HTML in your browser. I suspect it is applying the active class but the active class for a Navbar Item doesnât do anything. It might need the team to look into the navigation JS/CSS.
Both navbars on this test page have the Home button with active class but neither show differently to the other links. The first Navbar was added as a block from BS5, the second is a direct code copy from the bootstrap example docs.
There is a js script controlling which link to be active and it makes the page active when the url matches. @bpj the active class wonât stay there if toggled manually, as the script sees it doesnât match the page url.
@mebeingken is the page url matching the navigation href - href="/market_reports"? If not then that is why your class is not applied by the navbar script.
Well that is exactly what i am saying - you canât just add an active class to any menu item as the nav script will remove it if the nav link href="" does not match the url!
Any ideas on how to accomplish this? I have several child pages of the main navigation that should show the main nav as active even though the href is different. Iâve used the class toggle before but I guess I was just getting lucky in the other project. I guess I could run some js to add the class later.
That has always been an âissueâ with child pages and active state for the parent category/url. The script doesnât really know which page is a child/sub page of which other.
Maybe @patrick can suggest a solution here.
Here a way to do it with a custom attribute. On your link just add dmx-nav as an attribute. Below code checks if the browser url starts with the same path as the one on the link.
dmx.Attribute('nav', 'mounted', function(node, attr) {
this.$addBinding('', function() {
requestAnimationFrame(function() {
var url = new URL(node.href);
node.classList.toggle('active', location.pathname.startsWith(url.pathname));
});
});
});