ar.falsy.cat/assets/js/router.js

27 lines
551 B
JavaScript
Raw Normal View History

2022-05-30 03:40:44 +00:00
import {
apply,
navigate,
prefetch,
router,
} from "https://unpkg.com/million@1.11.5/dist/router.mjs"
2022-05-03 15:47:42 +00:00
2022-05-30 03:40:44 +00:00
export const attachSPARouting = (init, rerender) => {
2022-05-27 15:39:44 +00:00
// Attach SPA functions to the global Million namespace
window.Million = {
2022-05-30 03:40:44 +00:00
apply,
2022-05-27 15:39:44 +00:00
navigate,
prefetch,
2022-05-30 03:40:44 +00: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 15:47:42 +00:00
}