@boylu/router
v1.0.1
Published
Boylu Router is a simple SPA router for JavaScript
Downloads
5
Maintainers
Readme
@boylu/router
This is the main package of @boylu/router. Browser playground on StackBlitz
Installation
- Add
@boylu/router
to your existing project:
npm i @boylu/router
yarn add @boylu/router
pnpm i @boylu/router
Usage
Creating a project with Vite
npm create vite@latest router-test -- --template vanilla
yarn create vite router-test --template vanilla
pnpm create vite router-test --template vanilla
Creating a Routes
// routes.js
export const routes = [
{
name: "home",
path: "/",
component: () => "<h1>Home Page</h1>",
},
{
name: "about",
path: "/about",
component: () => "<h1>About Page</h1>",
},
];
Creating a Router
// main.js
import { createRouter } from "@boylu/router";
import { routes } from "./routes.js";
document.querySelector("#app").innerHTML = `
<nav>
<a href="/" class="router-link">Home</a>
<a href="/about" class="router-link">About</a>
</nav>
<div id="router-view"></div>
`;
createRouter(routes);