/router-khan-js

Sistema de rotas com Ecmascript 6 ( Suporte a Modulos )

Primary LanguageHTMLMIT LicenseMIT

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

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