feat: refine global tokens, nav active state, section title
This commit is contained in:
@@ -107,6 +107,7 @@
|
||||
} else {
|
||||
app.innerHTML = '<p>Page not found</p>';
|
||||
}
|
||||
updateActiveNav();
|
||||
}
|
||||
|
||||
function navigate(path) {
|
||||
@@ -114,6 +115,17 @@
|
||||
route();
|
||||
}
|
||||
|
||||
function updateActiveNav() {
|
||||
const path = window.location.pathname;
|
||||
document.querySelectorAll('header nav a').forEach(a => {
|
||||
const href = a.getAttribute('href');
|
||||
const isActive = href === '/'
|
||||
? path === '/'
|
||||
: path.startsWith(href);
|
||||
a.classList.toggle('active', isActive);
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('popstate', route);
|
||||
|
||||
async function api(path) {
|
||||
|
||||
Reference in New Issue
Block a user