public_notes/assets/js/router.js

17 lines
534 B
JavaScript
Raw Normal View History

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