Aiden Bai
2022-05-27 bd316d8249f096c4d5616d682f142f49d4ca914f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { router, navigate, reload, prefetch } from "https://unpkg.com/million@1.9.2/dist/router.mjs"
 
export const attachSPARouting = (draw) => {
  // Attach SPA functions to the global Million namespace
  window.Million = {
    router,
    navigate,
    reload,
    prefetch,
  };
  router(".singlePage")
  // We need on initial load, then subsequent redirs
  // requestAnimationFrame() delays graph draw until SPA routing is finished
  reload(draw)
  window.addEventListener("DOMContentLoaded", () => requestAnimationFrame(draw))
}