From 6623418dbe2e6f66a04c7d1b29455256af537724 Mon Sep 17 00:00:00 2001 From: Tudor Date: Thu, 8 Jan 2026 23:48:56 +0000 Subject: [PATCH] bug fix --- frontend/app.js | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/frontend/app.js b/frontend/app.js index c794439..21009ea 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -224,7 +224,13 @@ function navigateTo(path) { } function handleRoute() { - const path = window.location.pathname; + let path = window.location.pathname; + + // Normalize path - treat /index.html, empty, or just "/" as home + if (path === "" || path === "/index.html" || path.endsWith("/index.html")) { + path = "/"; + } + const view = routes[path] || "home"; // Update page title for SEO @@ -252,27 +258,32 @@ function handleRoute() { document.addEventListener("DOMContentLoaded", init); async function init() { - // Load filters and metrics in parallel (single request for filters) - const [filtersData, metricsData] = await Promise.all([ - fetchAPI("/api/filters", { showLoading: "filters" }), - fetchAPI("/api/metrics"), - ]); + try { + // Load filters and metrics in parallel (single request for filters) + const [filtersData, metricsData] = await Promise.all([ + fetchAPI("/api/filters", { showLoading: "filters" }), + fetchAPI("/api/metrics"), + ]); - // Cache and apply filters - if (filtersData) { - state.filters = filtersData; - populateFilters(filtersData); + // Cache and apply filters + if (filtersData) { + state.filters = filtersData; + populateFilters(filtersData); + } + + // Cache metrics + if (metricsData) { + state.metrics = metricsData.metrics; + } + + // Load initial data + await loadSchools(); + await loadRankings(); + } catch (err) { + console.error("Error during initialization:", err); } - // Cache metrics - if (metricsData) { - state.metrics = metricsData.metrics; - } - - // Load initial data - await loadSchools(); - await loadRankings(); - + // Always set up event listeners and routing, even if data loading fails setupEventListeners(); // Handle initial route