0.0.4 • Published 2 years ago

delta-router v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

DeltaRouter.js

DeltaRouter

A Minimal Client-Side Router

Installation

npm i delta-router

Usage

import Router, { navigate } from "delta-router";

const router = new Router();

router.on('/', () => console.log('Welcome Home!'));

router.on('/user/:uid', (params, search) => console.log(params, search));

router.on('/user/:uid/post/:postId', (params) => console.log(params));

router.on('*', (params, search, pathname) => console.error(`"${pathname}" not found.`));

router.listen();

const routeLinks = document.querySelectorAll('[data-route-link]');

routeLinks.forEach(link => {
    link.addEventListener('click', e => {
        e.preventDefault();
        const path = e.target.getAttribute('href');
        navigate(path, router.currentPath === path);
    });
});
0.0.3

2 years ago

0.0.2

2 years ago

0.0.4

2 years ago

0.0.1

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago