Skip to content

tbleckert/router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Simple js router

Resources

License

Stars

Watchers

Forks

Packages

No packages published