quartz/assets/js/router.js

27 lines
552 B
JavaScript
Raw Normal View History

2022-05-30 06:40:44 +03:00
import {
apply,
navigate,
prefetch,
router,
} from "https://unpkg.com/million@1.9.8-0/dist/router.mjs"
2022-05-03 18:47:42 +03:00
2022-05-30 06:40:44 +03:00
export const attachSPARouting = (init, rerender) => {
2022-05-27 18:39:44 +03:00
// Attach SPA functions to the global Million namespace
window.Million = {
2022-05-30 06:40:44 +03:00
apply,
2022-05-27 18:39:44 +03:00
navigate,
prefetch,
2022-05-30 06:40:44 +03:00
router,
}
const render = () => requestAnimationFrame(rerender)
window.addEventListener("DOMContentLoaded", () => {
apply((doc) => init(doc))
init()
router(".singlePage")
render()
})
window.addEventListener("million:navigate", render)
2022-05-03 18:47:42 +03:00
}