keroosha.cybergulag.today/assets/js/router.js

17 lines
534 B
JavaScript
Raw Normal View History

2022-05-27 23:19:19 +03:00
import { router, navigate, reload, prefetch } from "https://unpkg.com/million@1.9.5/dist/router.mjs"
2022-05-03 18:47:42 +03:00
2022-05-03 20:16:09 +03:00
export const attachSPARouting = (draw) => {
2022-05-27 18:39:44 +03:00
// Attach SPA functions to the global Million namespace
window.Million = {
router,
navigate,
reload,
prefetch,
};
2022-05-03 18:47:42 +03:00
router(".singlePage")
// We need on initial load, then subsequent redirs
// requestAnimationFrame() delays graph draw until SPA routing is finished
2022-05-27 18:39:44 +03:00
reload(draw)
2022-05-03 20:16:09 +03:00
window.addEventListener("DOMContentLoaded", () => requestAnimationFrame(draw))
2022-05-03 18:47:42 +03:00
}