From: Ardis Lu Date: Tue, 1 Feb 2022 05:03:28 +0000 (-0800) Subject: Update names to reflect what they're doing X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=529c2e201ff1747974b62c4e7c8e74aaadcfc9de;p=minimal-routing Update names to reflect what they're doing --- diff --git a/index.html b/index.html index 46dcce4..450957a 100644 --- a/index.html +++ b/index.html @@ -37,8 +37,8 @@ const main = document.querySelector('main'); const pages = Array.from(document.querySelectorAll('[data-page]')); // Must convert to array to preserve elements - // Display the appropriate page based on the URL path - function route(path) { + // Display the appropriate page based on the URL path (does NOT modify browser history) + function showPage(path) { if (path === '') { path = 'home'; } @@ -60,8 +60,8 @@ } } - // Update the browser history, then route - function changePage(path) { + // Update the browser history, then show page + function route(path) { // If the new page is equal to the current page, don't do anything if (window.location.pathname.substring(1) === path) { return; @@ -71,17 +71,17 @@ const url = new URL(path, base); window.history.pushState({}, '', url); - route(path); + showPage(path); } // Set event handlers for (const router of routers) { - router.addEventListener('click', e => changePage(e.target.dataset.route)); + router.addEventListener('click', e => route(e.target.dataset.route)); } - window.onpopstate = _ => route(window.location.pathname.substring(1)); + window.onpopstate = _ => showPage(window.location.pathname.substring(1)); - // Route to the current URL (to support direct linking aka deep links) - route(window.location.pathname.substring(1)); + // Show the current URL (to support direct linking aka deep links) + showPage(window.location.pathname.substring(1));