Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 1.48 KB

README.md

File metadata and controls

58 lines (39 loc) · 1.48 KB

Simple router

NPM

Install

Import directly from a CDN (for example import Router from 'https://esm.sh/@bleckert/router') or install from npm (npm install @bleckert/router).

Usage

Simply create a new router like this:

const router = new Router();

You can also create the router with a base url (will be prepended on all routes) and/or a routes object.

const router = new Router('/user', {
	profile(route, path) {

	},
	settings(route, path) {

	}
});

You can also add routes after init and call dispatch manually. This is how you add routes:

router.on('/profile', (route, path, event) => {

});

router.on('/splat/*', (route, path, event) => {

});

router.on('/named/:id', (route, path, event) => {

});

router.dispatch();