I am currently facing an issue with a global script in Angular 10 that is supposed to evaluate the current path and apply a style to the navigation bar conditionally. However, it seems to fail at times when using router links. I am wondering if there is a more efficient way to achieve this in Angular/Typescript that works seamlessly with router links.
$(document).ready(function(){
if (window.location.pathname != "/") {
$('#main-nav').css('background-color', 'black');
}
});
The functionality I want is simple: change the navbar color to black if the page is not the homepage.
I have come across suggestions about using ngOnInitView but I am unsure about where to implement it (should it be within my navbar component?).
Any insights or guidance on this issue would be greatly appreciated.