кто -нибудь встречал это поведение раньше? И есть решение?
Код: Выделить всё
// Main function to initialize navigation and dynamic loading
function setupDynamicRouting() {
const main = document.getElementById('main-content');
// Click handler: update hash
document.querySelectorAll('[data-section]').forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const section = link.getAttribute('data-section');
if (section) {
window.location.hash = section; // Triggers hashchange
}
});
});
// Hash change handler: fetch and load section
async function handleHashChange() {
const sectionName = window.location.hash.replace(/^#/, '') || 'main-dashboard';
const path = `./sections/${sectionName}.html?_=${Date.now()}`;
try {
const response = await fetch(path);
if (!response.ok) throw new Error(`Failed to fetch ${path}`);
const html = await response.text();
main.innerHTML = html;
} catch (err) {
console.error('[loadSection] Error:', err);
main.innerHTML = `
Could not load section: [b]${sectionName}[/b].
`;
}
}
// Initial section load
handleHashChange();
// React to future URL changes
window.addEventListener('hashchange', handleHashChange);
}< /code>
Evalu | Dashboard
[*]
[url=#]
[i]
[/url]
account_circle[/i] Profile
[url=/]
[i][/i]
Sidebar
[/url]
[list]
[url=#dashboardMenu]
[i][/i] Dashboard
[/url]
[url=#main-dashboard]Main Dashboard[/url]
[*][url=#course-dashboard]Course Dashboard[/url]
[*][url=#instructor-dashboard]Instructor Dashboard[/url]
[/list]
[*]
[url=#coursesMenu]
[i][/i] Courses
[/url]
[list]
[url=#courses]All Courses[/url]
[*][url=#new-course]New Course[/url]
[/list]
[*]
[url=#instructorsMenu]
[i][/i] Instructors
[/url]
[list]
[url=#instructors]All Instructors[/url]
[*][url=#new-instructor]New Instructor[/url]
[/list]
[url=#]
[img]https://github.com/mdo.png[/img]
[b]mdo[/b]
[/url]
[list]
[*][url=#]New project...[/url]
[*][url=#]Settings[/url]
[*][url=#]Profile[/url]
[*]
[*][url=#]Sign out[/url]
[/list]
Подробнее здесь: https://stackoverflow.com/questions/796 ... index-html
Мобильная версия