rizaldy.club/assets/js/router.js

27 lines
551 B
JavaScript
Raw Normal View History

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