I move inside the page with this click
<a class="nav-link" href="#news">News</a>
<section id="news" class="works">
If I click the link I can move to the section.
Or type directly example.com/#news
it works.
But in first method, url dosn't change to example.com/#news
it is example.com/
So bookmark is not possible.
How can I change url when moving herf #
?
I realized that js is interfering, but is it possible to add some sentence to change url??
on('click', '#navbar .nav-link', function(e) {
let section = select(this.hash)
if (section) {
e.preventDefault()
let navbar = select('#navbar')
let header = select('#header')
let sections = select('section', true)
let navlinks = select('#navbar .nav-link', true)
navlinks.forEach((item) => {
item.classList.remove('active')
})
this.classList.add('active')
if (navbar.classList.contains('navbar-mobile')) {
navbar.classList.remove('navbar-mobile')
let navbarToggle = select('.mobile-nav-toggle')
navbarToggle.classList.toggle('bi-list')
navbarToggle.classList.toggle('bi-x')
}
if (this.hash == '#header') {
header.classList.remove('header-top')
sections.forEach((item) => {
item.classList.remove('section-show')
})
return;
}
if (!header.classList.contains('header-top')) {
header.classList.add('header-top')
setTimeout(function() {
sections.forEach((item) => {
item.classList.remove('section-show')
})
section.classList.add('section-show')
}, 350);
} else {
sections.forEach((item) => {
item.classList.remove('section-show')
})
section.classList.add('section-show')
}
scrollto(this.hash)
}
}, true)