Skip to content

ddtt786/really-simple-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-typescript-router

A really simple JavaScript/TypeScript router

  • ~1kb minified ~0.5kb compressed

npm

import { Router } from "simple-typescript-router";

const router = new Router();
const title = <HTMLHeadingElement>document.querySelector("#title");

router
  .add("/blog/:id/post/:postid", ({ id, postid }) => {
    title.innerText = `blog ${id} : ${postid}`;
  })
  .add("/", () => {
    title.innerText = "home";
  })
  .add("_404", () => {
    title.innerHTML = "404";
  })
  .check();

web

import { Router } from "https://esm.sh/simple-typescript-router";

const router = new Router();
const title = <HTMLHeadingElement>document.querySelector("#title");

router
  .add("/blog/:username/post/:postid", ({ username, postid }) => {
    title.innerText = `${username} : ${postid}`;
  })
  .add("/", () => {
    title.innerText = "home";
  })
  .add("_404", () => {
    title.innerHTML = "404";
  })
  .check();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published