1.0.1 • Published 1 year ago

@boylu/router v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@boylu/router

This is the main package of @boylu/router. Browser playground on StackBlitz

Vercel npm

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);