Router

A high-performance basic router works everywhere.

tag Build Status license

Server: See zhmushan/abc

Browser:

<body>
  <button id="btn">Change Path</button>
  <script type="module">
    import { Node } from "https://deno.land/x/router/mod.js";

    const root = new Node();
    root.addRoute("/print_:info", c => {
      console.log(c.info);
    });

    btn.onclick = () => {
      const path = `/print_${randomStr()}`;
      const [func, params, _] = root.getValue(path);
      if (func) {
        const p = {};
        for (const { key, value } of params) {
          p[key] = value;
        }
        func(p);
        history.replaceState(undefined, "", path);
      }
    }

    function randomStr() {
      return Math.random().toString(32).split(".")[1];
    }
  </script>
</body>