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

27 lines
551 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.11.5/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
}