function mount(path, params){ const route = Routes[path]; if(!route){ return; } setStyle(route.style); renderTemplate(route.tpl); route.init && route.init(params); } function handleLocation(){ const sp = new URLSearchParams(window.location.search); const screen = sp.get('screen') || 'intro'; const params = Object.fromEntries(sp); mount('/' + screen, params); } window.addEventListener('popstate', handleLocation); const paramsStart = new URLSearchParams(window.location.search); const screenInit = paramsStart.get('screen'); if(screenInit){ mount('/' + screenInit, Object.fromEntries(paramsStart)); } else{ navigate('/intro'); } })();