When you click the link in the navigation, the browser will go to that link. To prevent this, you have the line commented out (e.preventDefault). If the application is not a single page application, you can write a function which will be executed on each page load [$(document).on('load, ()=>{});] where you check for the current URL and add the class .active to the corresponding element.
possible solution here How do I make Bootstrap navbar change active state?
Or like this code from GeeksForGeeks
<script>
/* Code for changing active
link on clicking */
var btns =
$("#navigation .navbar-nav .nav-link");
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click",
function () {
var current = document
.getElementsByClassName("active");
current[0].className = current[0]
.className.replace(" active", "");
this.className += " active";
});
}
/* Code for changing active
link on Scrolling */
$(window).scroll(function () {
var distance = $(window).scrollTop();
$('.page-section').each(function (i) {
if ($(this).position().top
<= distance + 250) {
$('.navbar-nav a.active')
.removeClass('active');
$('.navbar-nav a').eq(i)
.addClass('active');
}
});
}).scroll();
</script>