1.0.0 • Published 2 years ago
@alexandreono/router v1.0.0
A simple client-side router
Installation
npm i @alexandreono/router
For the router to work you need to launch the router server.
npx router-server
The server will run by default on port 5000 but you can add a .env file at the root of your project and provide the ROUTER_SERVER_PORT variable with your prefered port number.
API
Next to come
Example code
import { Router } from "./Router";
const root = document.getElementById("root");
if (!root) throw new Error("No root element found");
const router = new Router({ root });
router.add("/", b => {
return b
.add("h1", { text: "Welcome home!", class: ["sm-spacing-tb"] })
.add("button", { text: "Go to profile", linkTo: "/profile", class: ["cool-button"] })
.build();
});
router.add("/profile", b => {
return b
.add("h1", { text: "Profile page!", class: ["sm-spacing-tb"] })
.add("button", {
text: "Come back home",
class: ["cool-button"],
linkTo: "/",
})
.build();
});
router.run();
1.0.0
2 years ago