- Fast and simple.
- Routes without needing the hash.
- History was used api.
- Complete system documentation is available online at this link.
- Send error reports, suggestions, and upload requests to the GitHub issue tracker.
- Read the File.
- Ecmascript >= 6
"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();
The RouterKhan is licensed under the MIT license. See License File for more information.