Ecmascript 6

Router Khan Version ( Ecmascript 6 )

About Router Khan JS

  • Fast and simple.

  • Routes without needing the hash.

  • History was used api.

    Documentation

  • Complete system documentation is available online at this link.

    Contribution

  • Send error reports, suggestions, and upload requests to the GitHub issue tracker.

  • Read the File.

    System Requirements

  • Ecmascript >= 6

Init RouterKhanJS using Modules [<script type="module">]

   "use strict";

   import RouterProvide from "./src/Router.js";

   (async window => {
       const Router = RouterProvide.create();

       // example simple route
       Router.any("/", async (data, viewRouter) => {
         console.log("Init !!");
         viewRouter.innerHTML = "<h1>Router init</h1>";
       });

       // simple route using middleware
       Router.any(
         "/home",
         async (data, viewRouter, next) => {
           data.id = Math.random() * 1000;
           next();
         },
         async ({ id }, viewRouter, next) => {
           const homePromise = () =>
             new Promise((resolve, reject) => {
               resolve("Home !! id is: " + id);
             });
           viewRouter.innerHTML = await homePromise();
           next();
         },
         () => console.log("Finish exec middleware")
       );

       // simple route redirect
       Router.any("/toRedirect", () => {
         Router.redirect("/redirected");
       });

       // simple route receive router
       Router.any("/redirected", (data, viewRouter) => {
         viewRouter.innerHTML = `<h1>Redirecionado com sucesso!!</h1>`;
       });

       // simple route with parameters
       Router.any("/perfil/{name}/{id}", async ({ name, id }, viewRouter) => {
         viewRouter.innerHTML = `<h1>Perfil ${name} is ID ${id}</h1>`;
       });

       // init router
       Router.dispatch();

License

The RouterKhan is licensed under the MIT license. See License File for more information.

Contact

Router Khan JS

Sistema de rotas com Ecmascript 6 ( Suporte a Modulos )

Router Khan JS Info

⭐ Stars 24
🔗 Source Code github.com
🕒 Last Update a year ago
🕒 Created 5 years ago
🐞 Open Issues 71
➗ Star-Issue Ratio 0
😎 Author paulooosrj